Small BASIC
A programming language created by Microsoft that serves a stepping stone for beginners from block-based coding languages to more complex text-based languages.
280 questions
This browser is no longer supported.
Upgrade to Microsoft Edge to take advantage of the latest features, security updates, and technical support.
Once we tried to create a marionette program.
Challenge of this month will be:
Super Challenge
Write a program of a marionette that can be controlled with micro:bit sensors.
update with 2 dollies: TCB606-1
This is my first step:
' 3D Marionette Sample
' Copyright © 2021 Nonki Takahashi. The MIT License.
'
GraphicsWindow.Title = "3D Marionette"
GraphicsWindow.BackgroundColor = "SkyBlue"
gw = 500
gh = 500
GraphicsWindow.Width = gw
GraphicsWindow.Height = gh
'Create a view and load an image
view = LD3DView.AddView(gw, gh, "True")
' add a body (pipe)
color = "BurlyWood"
eye = "#333333"
len = 3
diameter[1] = 1.6
obj[1] = LD3DView.AddPipe(view, len, 0, diameter[1], 18, color, "D")
' add arms (4 pipes)
diameter[2] = 0.4
obj[2] = LD3DView.AddPipe(view, len / 2, 0, diameter[2], 18, color, "D")
LD3DView.TranslateGeometry(view, obj[2], -(diameter[1] + diameter[2]) / 2, len / 2, 0)
obj[3] = LD3DView.AddPipe(view, len / 2, 0, diameter[2], 18, color, "D")
LD3DView.TranslateGeometry(view, obj[3], -(diameter[1] + diameter[2]) / 2, 0, 0)
LD3DView.RotateGeometry(view, obj[3], 1,0,0, -45)
obj[4] = LD3DView.AddPipe(view, len / 2, 0, diameter[2], 18, color, "D")
LD3DView.TranslateGeometry(view, obj[4], (diameter[1] + diameter[2]) / 2, len / 2, 0)
obj[5] = LD3DView.AddPipe(view, len / 2, 0, diameter[2], 18, color, "D")
LD3DView.TranslateGeometry(view, obj[5], (diameter[1] + diameter[2]) / 2, 0, 0)
LD3DView.RotateGeometry(view, obj[5], 1,0,0, -45)
' add a head (sphere)
radius = 1
obj[6] = LD3DView.AddSphere(view, radius, 10, color, "D")
LD3DView.TranslateGeometry(view, obj[6], 0, len + radius, 0)
' add nose (pipe)
diameter[7] = 0.3
obj[7] = LD3DView.AddPipe(view, radius * 0.8, 0, diameter[7], 18, color, "D")
LD3DView.TranslateGeometry(view, obj[7], 0, len + radius * 0.5, radius)
LD3DView.RotateGeometry(view, obj[7], 1,0,0, 90)
' add eyes (2 spheres)
obj[8] = LD3DView.AddSphere(view, 0.1, 10, eye, "D")
LD3DView.TranslateGeometry(view, obj[8], -radius * 0.4, len + radius * 1.2, radius)
obj[9] = LD3DView.AddSphere(view, 0.1, 10, eye, "D")
LD3DView.TranslateGeometry(view, obj[9], radius * 0.4, len + radius * 1.2, radius)
' add feet (2 pipes)
diameter[10] = 0.8
obj[10] = LD3DView.AddPipe(view, len / 10, 0, diameter[10], 18, color, "D")
LD3DView.TranslateGeometry(view, obj[10], -diameter[10] / 2, 0, diameter[1])
obj[11] = LD3DView.AddPipe(view, len / 10, 0, diameter[10], 18, color, "D")
LD3DView.TranslateGeometry(view, obj[11], diameter[10] / 2, 0, diameter[1])
' add legs (4 pipes)
diameter[12] = 0.4
obj[12] = LD3DView.AddPipe(view, len / 2, 0, diameter[12], 18, color, "D")
LD3DView.TranslateGeometry(view, obj[12], -diameter[10] / 2, len / 10, diameter[1])
LD3DView.RotateGeometry(view, obj[12], 1,0,0, -10)
obj[13] = LD3DView.AddPipe(view, len / 2, 0, diameter[12], 18, color, "D")
LD3DView.TranslateGeometry(view, obj[13], -(diameter[10] - diameter[12]) / 2, 0, diameter[1] / 2)
LD3DView.RotateGeometry(view, obj[13], 1,0,0, 10)
obj[14] = LD3DView.AddPipe(view, len / 2, 0, diameter[12], 18, color, "D")
LD3DView.TranslateGeometry(view, obj[14], diameter[10] / 2, len / 10, diameter[1])
LD3DView.RotateGeometry(view, obj[14], 1,0,0, -10)
obj[15] = LD3DView.AddPipe(view, len / 2, 0, diameter[12], 18, color, "D")
LD3DView.TranslateGeometry(view, obj[15], (diameter[10] - diameter[12]) / 2, 0, diameter[1] / 2)
LD3DView.RotateGeometry(view, obj[15], 1,0,0, 10)
' add a floor image
path = Program.Directory + "\grid.png"
img = ImageList.LoadImage(path)
points = "-10 -1 10:10 -1 10:10 -1 -10 : -10 -1 10:10 -1 -10:-10 -1 -10"
indices = "0 1 2 3 4 5"
floor = LD3DView.AddGeometry(view, points, indices, "", "White", "D")
textures = "0 1: 1 1: 1 0: 0 1: 1 0: 0 0"
LD3DView.AddImage(view, floor, textures, img, "D")
' some different light types
spot = LD3DView.AddSpotLight(view, "#999999", -3,8,5, 1,-1,-1, 45, 10)
LD3DView.AddDirectionalLight(view, "#333333", 0,-1,0)
LD3DView.AddAmbientLight(view, "#999999")
' initial camera position and direction and view angle
x = 1
y = 2
z = 3
p = LDText.Split("-3,5,8", ",")
d = LDText.Split("0.5,-0.5,-1", ",")
LD3DView.ResetCamera(view, p[x],p[y],p[z], d[x],d[y],d[z], "","","")
Following youtube may help to think about marionette controll.