Microsoft Small Basic

Program Listing: RWS502
' Sample Code for Shapes Object

Init()
' Prepare an image
url = "http://gallery.technet.microsoft.com/Turtle-PNG-Bitmap-for-582b449c/file/116666/1/Turtle.png"
image = ImageList.LoadImage(url)

While "True"

' Add an image
GraphicsWindow.Title = title + " - AddImage()"
shp["img"] = Shapes.AddImage(image)
Shapes.Move(shp["img"], 10, 10)
Program.Delay(500)

' Add an ellipse
GraphicsWindow.Title = title + " - AddEllipse()"
GraphicsWindow.BrushColor = "Orange"
width = 80
height = 50
shp["ell"] = Shapes.AddEllipse(width, height)
Shapes.Move(shp["ell"], 10, 310)
Program.Delay(500)

' Add a line
GraphicsWindow.Title = title + " - AddLine()"
x1 = 0
y1 = 50
x2 = 80
y2 = 0
shp["line"] = Shapes.AddLine(x1, y1, x2, y2)
Shapes.Move(shp["line"], 110, 310)
Program.Delay(500)

' Add a rectangle
GraphicsWindow.Title = title + " - AddRectagle()"
GraphicsWindow.BrushColor = "Red"
shp["rect"] = Shapes.AddRectangle(width, height)
Shapes.Move(shp["rect"], 210, 310)
Program.Delay(500)

' Add a text and set (update) a text
GraphicsWindow.Title = title + " - AddText()"
txt = "Hello,"
GraphicsWindow.BrushColor = "DimGray"
shp["txt"] = Shapes.AddText(txt)
Shapes.Move(shp["txt"], 310, 310)
Program.Delay(2000)
txt = "World!"
Shapes.SetText(shp["txt"], txt)

' Add a triangle
GraphicsWindow.Title = title + " - AddTriangle()"
x1 = 0
y1 = 50
x2 = 80
y2 = 0
x3 = 80
y3 = 50
GraphicsWindow.BrushColor = "RoyalBlue"
shp["tri"] = Shapes.AddTriangle(x1, y1, x2, y2, x3, y3)
Shapes.Move(shp["tri"], 410, 310)
Program.Delay(3000)

' Get the left coodinate
GraphicsWindow.Title = title + " - GetLeft()"
x = Shapes.GetLeft(shp["rect"])
' Get the top coodinate
GraphicsWindow.Title = title + " - GetTop()"
y = Shapes.GetTop(shp["rect"])
' Animate (move) the rectangle
GraphicsWindow.Title = title + " - Animate()"
duration = 3000
x = x + 100
y = y - 100
Shapes.Animate(shp["rect"], x, y, duration)
Program.Delay(3000)

' Move the triangle
GraphicsWindow.Title = title + " - Move()"
x = x + 100
Shapes.Move(shp["tri"], x, y)
Program.Delay(500)

' Rotate the line
GraphicsWindow.Title = title + " - Rotate()"
For angle = 0 To 270
Shapes.Rotate(shp["line"], angle)
Program.Delay(10)
EndFor

' Zoom the image
GraphicsWindow.Title = title + " - Zoom()"
scaleX = 1
For scaleY = 1 To 0.1 Step - 0.05
Shapes.Zoom(shp["img"], scaleX, scaleY)
scaleX = scaleX + 1
Program.Delay(300)
EndFor

' Get opacity and set opacity of the rectangle
GraphicsWindow.Title = title + " - GetOpacity()/SetOpacity()"
For i = 1 To 5
op = Shapes.GetOpacity(shp["rect"])
op = op - 10
Shapes.SetOpacity(shp["rect"], op)
Program.Delay(1000)
EndFor

' Hide and show the ellipse
GraphicsWindow.Title = title + " - HideShape()/ShowShape()"
Shapes.HideShape(shp["ell"])
Program.Delay(1000)
Shapes.ShowShape(shp["ell"])

' Remove all shapes
GraphicsWindow.Title = title + " - Remove()"
n = Array.GetItemCount(shp)
index = Array.GetAllIndices(shp)
For i = 1 To n
Program.Delay(1000)
Shapes.Remove(shp[index[i]])
EndFor

GraphicsWindow.Title = title
Program.Delay(2000)
EndWhile

Sub Init
gw = 598
gh = 428
GraphicsWindow.Width = gw
GraphicsWindow.Height = gh
title = "Sample for Shapes Object"
GraphicsWindow.Title = title
GraphicsWindow.PenWidth = 4
GraphicsWindow.PenColor = "Black"
GraphicsWindow.FontSize = 30
GraphicsWindow.FontName = "Trebuchet MS"
EndSub