Microsoft Small Basic

Program Listing: TFN794-1
' Walkman 0.3b
' Copyright (c) 2013 Nonki Takahashi. All rights reserved.
'
' History:
' 0.3b 2013-07-11 Added one side movement. (TFN794-1)
' 0.2a 2013-07-07 Changed for Silverlight. (TFN794-0)
' 0.1a 2013-07-05 Created. (TFN794)
'
GraphicsWindow.Title = "Walkman 0.3b"
SB_Workaround()
fh = 10 ' floor height [cm]
gh = GraphicsWindow.Height ' window height [cm]
gw = GraphicsWindow.Width ' window width [cm]
GraphicsWindow.BrushColor = "Gray"
GraphicsWindow.FillRectangle(0, gh - fh, gw, fh)
Man_Add()
For cycle = 1 To 3
Man_WalkOneCycle()
EndFor
Sub Man_Add
man["x"] = gw - 100
man = man + "head=24;neck=12;body=48;ab=-10;j1=48;j2=48;j3=0;j4=0;"
man = man + "l11=36;l12=36;l13=9;l14=12;"
man = man + "a11=-10;a12=30;a13=10;a14=-10;"
man = man + "l21=36;l22=36;l23=9;l24=12;"
man = man + "a21=10;a22=30;a23=10;a24=-10;"
man = man + "l31=48;l32=48;l33=21;l34=7;"
man = man + "a31=10;a32=-20;a33=90;a34=10;"
man = man + "l41=48;l42=48;l43=21;l44=7;"
man = man + "a41=-10;a42=-20;a43=90;a44=10;"
man["y"] = gh - fh - 100
GraphicsWindow.BrushColor = "Black"
GraphicsWindow.PenColor = "Black"
man["oHead"] = Shapes.AddEllipse(man["head"], man["head"])
len = man["body"] + man["neck"] + man["head"] / 2
x0 = man["x"]
y0 = man["y"] - len
_ab = Math.GetRadians(man["ab"])
x = x0 + len * Math.Sin(_ab)
y = y0 - len * (Math.Cos(_ab) - 1)
Shapes.Move(man["oHead"], x - man["head"] / 2, y - man["head"] / 2)
len = man["body"]
man["oBody"] = Shapes.AddLine(0, 0, 0, len)
y0 = man["y"] - len
x = x0 + (len/2) * Math.Sin(_ab)
y = y0 - (len/2) * (Math.Cos(_ab) - 1)
If silverlight Then
alpha = _ab
SB_RotateWorkaround()
EndIf
Shapes.Move(man["oBody"], x, y)
Shapes.Rotate(man["oBody"], man["ab"])
For j = 1 To 4
x0 = man["x"] + man["j"+j] * Math.Sin(_ab)
man["x"+j+0] = x0
y0 = man["y"] - man["j"+j] * Math.Cos(_ab)
man["y"+j+0] = y0
a = man["ab"]
For i = 1 To 4
len = man["l"+j+i]
man["oL"+j+i] = Shapes.AddLine(0, 0, 0, len)
a = a + man["a"+j+i]
_a = Math.GetRadians(a)
x = x0 - (len/2) * Math.Sin(_a)
y = y0 + (len/2) * (Math.Cos(_a) - 1)
If silverlight Then
alpha = _a
SB_RotateWorkaround()
EndIf
Shapes.Move(man["oL"+j+i], x, y)
Shapes.Rotate(man["oL"+j+i], a)
x0 = x0 - len * Math.Sin(_a)
y0 = y0 + len * Math.Cos(_a)
EndFor
EndFor
EndSub
Sub Man_Move
len = man["body"] + man["neck"] + man["head"] / 2
x0 = man["x"]
y0 = man["y"] - len
_ab = Math.GetRadians(man["ab"])
x = x0 + len * Math.Sin(_ab)
y = y0 - len * (Math.Cos(_ab) - 1)
Shapes.Move(man["oHead"], x - man["head"] / 2, y - man["head"] / 2)
len = man["body"]
y0 = man["y"] - len
x = x0 + (len/2) * Math.Sin(_ab)
y = y0 - (len/2) * (Math.Cos(_ab) - 1)
If silverlight Then
alpha = _ab
SB_RotateWorkaround()
EndIf
Shapes.Move(man["oBody"], x, y)
Shapes.Rotate(man["oBody"], man["ab"])
For j = 1 To 4
x0 = man["x"] + man["j"+j] * Math.Sin(_ab)
man["x"+j+0] = x0
y0 = man["y"] - man["j"+j] * Math.Cos(_ab)
man["y"+j+0] = y0
a = man["ab"]
For i = 1 To 4
len = man["l"+j+i]
a = a + man["a"+j+i]
_a = Math.GetRadians(a)
x = x0 - (len/2) * Math.Sin(_a)
y = y0 + (len/2) * (Math.Cos(_a) - 1)
If silverlight Then
alpha = _a
SB_RotateWorkaround()
EndIf
Shapes.Move(man["oL"+j+i], x, y)
Shapes.Rotate(man["oL"+j+i], a)
x0 = x0 - len * Math.Sin(_a)
y0 = y0 + len * Math.Cos(_a)
EndFor
EndFor
EndSub
Sub Man_WalkOneCycle
For c = 0 To 360 Step 10
man["x"] = man["x"] - 4
man["a11"] = -10 + 20 * Math.Sin(Math.GetRadians(c))
man["a21"] = -10 - 20 * Math.Sin(Math.GetRadians(c))
man["a31"] = 10 - 20 * Math.Sin(Math.GetRadians(c))
man["a41"] = 10 + 20 * Math.Sin(Math.GetRadians(c))
Man_Move()
Program.Delay(1000/24)
EndFor
EndSub
Sub SB_RotateWorkaround
' Small Basic | Rotate line workaround for Silverlight
' param x, y - original coordinate
' param len - length of the line
' param alpha - angle [radian]
' returns x, y - workaround coordinate
x1 = -Math.Floor(Math.Abs(0 - 0) / 2)
y1 = -Math.Floor(Math.Abs(0 - len) / 2)
ox = x - x1
oy = y - y1
x = x1 * Math.Cos(alpha) - y1 * Math.Sin(alpha) + ox
y = x1 * Math.Sin(alpha) + y1 * Math.Cos(alpha) + oy
EndSub
Sub SB_Workaround
' Small Basic | Workaround for Silverlight
' returns silverlight - "True" if in remote
color = GraphicsWindow.GetPixel(0, 0)
If Text.GetLength(color) > 7 Then
silverlight = "True"
msWait = 300
Else
silverlight = "False"
EndIf
EndSub