Microsoft Small Basic

Program Listing: VQP503
' Sample Code for GraphicsWindow 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"
ShowProperties()

' Draw an image
GraphicsWindow.Title = title + " - DrawImage()"
GraphicsWindow.DrawImage(image, 10, 10)
Program.Delay(500)

' Draw a resized image
GraphicsWindow.Title = title + " - DrawResizedImage()"
GraphicsWindow.DrawResizedImage(image, 240, 10, 100, 100)
Program.Delay(500)

' Fill an ellipse
GraphicsWindow.Title = title + " - FillEllipse()"
GraphicsWindow.BrushColor = "Orange"
width = 80
height = 50
GraphicsWindow.FillEllipse(10, 310, width, height)
Program.Delay(500)

' Draw an ellipse
GraphicsWindow.Title = title + " - DrawEllipse()"
GraphicsWindow.DrawEllipse(10, 310, width, height)
Program.Delay(500)

' Draw a line
GraphicsWindow.Title = title + " - DrawLine()"
x1 = 0
y1 = 50
x2 = 80
y2 = 0
GraphicsWindow.DrawLine(110 + x1, 310 + y1, 110 + x2, 310 + y2)
Program.Delay(500)

' Fill a rectangle
GraphicsWindow.Title = title + " - FillRectagle()"
GraphicsWindow.BrushColor = "Red"
GraphicsWindow.FillRectangle(210, 310, width, height)
Program.Delay(500)

' Draw a rectangle
GraphicsWindow.Title = title + " - DrawRectagle()"
GraphicsWindow.DrawRectangle(210, 310, width, height)
Program.Delay(500)

' Draw a text
GraphicsWindow.Title = title + " - DrawText()"
txt = "Hello, World!"
GraphicsWindow.BrushColor = "DimGray"
GraphicsWindow.DrawText(310, 310, txt)
Program.Delay(500)

' Fill a triangle
GraphicsWindow.Title = title + " - FillTriangle()"
x1 = 0
y1 = 50
x2 = 80
y2 = 0
x3 = 80
y3 = 50
GraphicsWindow.BrushColor = "RoyalBlue"
GraphicsWindow.FillTriangle(500 + x1, 310 + y1, 500 + x2, 310 + y2, 500 + x3, 310 + y3)
Program.Delay(500)

' Fill a triangle
GraphicsWindow.Title = title + " - DrawTriangle()"
GraphicsWindow.DrawTriangle(500 + x1, 310 + y1, 500 + x2, 310 + y2, 500 + x3, 310 + y3)
Program.Delay(500)

' Get a pixel and set the pixel
GraphicsWindow.Title = title + " - GetPixel(), SetPixel()"
For y = 10 To 109
For x = 290 To 339
color = GraphicsWindow.GetPixel(x, y)
If color <> "#000000" Then
color = "#" + Text.GetSubTextToEnd(color, 6) + Text.GetSubText(color, 2, 4)
GraphicsWindow.SetPixel(x, y, color)
EndIf
EndFor
EndFor
Program.Delay(500)

' Clear the graphics window
GraphicsWindow.Title = title + " - Clear()"
GraphicsWindow.Clear()
Program.Delay(500)

' Set the window title
GraphicsWindow.Title = title

ChangeProperties()
EndWhile

Sub Init
CRLF = Text.GetCharacter(13) + Text.GetCharacter(10)
gw = 598
gh = 428
GraphicsWindow.Width = gw
GraphicsWindow.Height = gh
title = "Sample for GraphicsWindow Object"
GraphicsWindow.Title = title
GraphicsWindow.PenWidth = 4
GraphicsWindow.PenColor = "Black"
GraphicsWindow.FontSize = 30
GraphicsWindow.FontName = "Trebuchet MS"
EndSub

Sub ShowProperties
bg = GraphicsWindow.BackgroundColor
fb = GraphicsWindow.FontBold
fi = GraphicsWindow.FontItalic
fn = GraphicsWindow.FontName
fs = GraphicsWindow.FontSize
pc = GraphicsWindow.PenColor
pw = GraphicsWindow.PenWidth
buf = "BackgroundColor = " + bg + CRLF
buf = buf + "FontBold = " + fb + CRLF
buf = buf + "FontItalic = " + fi + CRLF
buf = buf + "FontName = " + fn + CRLF
buf = buf + "FontSize = " + fs + CRLF
buf = buf + "PenColor = " + pc + CRLF
buf = buf + "PenWidth = " + pw + CRLF
GraphicsWindow.FontSize = 14
GraphicsWindow.BrushColor = "#333333"
GraphicsWindow.Title = title + " - DrawBoundText()"
GraphicsWindow.DrawBoundText(370, 10, 200, buf)
Program.Delay(500)
GraphicsWindow.FontSize = fs
EndSub

Sub ChangeProperties
' Change the pen width
pw = 2 *pw
If 16 < pw Then
pw = 4
EndIf
GraphicsWindow.PenWidth = pw

' Change the pen color
If pc = "#000000" Then
pc = GraphicsWindow.GetRandomColor()
Else
pc = "Black"
EndIf
GraphicsWindow.PenColor = pc

' Change the font size
fs = fs * 0.8
If fs < 10 Then
fs = 30
EndIf
GraphicsWindow.FontSize = fs

' Change the font name
If fn = "Trebuchet MS" Then
fn = "Times New Roman"
ElseIf fn = "Times New Roman" Then
fn = "Courier New"
Else
fn = "Trebuchet MS"
EndIf
GraphicsWindow.FontName = fn


' Change the font bold
If fb Then
fb = "False"
Else
fb = "True"
EndIf
GraphicsWindow.FontBold = fb

' Change the font italic
If fi Then
fi = "False"
Else
fi = "True"
EndIf
GraphicsWindow.FontItalic = fi

' Change the background color
If bg = "#FFFFFF" Then
bg = GraphicsWindow.GetColorFromRGB(0, 255, 255)
ElseIf bg = "#00FFFF" Then
bg = "Pink"
Else
bg = "White"
EndIf
GraphicsWindow.BackgroundColor = bg
EndSub