Microsoft Small Basic

Program Listing: JRT022
'Yoyo on 100 lines program
'jalpc November 2014
'
data_()
GraphicsWindow.Hide()
form_()
shapes_()
GraphicsWindow.Show()
tmpIni=Clock.ElapsedMilliseconds/80
Timer.Tick=OnTick
Timer.Interval=20
sub OnTick
tmp = Clock.ElapsedMilliseconds/80
tmp = tmp - tmpIni
angle=tmp*(360/30)
difr["difY"]=difr["difY"]+difr["dif"]
If (difr["difY"] =difr["difMax"]) Or (difr["difY"] = -difr["difMax"]) Then
difr["dif"]=difr["dif"]*-1
EndIf
movFig()
EndSub
Sub movFig
' Figure rotating
Shapes.rotate(obj[7],angle)
rad = Math.GetRadians(angle)
incr_X = distCenRotExt_X*Math.Cos(rad) - distCenRotExt_Y*Math.Sin(rad)
incr_Y = distCenRotExt_X*Math.Sin(rad) + distCenRotExt_Y*Math.Cos(rad)
posNew_X= posShapRot_X + distCenRotExt_X - incr_X - shap[7]["W"]/2
posNew_Y= posShapRot_Y + distCenRotExt_Y - incr_Y - shap[7]["H"]/2
posNew_Y=posNew_Y+difr["difY"]
Shapes.Move(obj[7],posNew_X,posNew_Y)
'Yoyo Up/Down
For numFig=0 To Array.GetItemCount(shap)-2
x=shap[numFig]["X"]-shap[numFig]["W"]/2
y=shap[numFig]["Y"]-shap[numFig]["H"]/2 +difr["difY"]
Shapes.Move(obj[numFig],x,y)
EndFor
'Eraser rope
Shapes.Move(eraser,x-20,y-30)
EndSub
Sub form_
GraphicsWindow.BackgroundColor="LightBlue"
GraphicsWindow.PenWidth=1
GraphicsWindow.Width=dim["pgW"]
GraphicsWindow.Height=dim["pgH"]
GraphicsWindow.Top=dim["pgTop"]
GraphicsWindow.Left=dim["pgLeft"]
GraphicsWindow.CanResize="False"
GraphicsWindow.Title="yoyo on 100 lines program"
EndSub
Sub shapes_
'rope, ring and eraser
GraphicsWindow.BrushColor="Black"
GraphicsWindow.PenColor="Black"
ring=Shapes.AddEllipse(15,15)
Shapes.Move(ring,(dim["pgW"]/2)-30,27)
rope=Shapes.AddRectangle(5,300)
Shapes.Move(rope,(dim["pgW"]/2)-25,40)
GraphicsWindow.BrushColor="LightBlue"
GraphicsWindow.PenColor="LightBlue"
eraser=Shapes.AddRectangle(30,290)
Shapes.Move(eraser,(dim["pgW"]/2)-30,170)
'Yo-yo
For numFig=0 To Array.GetItemCount(shap)-1
GraphicsWindow.BrushColor=bc[numFig]
GraphicsWindow.PenColor=pc[numFig]
GraphicsWindow.PenWidth=pw[numFig]
obj[numFig]=Shapes.AddEllipse(shap[numFig]["W"],shap[numFig]["H"])
x=shap[numFig]["X"]-shap[numFig]["W"]/2
y=shap[numFig]["Y"]-shap[numFig]["H"]/2
Shapes.Move(obj[numFig],x,y)
EndFor
EndSub
Sub data_
dim="pgW=350;pgH=450;pgLeft=50;pgTop=0;"
difr="difY=0;dif=0.8;difMax=100;"
posIni="posIniX=175;posIniY=180;"
bc="0=Gray;1=White;2=Magenta;3=White;4=Magenta;5=White;6=Magenta;7=Magenta;"
pc="0=Black;1=Black;2=Magenta;3=White;4=Magenta;5=White;6=Magenta;7=Magenta;"
pw="0=2;1=2;2=2;3=2;4=2;5=2;6=2;7=2"
shap[0]="X=180;Y=200;W=100;H=100;"
shap[1]="X=175;Y=200;W=100;H=100;"
shap[2]="X=175;Y=200;W=90;H=90;"
shap[3]="X=175;Y=200;W=70;H=70;"
shap[4]="X=175;Y=200;W=40;H=40;"
shap[5]="X=175;Y=200;W=20;H=20;"
shap[6]="X=175;Y=200;W=15;H=15;"
shap[7]="X=175;Y=200;W=10;H=80;" ' Figure rotating
moveCenMed_X = 0
moveCenMed_Y = 0
posShapRot_X=posIni["posIniX"] - moveCenMed_X
posShapRot_Y=posIni["posIniY"] - moveCenMed_Y + 20
distCenRotExt_X = moveCenMed_X
distCenRotExt_Y = moveCenMed_Y
EndSub