Small Basic: Walking man (Code)


walkman

Excellent  program written by NaoChanOn

Challenge of the month July 2013 // Walking man by NaochanON

Program Code:

Shapes_Init()

Shapes_Add()

 

While (pos<1100)

   dx=6

   dy=2

   MM=MM+5

   walking()

   If -30<MM And  MM<30 Then

     NN=MM

   ElseIf 30<=MM and MM<90 Then

     NN=60-MM

   Elseif MM=90 then

     MM=-30

   EndIf

   Program.Delay(200)

endwhile

 

Sub armlegmoving

   rad=math.GetRadians(NN)

   ‘————————————– Arm & Hand —————————————————————————————

  ArmCP=»X=»+(shapes.GetLeft(shp[7][«obj»])+shp[7][«width»]/2)+»;Y=»+(shapes.Gettop(shp[7][«obj»]))

   ArmDR= shp[5][«height»]/2

   Shapes.Rotate(shp[8][«obj»],NN)                                        ‘ Left arm // backward

   Shapes.Move(shp[8][«obj»],ArmCP[«X»]- ArmDR*Math.Sin(rad), ArmCP[«Y»]+ArmDR*Math.cos(rad)-(shp[5][«y»]-shp[7][«y»]))

   Shapes.Rotate(shp[9][«obj»],NN)                                        ‘ Left hand // backward

   Shapes.Move(shp[9][«obj»],ArmCP[«X»]- 2*ArmDR*Math.Sin(rad), ArmCP[«Y»]+2*ArmDR*Math.cos(rad)+shp[6][«height»]/2)

   Shapes.Rotate(shp[5][«obj»],-NN)                                        ‘ Right arm // forward

   Shapes.Move(shp[5][«obj»],ArmCP[«X»]+ArmDR*Math.Sin(rad), ArmCP[«Y»]+ArmDR*Math.cos(rad) -(shp[8][«y»]-shp[7][«y»]) )

   Shapes.Rotate(shp[6][«obj»],-NN)                                        ‘ Right hand// forward

   Shapes.Move(shp[6][«obj»],ArmCP[«X»]+ 2*ArmDR*Math.Sin(rad), ArmCP[«Y»]+2*ArmDR*Math.cos(rad)+shp[9][«height»]/2)

   ‘————————————– Leg & Foot ————————————————————————————— —————-

  LegCP=»X=»+(shapes.GetLeft(shp[7][«obj»])+shp[7][«width»]/2-5)+»;Y=»+(shapes.Gettop(shp[7][«obj»]) +shp[7][«height»]-5) ‘ 5… adjustment

   LegDR=shp[10][«height»]/2

   Shapes.Rotate(shp[10][«obj»],NN)                                        ‘ Left leg // backward

   Shapes.Move(shp[10][«obj»],LegCP[«X»]- LegDR*Math.Sin(rad), LegCP[«Y»])

   Shapes.Rotate(shp[11][«obj»],NN)                                        ‘ Left foot // backward

   Shapes.Move(shp[11][«obj»],LegCP[«X»]- 2*LegDR*Math.Sin(rad), LegCP[«Y»]+2*LegDR*Math.cos(rad))

   Shapes.Rotate(shp[12][«obj»],-NN)                                        ‘ Right leg// forward

   Shapes.Move(shp[12][«obj»],LegCP[«X»]+ LegDR*Math.Sin(rad), LegCP[«Y»])

   Shapes.Rotate(shp[13][«obj»],-NN)                                        ‘ Left foot // forward

   Shapes.Move(shp[13][«obj»],LegCP[«X»]+ 2*LegDR*Math.Sin(rad), LegCP[«Y»]+2*LegDR*Math.cos(rad))

EndSub

 

Sub walking

   For k=1 To  Array.GetItemCount(shp)

     Shapes.Move(shp[k][«obj»],Shapes.GetLeft(shp[k][«obj»])+dx,Shapes.Gettop(shp[k][«obj»])+dy)

   endfor

   pos=Shapes.GetLeft(shp[1][«obj»])

   armlegmoving()

EndSub

 

Sub Shapes_Add

   GraphicsWindow.BackgroundColor=»Lightcyan»

   GraphicsWindow.Width=1200

   GraphicsWindow.Height=700

   For i = 1 To Array.GetItemCount(shp)

     GraphicsWindow.PenWidth = shp[i][«pw»]

     GraphicsWindow.PenColor = shp[i][«pc»]

     GraphicsWindow.BrushColor = shp[i][«bc»]

     If shp[i][«func»] = «rect» Then

       shp[i][«obj»] = shapes.AddRectangle(shp[i][«width»], shp[i][«height»])

     ElseIf shp[i][«func»] = «ell» Then

       shp[i][«obj»] = shapes.AddEllipse(shp[i][«width»], shp[i][«height»])

     ElseIf shp[i][«func»] = «tri» Then

       shp[i][«obj»] = shapes.AddTriangle(shp[i][«x1»], shp[i][«y1»], shp[i][«x2»], shp[i][«y2»], shp[i][«x3»], shp[i][«y3»] )

     ElseIf shp[i][«func»] = «line» Then

       shp[i][«obj»] = shapes.AddLine(shp[i][«x1»], shp[i][«y1»], shp[i][«x2»], shp[i][«y2»])

     EndIf

     Shapes.Move(shp[i][«obj»], X0 + shp[i][«x»], Y0 + shp[i][«y»])

     If shp[i][«angle»] <> 0 Then

       Shapes.Rotate(shp[i][«obj»], shp[i][«angle»])

     EndIf

   EndFor

EndSub

 

Sub Shapes_Init

   X0 = 10        ‘ x offset

   Y0 = 50       ‘ y offset

   shp[1] = «func=ell;x=42;y=0;width=34;height=45;bc=#EB9869;pc=#EB9869;pw=2;»               ‘ face

   shp[2] = «func=line;x=65;y=13;x1=0;y1=0;x2=8;y2=1;pc=#6A5ACD;pw=4;»                       ‘ Eye

   shp[3] = «func=line;x=65;y=29;x1=0;y1=0;x2=8;y2=3;pc=#F80800;pw=2;»                       ‘ mouse

   shp[4] = «func=tri;x=74;y=17;x1=0;y1=0;x2=10;y2=8;x3=0;y3=12;angle=0;bc=#EB9869;pc=#EB9869;pw=1;»  ‘nose

   shp[5] = «func=rect;x=53;y=50;width=8;height=60;angle=0;bc=#6A5ACD;pc=#000000;pw=1;»      ‘ Left arm

   shp[6] = «func=ell;x=53;y=110;width=13;height=22;angle=0;bc=#EB9869;pc=#EB9869;pw=8;»     ‘ Left hand

   shp[7] = «func=ell;x=40;y=42;width=33;height=103;bc=#00AA00;pc=#00AA00;pw=2;»             ‘ body

   shp[8] = «func=rect;x=53;y=50;width=8;height=60;angle=0;bc=#00BB00;pc=#000000;pw=1;»      ‘ Right arm

   shp[9] = «func=ell;x=53;y=110;width=13;height=22;angle=0;bc=#EB9869;pc=#EB9869;pw=2;»     ‘ Right hand

   shp[10] = «func=rect;x=50;y=140;width=12;height=71;angle=0;bc=#6A5ACD;pc=#6A5ACD;pw=2;»   ‘ left Leg

   shp[11] = «func=ell;x=50;y=209;width=33;height=13;angle=0;bc=#BED3CA;pc=#414C3E;pw=2;»    ‘ left foot

   shp[12] = «func=rect;x=50;y=140;width=12;height=71;angle=0;bc=#00AA00;pc=#6A5ACD;pw=2;»   ‘ Right Leg

   shp[13] = «func=ell;x=50;y=209;width=33;height=13;angle=0;bc=#1AD3CA;pc=#414C3E;pw=2;»    ‘ Right foot

EndSub

Shapes Editor – Small Basic Featured Program


shape

Small Basic  The Official Blog of Small Basic

 

Ed Price – MSFT  Microsoft      From Nonki Takahashi:

What’s New in Shapes 1.42 :

  • Supported cursor key to move a shape.
  • New UI for consecutive shapes addition.
  • Added instruction in save popup.

http://blogs.msdn.com/b/smallbasic/archive/2013/06/14/shapes-editor-small-basic-featured-program.aspx

Small Basic Forum – Desafío del Mes – abril 2013


a2

Editado por litdev  Microsoft Community Contributor, Moderador Lunes, 01 de abril 2013 17:41
Sugerencia Comunidad 2 (Por Nonki)
(1) Dibuje la red de un dado (dados).
(2) Haz un dibujo de una flor.
(3) Haz un dibujo de un coche
Esta es mi muestra de Sugerencia Comunidad 2 (1):
Program Listing MDB491. Nonki Takahashi.

http://social.msdn.microsoft.com/Forums/en-US/smallbasic/thread/7239821c-161c-4328-b29d-7c55e40b11b9

Dibujando y rellenando formas (MS Small Basic)


Capítulo 6 – Manual de Small Basic

Siempre dentro de GraphicsWindows (ventana de gráficos), usamos la función Draw (dibujar) y Fill (rellenar).

Cada vez que tipeamos una función u operación A la derecha de la pantalla nos explica que es lo que hacen éstas. ¿ La miró alguna vez?.

Abra desde el escritorio un archivo Small Basic. Guardelo en su carpeta de usuario como figura30.

Escriba las instrucciones para dibujar un rectángulo (solo el entorno) con los bordes de color rojo (PenColor).

A continuación rellene un rectángulo con el color verde (BrushColor)

Si se fija a la derecha del escritorio, le mostrará que en los paréntesis después de la función van las coordenadas x e y, del punto donde se empieza a dibujar( Draw) o pintar(Brush) y el largo y el ancho de la figura.

Como ambos rectángulos serán del mismo tamaño, ¿ que debe cambiar en las instrucciones para que los rectángulos no se superpongan?

(agreguelo en el comentario). Lea abajo de la figura 30 del manual y lo encontrará perfectamente explicado.

¿ Le salió ?. ¿ Lo entendió ?

Haga lo mismo con la figura 31. Obvio el archivo se llamará figura31

¿ Bien ?. Es sencillo ¿no?

Ahora, repita el procedimiento para la figura 32

Óptimo. Más sencillo imposible.

Y ahora demuestreme que lo entendió. Si leyó y entendió las instrucciones de los programas de arriba, ésto le será muy sencillo.

Abra un archivo Small Basic y lo nombra figura_mia, escriba las instrucciones para que en el mismo archivo, le aparezcan: un rectángulo de color azul, una elipse de color rojo, un círculo de color amarillo y un triángulo (epaaa…es también con fill) de color negro.

Agregue en el comentario, lo que le contaría a una amiga o a su familia, como funciona GraphicsWindow en MS Small Basic.