Microsoft Small Basic

Program Listing: KSV247-4
' New Year Greeting 2015
' Copyright © 2014 Nonki Takahashi. The MIT License.
' Program ID KSV247-4
'
title = "2015"
GraphicsWindow.Title = title
SB_Workaround()
Init()
param = "fn=Verdana;color=#33000000;fs=160;y=180;text=2015;"
param["x"] = (gw - 455) / 2
AddText()
param = "fn=Times New Roman;color=White;fs=24;x=50;y=20;text=I WISH YOU;shadow=True;"
AddText()
param["fs"] = 36
param["y"] = 50
param["text"] = "A HAPPY NEW YEAR !"
AddText()
AddSheep()
While "True"
Program.Delay(200)
For i = 1 To nSheep
a[i] = a[i] - 1
If a[i] <= (-nSheep / 2) * 8 Then
a[i] = (nSheep - nSheep / 2) * 8
EndIf
_a = Math.GetRadians(a[i])
cx = ox + r * Math.Sin(_a)
cy = oy - r * Math.Cos(_a)
x = cx - 200 / 2
y = cy - 150 / 2
Shapes.Move(sheep[i], x, y)
Shapes.Rotate(sheep[i], a[i])
EndFor
If opacity < 100 Then
opacity = opacity + 1
Shapes.SetOpacity(sky, opacity)
EndIf
EndWhile
Sub AddSheep
For i = 1 To nSheep
a[i] = (i - nSheep / 2) * 8
_a = Math.GetRadians(a[i])
cx = ox + r * Math.Sin(_a)
cy = oy - r * Math.Cos(_a)
x = cx - 200 / 2
y = cy - 150 / 2
sheep[i] = Shapes.AddImage(img)
If silverlight Then
Program.Delay(msWait)
EndIf
Shapes.Move(sheep[i], x, y)
Shapes.Rotate(sheep[i], a[i])
Shapes.Zoom(sheep[i], scale, scale)
EndFor
EndSub
Sub AddText
GraphicsWindow.FontName = param["fn"]
GraphicsWindow.FontSize = param["fs"]
x = param["x"]
y = param["y"]
If param["shadow"] Then
GraphicsWindow.BrushColor = "#99000000"
txt = Shapes.AddText(param["text"])
Shapes.Move(txt, x + 2, y + 2)
EndIf
GraphicsWindow.BrushColor = param["color"]
txt = Shapes.AddText(param["text"])
Shapes.Move(txt, x, y)
EndSub
Sub DrawStars
GraphicsWindow.BrushColor = "White"
For i = 1 To 500
x = Math.GetRandomNumber(gw)
y = Math.GetRandomNumber(gh)
size = Math.GetRandomNumber(3)
GraphicsWindow.FillEllipse(x, y, size, size)
EndFor
EndSub
Sub Init
gw = 598
gh = 428
scale = 0.5
GraphicsWindow.Width = gw
GraphicsWindow.Height = gh
GraphicsWindow.PenWidth = 0
GraphicsWindow.BrushColor = "SkyBlue"
sky = Shapes.AddRectangle(gw, gh)
opacity = 0
Shapes.SetOpacity(sky, opacity)
bc = "Black"
GraphicsWindow.BackgroundColor = bc
DrawStars()
url = "http://www.nonkit.com/smallbasic.files/sheep200.png"
img = ImageList.LoadImage(url)
width = 200
height = 150
nSheep = 6
r = gh * 2
ox = gw / 2
oy = gh * 0.3 + r
EndSub
Sub SB_Workaround
' Small Basic | Workaround for Silverlight
' returns silverlight - "True" if in remote
color = GraphicsWindow.GetPixel(0, 0)
If Text.GetLength(color) > 7 Then
silverlight = "True"
msWait = 300
Else
silverlight = "False"
EndIf
EndSub