Microsoft Small Basic

Program Listing: QMD035
' Snow Flake 0.1
' Copyright (c) 2013 Nonki Takahashi. All rights reserved.
'
gw = 624
gh = 443
GraphicsWindow.Width = gw
GraphicsWindow.Height = gh
GraphicsWindow.Title = "Snow Flake 0.1"
GraphicsWindow.BackgroundColor = "Black"
x0 = gw / 2
y0 = gh / 2
r = 2
color = "#CCFFFFFF"
While "True"
x = x0
y = y0
GraphicsWindow.Clear()
DrawParticle()
For j = 1 To 400
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()
xs = x
x = y - y0 + x0
y = xs - x0 + y0
DrawParticle()
EndFor
x = _x
y = _y
EndFor
Program.Delay(3000)
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