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.

#Create a box object
MyBox = box(pos=vector(0,0,0), length=1, height=1, width=1, color=color.red)

Motion

Here is some code you can repurpose to define vectors and variables.

#Define a velocity vector
v = vector(3,0,0)

#Define the time variables (initial time, time-step, final time)
t = 0 
dt = 0.01
tf = 2

Here is some code you can repurpose to add animations to your code (notice the indentation of lines below the while line).

#While loop to iterate over time until we reach the final time
while t < tf:
    
    #Rate keeps animation slow enough to view
    rate(100)
    
    #Position update step to predict location of box after a time-step dt base on v
    MyBox.pos = MyBox.pos + v*dt
    
    #Update the time to go on to the next time-step after the position update
    t = t + dt

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).

#Define an acceleration vector
a = vector(1,0,0)

#While loop to iterate over time
while t < tf:

    #Keeps animation slow enough to view
    rate(100)
    
    #Velocity update step to predict velocity of box after a time-step dt
    v = v + a*dt
    
    #Position update step to predict location of box after a time-step dt
    MyBox.pos = MyBox.pos + v*dt
    
    #Update the time to go on to the next time-step after the position update
    t = t + dt

Graphing

Here is some code you can use to graph physical quantities in real-time with the animation, such as position or kinetic energy.

#Create graph object for position
PositionGraph = gcurve(color=color.red)

#While loop to iterate over time
while t < tf:
    
    #Keeps animation slow enough to view
    rate(100)
    
    #Position update step to predict location of box after a time-step dt
    MyBox.pos = MyBox.pos + v*dt
    
    #Add a data point to our graph for with the position at time t
    PositionGraph.plot(t,MyBox.pos.x)
    
    #Update the time to go on to the next time-step after the position update
    t = t + dt
  • 2020/genesee_friction_activity_snippets.1581492147.txt.gz
  • Last modified: 2020/02/12 07:22
  • by wellerd