DrawScript

home.gif


Newton's Cradle


A simple animation of the popular toy

cradle.gif

·Zoom(2/3)
·BoundBox(3,2,14,5)
·Fill(0) : ·Width(2)

FOR i=0 TO 8
PROCCradle(7,7,1,4,i*PI/4/8) : ·SaveDrawing("cradle"+STR$(i))
PROCCradle(7,7,1,4,(8-i)*PI/4/8) : ·SaveDrawing("cradle"+STR$(i+9))
PROCCradle(7,7,1,4,-i*PI/4/8) : ·SaveDrawing("cradle"+STR$(i+18))
PROCCradle(7,7,1,4,-(8-i)*PI/4/8) : ·SaveDrawing("cradle"+STR$(i+27))
NEXT
END

DEF PROCCradle(a,b,r,length,theta)
IF theta>0 THEN PROCBall(a,b,r,length,0) ELSE PROCBall(a,b,r,length,theta)
PROCBall(a+2*r,b,r,length,0)
PROCBall(a+4*r,b,r,length,0)
IF theta>0 THEN
PROCBall(a+6*r,b,r,length,theta)
ELSE
PROCBall(a+6*r,b,r,length,0)
ENDIF
ENDPROC

DEF PROCBall(x,y,r,length,theta)
LOCAL xc,yc
IF theta<0 THEN
xc=x-length*SIN(-theta) : yc=y-length*COS(-theta)
ELSE
xc=x+length*SIN(theta) : yc=y-length*COS(theta)
ENDIF
·Line(x,y,xc,yc)
·Circle(xc,yc,r)
ENDPROC