Microsoft Small Basic

Program Listing: QMD035-2
' Snowflake 0.4
' Copyright (c) 2013 Nonki Takahashi. All rights reserved.
'
' History:
' 0.4 2013-12-11 Many snowflakes version. (QMD035-2)
' 0.3 2013-12-10 Changed reflection. (QMD035-1)
' 0.2 2013-12-10 Adjusted timing. (QMD035-0)
' 0.1 2013-12-10 Created. (QMD035)
'
gw = 624
gh = 443
GraphicsWindow.Width = gw
GraphicsWindow.Height = gh
GraphicsWindow.Title = "Snowflake 0.4"
GraphicsWindow.BackgroundColor = "Black"
r = 3
color = "#99FFFFFF"
While "True"
x0 = Math.GetRandomNumber(gw - 100) + 50
y0 = Math.GetRandomNumber(gh - 100) + 50
x = x0
y = y0
GraphicsWindow.BrushColor = "#11000000"
GraphicsWindow.FillRectangle(0, 0, gw, gh)
DrawParticle()
For j = 1 To 60
GetNextXY()
For i = 1 To 6
_a = Math.GetRadians(i * 60)
x = x0 + (_x - x0) * Math.Sin(_a) + (_y - y0) * Math.Cos(_a)
y = y0 + (_x - x0) * Math.Cos(_a) - (_y - y0) * Math.Sin(_a)
DrawParticle()
y = 2 * y0 - y
DrawParticle()
EndFor
x = _x
y = _y
Program.Delay(50)
EndFor
EndWhile
Sub GetNextXY
' param x, y - current x, y
' return _x, _y - next x, y
dir = Math.GetRandomNumber(6) - 1
_dir = Math.GetRadians(dir * 60)
_x = x + r * Math.SquareRoot(3) * Math.Cos(_dir)
_y = y + r * Math.SquareRoot(3) * Math.Sin(_dir)
EndSub
Sub DrawParticle
' Draw Particle
' param x, y - center of hexagon
' param r - circumradius of hexagon
' param color - color of hexagon
GraphicsWindow.BrushColor = color
GraphicsWindow.FillEllipse(x - r, y - r, 2 * r, 2 * r)
EndSub