Differences

This shows you the differences between two versions of the page.

Link to this comparison view

Both sides previous revision Previous revision
Next revision
Previous revision
summer_2019:glowscript_tips [2019/08/07 17:34]
wellerd
summer_2019:glowscript_tips [2019/08/13 00:27] (current)
wellerd
Line 23: Line 23:
   * **Printing values and text** - The ''​print()''​ command will output any value called from within the parentheses. You can print variables and attributes from your code as a way of checking what numbers the simulation has calculated. The following code creates a conical object named ''​IceCreamCone'',​ and the ''​print(IceCreamCone.size.x)''​ command prints the x-component of the object'​s size attribute. If you want to print text, it must be transformed into a "​string"​ of letters by using quotation marks within the ''​print()''​ command.   * **Printing values and text** - The ''​print()''​ command will output any value called from within the parentheses. You can print variables and attributes from your code as a way of checking what numbers the simulation has calculated. The following code creates a conical object named ''​IceCreamCone'',​ and the ''​print(IceCreamCone.size.x)''​ command prints the x-component of the object'​s size attribute. If you want to print text, it must be transformed into a "​string"​ of letters by using quotation marks within the ''​print()''​ command.
 <​code>​ <​code>​
-IceCreamCone=cone(pos=vec(10,20,0), axis=vec(5,0,0), size=vec(12,3,3+IceCreamCone=cone(pos=vec(0,0,0), axis=vec(0,-5,0), size=vec(3,1,1)
-print(IceCreamCone.size.x)+print("Ice cream cone length:", ​IceCreamCone.size.x)
 print("​Two scoops of butter pecan please!"​) print("​Two scoops of butter pecan please!"​)
 </​code>​ </​code>​
  
 ==== Graphing ==== ==== Graphing ====
-  * **Graphs** - the most convenient graphs in Glowscript utilize the ''​gcurve''​ command which plots a series ​of connected ​data points. In the following code, ''​MyGraph1''​ is needed to set up the graphing window with its various features. The line with ''​HeightGraph''​ names a particular data-set that will be represented ​as a series of connected data points. Lastly, within the while loop, the ''​HeightGraph.plot''​ command is used to ''​plot''​ data points ​along time for our specified data-set.+  * **Graphs** - the most convenient graphs in Glowscript utilize the ''​gcurve''​ command which plots x-y data points as scatterplot and connects the points with a line. In general, Three lines of code are needed to graph in Glowscript... 
 +  - A line above the while loop which creates the axes and titles of the graph (line 3 in the picture below). 
 +  - A line above the while loop which tells the program what you are about to graph (line 4 in the picture below). 
 +  - A line inside of the while loop which plots the respective x-y data point for that iteration of the while loop (line 19 in the picture below). 
 +{{:​summer_2019:​python-trinket-physics.png?​400|}} 
 + 
 +  * **Another graphing example** - In the following code, ''​MyGraph1''​ is needed to set up the graphing window with its various ​axes titles, minimum and maximum boundaries, and other features. The line with ''​HeightGraph''​ names a particular data-set that will be represented ​on our scatterplot. Lastly, ​**within the while loop**, the ''​HeightGraph.plot(t,​Cart.pos.y)''​ command is used to ''​plot''​ data points for our specified data-set ​(''​t''​ will be on the x-axis and ''​Cart.pos.y''​ will be on the y-axis).
 <​code>​ <​code>​
 MyGraph1 = graph(title='​Height vs Time', xtitle='​Time (s)', ytitle='​Height (m)', fast=False) #Name our graph and set some features MyGraph1 = graph(title='​Height vs Time', xtitle='​Time (s)', ytitle='​Height (m)', fast=False) #Name our graph and set some features
Line 41: Line 47:
     Cart.pos=Cart.pos+vec(0,​1,​0)*dt     Cart.pos=Cart.pos+vec(0,​1,​0)*dt
         ​         ​
-    HeightGraph.plot(t,​Cart.pos.y) # This line plots data points as the program iterates+    ​# This line plots data points as the program iterates 
 +    ​HeightGraph.plot(t,​Cart.pos.y) # t will be on the x-axis and Cart.pos.y will be on the y-axis
     ​     ​
     t=t+dt     t=t+dt
  • summer_2019/glowscript_tips.1565199265.txt.gz
  • Last modified: 2019/08/07 17:34
  • by wellerd