This is an old revision of the document!
Friction Activity
Here is a link to the google doc where you can find more details on the activity: GISD Workday Activity
Below we have provided some snippets of code you can use by copying into your own glowscript window, modifying the code, and running the program. Any code with a # in front of it is simply a comment (or an editor's note) that defines what the line will make the computer do.
Objects
Here is some code you can use and modify to create objects like blocks and platforms.
MyBox = box(pos=vector(0,0,0), length=1, height=1, width=1, color=color.red) #Create a box object
Motion
Here is some code you can repurpose to define vectors and variables.
v = vector(3,0,0) #Define a velocity vector #Define the time variables (initial time, time-step, final time) for the while loop t = 0 #Define the initial time dt = 0.01 #Define the time-step tf = 2 #Define the final time
Here is some code you can repurpose to add animations to your code (notice the indentation of lines below the while line).
while t < tf: #While loop to iterate over time until we reach the final time rate(100) #Rate keeps animation slow enough to view MyBox.pos = MyBox.pos + v*dt #Position update step to predict location of box after a time-step dt base on v t = t + dt #Update the time to go on to the next time-step after the position update
Acceleration
Here is some code you can repurpose to add acceleration to your simulation. Ultimately, this could be used to make objects slow down using friction (after defining some other variables and calculations).
a = vector(1,0,0) #Define an acceleration vector while t < tf: #While loop to iterate over time rate(100) #Keeps animation slow enough to view v = v + a*dt #Velocity update step to predict velocity of box after a time-step dt MyBox.pos = MyBox.pos + v*dt #Position update step to predict location of box after a time-step dt t = t + dt #Update the time to go on to the next time-step after the position update
Graphing
Here is some code you can use to graph physical quantities in real-time with the animation, such as position or kinetic energy.
PositionGraph = gcurve(color=color.red) #Create graph object for position while t < tf: #While loop to iterate over time rate(100) #Keeps animation slow enough to view MyBox.pos = MyBox.pos + v*dt #Position update step to predict location of box after a time-step dt PositionGraph.plot(t,MyBox.pos.x) #Add a data point to our graph for with the position at time t t = t + dt #Update the time to go on to the next time-step after the position update