Differences
This shows you the differences between two versions of the page.
Both sides previous revision Previous revision Next revision | Previous revision Next revision Both sides next revision | ||
2020:genesee_friction_activity_snippets [2020/02/12 07:19] wellerd |
2020:genesee_friction_activity_snippets [2020/02/12 07:37] wellerd |
||
---|---|---|---|
Line 3: | Line 3: | ||
Here is a link to the google doc where you can find more details on the activity: [[https://docs.google.com/document/d/1yGWHwJ3tRL8yq5J3BD2bIPrBk04dghvQxNl029No9xY/edit?usp=sharing | GISD Workday Activity]] | Here is a link to the google doc where you can find more details on the activity: [[https://docs.google.com/document/d/1yGWHwJ3tRL8yq5J3BD2bIPrBk04dghvQxNl029No9xY/edit?usp=sharing | 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. | + | 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. The first line of a Glowscript code must always be... |
+ | |||
+ | <code> | ||
+ | GlowScript 2.9 VPython | ||
+ | </code> | ||
==== Objects ==== | ==== Objects ==== | ||
Line 10: | Line 14: | ||
<code> | <code> | ||
- | MyBox = box(pos=vector(0,0,0), length=1, height=1, width=1, color=color.red) #Create a box object | + | #Create a box object |
+ | MyBox = box(pos=vector(0,0,0), length=1, height=1, width=1, color=color.red) | ||
</code> | </code> | ||
Line 18: | Line 23: | ||
<code> | <code> | ||
- | v = vector(3,0,0) #Define a velocity vector | + | #Define a velocity vector |
+ | v = vector(3,0,0) | ||
- | t = 0 #Define the initial time | + | #Define the time variables (initial time, time-step, final time) |
- | dt = 0.01 #Define the time-step | + | t = 0 |
- | tf = 2 #Define the final time | + | dt = 0.01 |
+ | tf = 2 | ||
</code> | </code> | ||
Line 28: | Line 35: | ||
<code> | <code> | ||
- | while t < tf: #While loop to iterate over time until we reach the final time | + | #While loop to iterate over time until we reach the final time |
+ | while t < tf: | ||
| | ||
- | rate(100) #Rate keeps animation slow enough to view | + | #Rate keeps animation slow enough to view |
+ | rate(100) | ||
| | ||
- | MyBox.pos = MyBox.pos + v*dt #Position update step to predict location of box after a time-step dt base on v | + | #Position update step to predict location of box after a time-step dt base on v |
+ | MyBox.pos = MyBox.pos + v*dt | ||
| | ||
- | t = t + dt #Update the time to go on to the next time-step after the position update | + | #Update the time to go on to the next time-step after the position update |
+ | t = t + dt | ||
</code> | </code> | ||
Line 43: | Line 54: | ||
<code> | <code> | ||
- | a = vector(1,0,0) #Define an acceleration vector | + | #While loop to iterate over time |
+ | while t < tf: | ||
- | while t < tf: #While loop to iterate over time | + | #Keeps animation slow enough to view |
- | + | rate(100) | |
- | 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 | + | #Velocity update step to predict velocity of box after a time-step dt |
+ | v = v + a*dt | ||
| | ||
- | MyBox.pos = MyBox.pos + v*dt #Position update step to predict location of box after a time-step dt | + | #Position update step to predict location of box after a time-step dt |
+ | MyBox.pos = MyBox.pos + v*dt | ||
| | ||
- | t = t + dt #Update the time to go on to the next time-step after the position update | + | #Update the time to go on to the next time-step after the position update |
+ | t = t + dt | ||
</code> | </code> | ||
Line 62: | Line 76: | ||
<code> | <code> | ||
- | PositionGraph = gcurve(color=color.red) #Create graph object for position | + | #Create graph object for position |
+ | PositionGraph = gcurve(color=color.red) | ||
- | while t < tf: #While loop to iterate over time | + | #While loop to iterate over time |
- | rate(100) #Keeps animation slow enough to view | + | while t < tf: |
+ | | ||
+ | #Keeps animation slow enough to view | ||
+ | rate(100) | ||
| | ||
- | MyBox.pos = MyBox.pos + v*dt #Position update step to predict location of box after a time-step dt | + | #Position update step to predict location of box after a time-step dt |
+ | MyBox.pos = MyBox.pos + v*dt | ||
| | ||
- | PositionGraph.plot(t,MyBox.pos.x) #Add a data point to our graph for with the position at time t | + | #Add a data point to our graph for with the position at time t |
+ | PositionGraph.plot(t,MyBox.pos.x) | ||
| | ||
- | t = t + dt #Update the time to go on to the next time-step after the position update | + | #Update the time to go on to the next time-step after the position update |
+ | t = t + dt | ||
</code> | </code> |