1- GlowScript 1.0
2- /* Simulation of dancing pendulums.
1+ GlowScript 2.7 JavaScript
32
4- Run the program and follow the link to the video for more explanation. */
3+ // Simulation of dancing pendulums.
4+
5+ // Run the program and follow the link to the video for more explanation. */
56
67// David Scherer, August 2011
78
9+ function display_instructions ( ) {
10+ var s = "In GlowScript programs:\n"
11+ s += " Rotate the camera by dragging with the right mouse button,\n or hold down the Ctrl key and drag.\n"
12+ s += " To zoom, drag with the left+right mouse buttons,\n or hold down the Alt/Option key and drag,\n or use the mouse wheel.\n"
13+ s += "Touch screen: pinch/extend to zoom, swipe or two-finger rotate."
14+ scene . title = s
15+ }
16+
17+ display_instructions ( )
18+
819var pendulums = [ ]
920
1021var hinge = cylinder ( )
@@ -28,19 +39,15 @@ for(var i=0; i<15; i++) {
2839 pendulums . push ( p )
2940}
3041
31- var link = $ ( "<a/>" ) . prop ( "href" , "http://sciencedemonstrations.fas.harvard.edu/icb/icb.do?keyword=k16940&pageid=icb.page80863&pageContentId=icb.pagecontent341734&state=maximize&view=view.do&viewParam_name=indepth.html#a_icb_pagecontent341734" )
32- link . text ( "Based on this video" )
33- link . appendTo ( $ ( "<div/>" ) . appendTo ( canvas . container ) )
34-
35- var start = performance . now ( )
42+ var start = new Date ( ) . getTime ( )
3643while ( true ) {
37- var t = ( performance . now ( ) - start ) * .001
38- scene . caption . text ( "t=" + t . toFixed ( 1 ) )
44+ var t = ( new Date ( ) . getTime ( ) - start ) * .001
45+ scene . caption = "t=" + t . toFixed ( 1 )
3946 for ( var i = 0 ; i < pendulums . length ; i ++ ) {
4047 var p = pendulums [ i ]
4148 var theta = p . theta0 * cos ( 2 * pi * t / p . period )
4249 p . wire . axis = vec ( sin ( theta ) , - cos ( theta ) , 0 )
4350 p . pos = p . wire . pos + p . wire . axis * p . wire . size . x
4451 }
45- scene . waitfor ( "redraw" , wait )
52+ scene . waitfor ( "redraw" )
4653}
0 commit comments