Tutorial 1 for Workshop 18-24 July: Creating a Simple Ball Simulation With ChatGPT and WebEJS

🌟 Building a simulation using ChatGPT3.5 (initial variables and scaffolds) with WebEJS (power customisation to meet designer's and users' needs).

Let's create a simple ball moving to the right as an idea for this tutorial :)

Go to ChatGPT https://chat.openai.com/ to ask what you want to build

Prompt 1: simple

  1. 1. Type "Give me an outline of a simulation made in EJSS for a simple case of a ball moving to the right." into text area

    hint: when using GPT, it is always good to start simple and ask for more complex features later after the simple things are working properly

    Type "Give me an outline of a simulation made in EJSS for a simple case of a ball moving to the right." into text area
  2. 2. Click on this icon to submit the comment

    Click on this icon to submit the comment
  3. 3. Read the response from ChatGPT & Copy (ctrl+c) the part on the parameters

    Parameters are the variables used to build the simulation.

    Read the response from ChatGPT & Copy (ctrl+c) the part on the parameters
  4. 4. Edit the 1st message by pressing on the pencil icon.

    Edit the 1st message by pressing on the pencil icon.
  5. 5. Prompt 2: Refine based on what GPT gives. Add on to the previous message by pasting (ctrl+v) what was copied: "Define the parameters of the simulation: - Initial position of the ball. - Initial velocity of the ball. - Acceleration (if any). - Time step for the simulation. "

    Responses from ChatGPT may not always be exactly the same. There are times when words are phrased differently with the same concept.

    E.g., it could also be in a form of a sentence like "Define parameters such as initial position, initial velocity, acceleration, and time step." to copy (ctrl+c) and paste (ctrl+v)

    Prompt 2: Refine based on what GPT gives. Add on to the previous message by pasting (ctrl+v) what was copied: "Define the parameters of the simulation: - Initial position of the ball. - Initial velocity of the ball. - Acceleration (if any). - Time st
  6. 6. Prompt 2b add: Further add the following into the text area: "Allow users to input these parameters via text fields or sliders Create a graphical representation of the ball. Provide some JavaScript code"

    Prompt 2b add: Further add the following into the text area: "Allow users to input these parameters via text fields or sliders Create a graphical representation of the ball. Provide some JavaScript code"
  7. 7. The final message could look like this too:

    The final message could look like this too:
  8. 8. Click on Save & Submit

    Click on Save & Submit
  9. 9. Transfer results from GPT to WebEJSS. https://www.um.es/fem/wikis/runwebejs/?url= Read the defined variables/parameters generated by ChatGPT. Copy the element titled "x0" with 0 as the given value. Take note of the other variables.

    In this case, the variables to take note are:

    x0, v0, a, dt, t, x & v

    Transfer results from GPT to WebEJSS. https://www.um.es/fem/wikis/runwebejs/?url= Read the defined variables/parameters generated by ChatGPT. Copy the element titled "x0" with 0 as the given value. Take note of the other variables.

WebEJS 1.0beta entry point: https://t.um.es/runwebejs ir https://www.um.es/fem/wikis/runwebejs/?url= *this entry point is designed to redirect you to one of the more than one (in the very near future) WebEJS servers that can run WebEJS for you. Defining the variables

  1. 10. Click on Model

    Click on Model
  2. 11. Click on "Click to create a page of variables"

    Click on "Click to create a page of variables"
  3. 12. A pop-up message to "Create page" will appear. Click on OK.

    A pop-up message to "Create page" will appear. Click on OK.
  4. 13. Paste "x0" into input

    Paste "x0" into input
  5. 14. Type "0" as the given value.

    Refer to ChatGPT generated message to recall the value given.

    Type "0" as the given value.

ChatGPT

  1. 15. Refer back to ChatGPT and copy the rest of the variables required. Our current focus to copy over is "v0", where it is initiated with 10 as the value.

    After copying "x0", what's left are:

    v0, a, dt, t, x & v.

    Jump to the next major step (#31) after filling up all the required variables:

    https://app.tango.us/app/workflow/Creating-a-Simple-Ball-Simulation-With-ChatGPT-and-WebEJS-6c7eebacc16f42ef91843d5721823284#step-ebefeb30-01e2-420d-ba57-cef672cd8e04

    Refer back to ChatGPT and copy the rest of the variables required. Our current focus to copy over is "v0", where it is initiated with 10 as the value.

WebEJS 1.0beta

  1. 16. Paste "v0" into input

    Paste "v0" into input
  2. 17. Type "10" as the Initial Value

    Type "10" as the Initial Value

WebEJS 1.0beta

  1. 18. Paste "a" into input.

    After copying "v0", what's left are:

    a, dt, t, x & v.

    Jump to the next major step (#31) after filling up all the required variables:

    https://app.tango.us/app/workflow/Creating-a-Simple-Ball-Simulation-With-ChatGPT-and-WebEJS-6c7eebacc16f42ef91843d5721823284#step-ebefeb30-01e2-420d-ba57-cef672cd8e04

    Paste "a" into input.
  2. 19. Type "0" as the given value.

    Type "0" as the given value.

ChatGPT

  1. 20. Refer back to ChatGPT and copy the rest of the variables required. Our current focus to copy over is "t", where it is initiated with 0 as the value.

    After copying "a", what's left are:

    dt, t, x & v.

    Jump to the next major step (#31) after filling up all the required variables:

    https://app.tango.us/app/workflow/Creating-a-Simple-Ball-Simulation-With-ChatGPT-and-WebEJS-6c7eebacc16f42ef91843d5721823284#step-ebefeb30-01e2-420d-ba57-cef672cd8e04

    Refer back to ChatGPT and copy the rest of the variables required. Our current focus to copy over is "t", where it is initiated with 0 as the value.
  2. 21. Paste "t" into input

    Paste "t" into input
  3. 22. Type "0" as the given value.

    Type "0" as the given value.
  4. 23. Refer back to ChatGPT and copy the rest of the variables required. Our current focus to copy over is "dt", where it is initiated with 0.1 as the value for the Time Step.

    After copying "t", what's left are:

    dt, x & v.

    Jump to the next major step (#31) after filling up all the required variables:

    https://app.tango.us/app/workflow/Creating-a-Simple-Ball-Simulation-With-ChatGPT-and-WebEJS-6c7eebacc16f42ef91843d5721823284#step-ebefeb30-01e2-420d-ba57-cef672cd8e04

    Refer back to ChatGPT and copy the rest of the variables required. Our current focus to copy over is "dt", where it is initiated with 0.1 as the value for the Time Step.
  5. 24. Paste "dt" into input

    Paste "dt" into input
  6. 25. Type "0.05"

    The recommended value for the Time Step (dt) is 0.05

    Type "0.05"
  7. 26. Refer back to ChatGPT and copy the rest of the variables required. Our current focus to copy over is "x" & "v", where it is initiated with 0 as the value.

    After copying "dt", what's left are:

    x & v.

    Jump to the next major step (#31) after filling up all the required variables:

    https://app.tango.us/app/workflow/Creating-a-Simple-Ball-Simulation-With-ChatGPT-and-WebEJS-6c7eebacc16f42ef91843d5721823284#step-ebefeb30-01e2-420d-ba57-cef672cd8e04

    Refer back to ChatGPT and copy the rest of the variables required. Our current focus to copy over is "x" & "v", where it is initiated with 0 as the value.
  8. 27. Type "x"

    Type "x"
  9. 28. Type "x0" to initiate 0 as the initial value

    Type "x0" to initiate 0 as the initial value
  10. 29. Type "v"

    Type "v"
  11. 30. Type "v0" to initiate 10 as the initial velocity

    Type "v0" to initiate 10 as the initial velocity

🌟 Implementing the motion

  1. 31. Click on "Evolution" tab

    The "Evolution" tab implements the algorithm for the motion of the simulation.

    In this editor systems of Ordinary Differential Equations of first order are defined.

    Click on "Evolution" tab
  2. 32. Click on "Click to create a page of ODEs"

    Click on "Click to create a page of ODEs"
  3. 33. A pop-up message to "Create page" will appear. Click on OK.

    A pop-up message to "Create page" will appear. Click on OK.
  4. 34. Type "t" for the independent variable.

    Type "t" for the independent variable.
  5. 35. Type "dt" as the increment.

    Type "dt" as the increment.
  6. 36. Click on the 1st option under State

    A pop-up message "List of suitable variables" will appear after.

    Click on the 1st option under State
  7. 37. Type "x"

    OR select "x"

    Type "x"
  8. 38. Click on OK

    Click on OK
  9. 39. Click on the 2nd option under State

    A pop-up message "List of suitable variables" will appear after.

    Click on the 2nd option under State
  10. 40. Type "v"

    Type "v"
  11. 41. Click on OK

    Click on OK
  12. 42. Click on the 1st option under Rate

    A pop-up message "List of suitable variables" will appear after.

    This step is to link velocity (v) to the displacement (x)

    Click on the 1st option under Rate
  13. 43. Type "v"

    or select "v"

    Type "v"
  14. 44. Click on OK

    Click on OK
  15. 45. Click on the 2nd option under Rate

    A pop-up message "List of suitable variables" will appear after.

    This step links velocity (v) to the acceleration (a).

    Click on the 2nd option under Rate
  16. 46. Select "a : (double) :"

    or type "a"

    Select "a : (double) :"
  17. 47. Click on OK

    Click on OK
  18. 48. The "Evolution" tab should look like this:

    velocity, v = dx / dt

    acceleration, a = dv / dt

    usually this is the pedagogical math equation that students are taught in math lessons at secondary level so we will use this instead of computing style of

    // Update ball position

    x += v*dt; // or x = x + v*dt

    The "Evolution" tab should look like this:

🌟 Crafting Plotting Panel View with HTML

  1. 49. Click on View

    Click on View
  2. 50. Click & Hold the following image under "Interface" Drag it to "Simulation view" on the left, following the Green markings.

    Click & Hold the following image under "Interface" Drag it to "Simulation view" on the left, following the Green markings.
  3. 51. This will appear after dragging the previous icon.

    This will appear after dragging the previous icon.
  4. 52. Now we want to shift the "controlPanel" (in Green) to the top of the page.

    To do this, we will have to shift the "controlPanel" to inside "labelPanel", as indicated with the Red markings.

    Now we want to shift the "controlPanel" (in Green) to the top of the page.
  5. 53. The Panel should look like this.

    The Panel should look like this.
  6. 54. Drag the highlighted icon (Shape) to the "plottingPanel" . The Panel should look like this.

    A pop-up message "Create a new element" will appear after.

    Drag the highlighted icon (Shape) to the "plottingPanel" . The Panel should look like this.
  7. 55. Type "Ball"

    Type "Ball"
  8. 56. Click on OK

    Click on OK
  9. 57. Click on the Shape Icon to open up its menu for more options.

    Sometimes WebEJS might end up creating 2 Shapes instead. Delete the extra 2nd element by clicking on the shape icon here.

    If this doesn't occur in your case, skip to step #60 here:

    https://app.tango.us/app/workflow/Creating-a-Simple-Ball-Simulation-With-ChatGPT-and-WebEJS-6c7eebacc16f42ef91843d5721823284#step-5738dcc1-b731-4fd1-ba87-8a877250e936

    Click on the Shape Icon to open up its menu for more options.
  10. 58. Click on "Remove" option in the Menu

    Click on "Remove" option in the Menu
  11. 59. Click on Remove

    A pop-up message will appear to confirm the removal of the Shape element.

    Click on Remove
  12. 60. Click on the Shape icon to open up its menu for its properties.

    Click on the Shape icon to open up its menu for its properties.
  13. 61. Click on "Properties" in the Menu.

    Click on "Properties" in the Menu.
  14. 62. Type "x"

    Link the X position with the variable "x"

    Type "x"
  15. 63. Type "1"

    SizeX for this case shall be 1.

    Type "1"
  16. 64. Type "1"

    SizeY for this case shall be 1.

    Type "1"
  17. 65. Click on Done

    Click on Done

🌟 PREVIEW: the simulation

  1. 66. Check "on" for the Live model

    Check "on" for the Live model
  2. 67. "FULL MODEL: Simulation" will appear instead of "PREVIEW: Simulation", indicating that the Live model is on display.

    "FULL MODEL: Simulation" will appear instead of "PREVIEW: Simulation", indicating that the Live model is on display.
  3. 68. Wait patiently as the simulation loads up.

    Wait patiently as the simulation loads up.
  4. 69. Click on "Reset" button to reset the simulation

    Click on "Reset" button to reset the simulation
  5. 70. The simulation should look like this as a result.

    The ball is moving to the right at a speed of (dx/dt = v = v0 = 10)

    ^ may go to variables to change v0 = 0.6 or any other desired value to slow the speed.

    The simulation should look like this as a result.
  6. 71. ^ may change the velocity value, v0 to "0.6" for a slower motion.

    ^ may change the velocity value, v0 to "0.6" for a slower motion.

🌟 use Model - Evolution

Go to the "Model" tab under "Evolution".

  1. 72. Click on Model

    Click on Model
  2. 73. Click on the "Events" button under "Evol Page 1"

    A pop-up window will appear after.

    Click on the "Events" button under "Evol Page 1"
  3. 74. Click on "Click to create a page of Events"

    A pop-up window to create the page will appear after.

    Click on "Click to create a page of Events"
  4. 75. Click on OK

    Click on OK
  5. 76. Edit the Zero Condition for Event 1

    Let's start by editing the Zero Condition for Event 1

    Edit the Zero Condition for Event 1
  6. 77. go back to GPT and ask "provide a JavaScript code in EJSS, about how to make the ball position (x,y) reflect back after hitting the boundary of the screen with velocity is vx and vy"

    go back to GPT and ask "provide a JavaScript code in EJSS, about how to make the ball position (x,y) reflect back after hitting the boundary of the screen with velocity is vx and vy"
  7. 78. Copy element titled "canvasWidth"

    Copy element titled "canvasWidth"

use GPT's answers as EJSS variables

  1. 79. Paste "canvasWidth" into input

    Paste "canvasWidth" into input
  2. 80. Type "2"

    Type "2"
  3. 81. Type "canvasHeight"

    Type "canvasHeight"
  4. 82. Type "2"

    Type "2"

Use GPT as AI coding assistant

  1. 83. Click on ChatGPT 3.5…

    Click on ChatGPT 3.5…
  2. 84. Click on ChatGPT 3.5…

    Click on ChatGPT 3.5…
  3. 85. Copy element

    Copy element

Designing the Simulation, -Variables - Evolution - PlottingPanel

  1. 86. Click on Evolution

    Click on Evolution
  2. 87. Click on Evol Page 1

    Click on Evol Page 1
  3. 88. Click on Event 1

    Click on Event 1
  4. 89. copy this inside the Zero condition if (x + radius >= canvasWidth/2 || x - radius <= -canvasWidth/2) { return 0; // Condition for Event } copy this inside the Action // Action for Event 1 vx *= -1

    ignore the commented lines // as they are previous lines of codes but not needed now

    copy this inside the Zero condition if (x + radius >= canvasWidth/2 || x - radius <= -canvasWidth/2) { return 0; // Condition for Event } copy this inside the Action // Action for Event 1 vx *= -1
  5. 90. Go to HTMLVIEW- Click on Ball image

    Go to HTMLVIEW- Click on Ball image
  6. 91. Click on image

    Click on image
  7. 92. Type "radius*2" for both SizeX and SizeY

  8. 93. Type "radius*2" for both SizeX and SizeY

    reason is SizeX and SizeY are double of the radius

    Type "radius*2" for both SizeX and SizeY
  9. 94. Click on Done

    Click on Done
  10. 95. Go back to Model to introduce your variable

    Go back to Model to introduce your variable
  11. 96. Paste "radius" into input

    Paste "radius" into input
  12. 97. Type "0.1"

    note that the radius cannot be too big like 1 else it will never be able to meet the event on the ODE event.

    Type "0.1"
  13. 98. Add the variable canvasWidth and canvasHeight to the plotingPanel's MinimumX, MaximumX etc , go to Click on View

    Add the variable canvasWidth and canvasHeight to the plotingPanel's MinimumX, MaximumX etc , go to Click on View
  14. 99. Click on image

    Click on image
  15. 100. Click on image

    Click on image
  16. 101. Type "-canvasWidth/2"

    Type "-canvasWidth/2"
  17. 102. Type "canvasWidth/2"

    Type "canvasWidth/2"
  18. 103. Type "-canvasHeight/2"

    Type "-canvasHeight/2"
  19. 104. Copy input titled "canvasHeight/2"

    Copy input titled "canvasHeight/2"
  20. 105. Paste "canvasHeight/2" into input

    Paste "canvasHeight/2" into input
  21. 106. To make the PlottingPanel length x and length y equal, Click on SquareAspect

    To make the PlottingPanel length x and length y equal, Click on SquareAspect
  22. 107. Click on Main

    Click on Main
  23. 108. Click on true

    Click on true
  24. 109. Click on OK

    Click on OK
  25. 110. To make the Width and Height of the PlottingPanel bigger, Click on Width

    To make the Width and Height of the PlottingPanel bigger, Click on Width
  26. 111. Click on Main

    Click on Main
  27. 112. Type "100%" and "90vh" respectively as shown. remember to have the quotation "" else it will cause an error remember strings need "", numbers don't need.

    Type "100%" and "90vh" respectively as shown. remember to have the quotation "" else it will cause an error remember strings need "", numbers don't need.
  28. 113. Example of Error Click on Uncaught ReferenceError: _simulation is not defined (at https://macmath.inf.um.es/static/sessions/78bfa731-67b6-47dd-a7d5-6d9c8a78e9f6/output/_preview.xhtml => line:164)

    Example of Error Click on Uncaught ReferenceError: _simulation is not defined (at https://macmath.inf.um.es/static/sessions/78bfa731-67b6-47dd-a7d5-6d9c8a78e9f6/output/_preview.xhtml => line:164)

Run the simulation on a separate tab for best preview

  1. 114. After the Simulation is loaded up, it will display the conditions here.

    After the Simulation is loaded up, it will display the conditions here.
  2. 115. Click on Run the simulation

    An alternative to watch the simulation is by clicking on the "Run the simulation" icon on the top right corner

    Click on Run the simulation
  3. 116. Simulation should run in a separate tab

    Simulation should run in a separate tab
  4. 117. The simulation should look like this as a result.

    The simulation should look like this as a result.

🌟 Exporting the file

  1. 118. Click on the icon for Simulation properties

    Click on the icon for Simulation properties
  2. 119. Click on "Export options"

    Click on "Export options"
  3. 120. Check "Save the source file in XML format (readable by JavaScript EJS 6)"

    Check "Save the source file in XML format (readable by JavaScript EJS 6)"
  4. 121. Click on "Done" button

    Click on "Done" button
  5. 122. Click on the icon for "Download ZIP with the complete simulation"

    A pop-up window will appear after.

    Click on the icon for "Download ZIP with the complete simulation"
  6. 123. Rename ZIP file to "MovingBall.zip"

    Rename ZIP file to "MovingBall.zip"
  7. 124. Click on Download

    Click on Download
  8. 125. After Extracting the file, click on "simulation.xhtml" to open up the simulation on your default browser.

    After Extracting the file, click on "simulation.xhtml" to open up the simulation on your default browser.