Microsoft Small Basic

Program Listing: CML636
' Kinect Joint Viewer
' Copyright © Nonki Takahashi 2015. The MIT License.
'
joints = "1=AnkleLeft;2=AnkleRight;3=ElbowLeft;4=ElbowRight;"
joints = joints + "5=FootLeft;6=FootRight;7=HandLeft;8=HandRight;"
joints = joints + "9=HandTipLeft;10=HandTipRight;11=Head;12=HipLeft;"
joints = joints + "13=HipRight;14=KneeLeft;15=KneeRight;16=Neck;"
joints = joints + "17=ShoulderLeft;18=ShoulderRight;19=SpineBase;"
joints = joints + "20=SpineMid;21=SpineShoulder;22=ThumbLeft;"
joints = joints + "23=ThumbRight;24=WristLeft;25=WristRight;"
GraphicsWindow.Width = 600
GraphicsWindow.Height = 600
GraphicsWindow.BackgroundColor = "Gray"
GraphicsWindow.FontName = "Trebuchet MS"
GraphicsWindow.BrushColor = "Black"
nJoints = Array.GetItemCount(joints)
For j = 1 To nJoints
txtJoints[j] = Shapes.AddText(joints[j])
Shapes.Move(txtJoints[j], 0, -20)
EndFor
KinectBodyList.BodiesChanged = OnBodiesChanged
KinectBodyList.StartTracking()
While "True"
If bodiesChanged Then
buf = ""
For i = 1 To KinectBodyList.Count
If KinectBodyList.IsTracked(i) Then
n = 0
For j = 1 To nJoints
pos = KinectBodyList.GetJointPosition(i, joints[j])
If pos = "" Then
Shapes.Move(txtJoints[j], 10, -20)
Else
Shapes.Move(txtJoints[j], pos["X"] * 250 + 300, 200 - pos["Y"] * 250)
n = n + 1
EndIf
EndFor
If 22 < n Then
KinectBodyList.StopTracking("True")
EndIf
EndIf
EndFor
bodiesChanged = "False"
EndIf
EndWhile
Sub OnBodiesChanged
bodiesChanged = "True"
EndSub