Share via


Small Basic Getting Started Guide: Appendix A: Fun Samples

Small Basic > Getting Started Guide > Appendix A: Fun Samples

 

Turtle Fractal

http://msdn.microsoft.com/gg605178.Turtle_drawing_a_tree_fractal(en-us,MSDN.10).jpg

Figure A.1 - Turtle drawing a tree fractal

angle = 30
delta = 10
distance = 60
Turtle.Speed = 9
GraphicsWindow.BackgroundColor = "Black"
GraphicsWindow.PenColor = "LightGreen"
DrawTree()

Sub DrawTree
  If (distance > 0) Then
    Turtle.Move(distance)
    Turtle.Turn(angle)
    
    Stack.PushValue("distance", distance)
    distance = distance - delta
    DrawTree()
    Turtle.Turn(-angle * 2)
    DrawTree()
    Turtle.Turn(angle)
    distance = Stack.PopValue("distance")
    
    Turtle.Move(-distance)
  EndIf
EndSub

 

Photos from Flickr

http://msdn.microsoft.com/gg605178.Retrieving_pictures_from_Flickr(en-us,MSDN.10).jpg

Figure A.2 - Retrieving pictures from Flickr

GraphicsWindow.BackgroundColor = "Black"
GraphicsWindow.MouseDown = OnMouseDown

Sub OnMouseDown
    pic = Flickr.GetRandomPicture("mountains, river")
    GraphicsWindow.DrawResizedImage(pic, 0, 0, 640, 480)
EndSub

 

Dynamic Desktop Wallpaper

For i = 1 To 10
  pic = Flickr.GetRandomPicture("mountains")
  Desktop.SetWallPaper(pic)
  Program.Delay(10000)
EndFor

 

Paddle Game

http://msdn.microsoft.com/gg605178.Paddle_Game(en-us,MSDN.10).jpg

Figure A.3 - Paddle Game

GraphicsWindow.BackgroundColor = "DarkBlue"
paddle = Shapes.AddRectangle(120, 12)
ball = Shapes.AddEllipse(16, 16)
GraphicsWindow.MouseMove = OnMouseMove

x = 0
y = 0
deltaX = 1
deltaY = 1

RunLoop:
  x = x + deltaX
  y = y + deltaY
  
  gw = GraphicsWindow.Width
  gh = GraphicsWindow.Height
  If (x >= gw - 16 or x <= 0) Then
    deltaX = -deltaX
  EndIf
  If (y <= 0) Then
    deltaY = -deltaY
  EndIf
  
  padX = Shapes.GetLeft (paddle)
  If (y = gh - 28 and x >= padX and x <= padX + 120) Then
    deltaY = -deltaY
  EndIf
  
  Shapes.Move(ball, x, y)
  Program.Delay(5)
  
  If (y < gh) Then
    Goto RunLoop
  EndIf

GraphicsWindow.ShowMessage("You Lose", "Paddle")

Sub OnMouseMove
  paddleX = GraphicsWindow.MouseX
  Shapes.Move(paddle, paddleX - 60, GraphicsWindow.Height - 12)
EndSub

 
Next Article