Microsoft Small Basic

Program Listing: ZBG645
' Snow Flakes
' Copyright © 2018 Nonki Takahashi. The MIT License.

GraphicsWindow.Title = "Snow Flakes"
Init()
While "True"
For row = 1 To 7
oy = gh / 2 + (row - 4) * h
If Math.Remainder(row, 2) = 0 Then
max = 9
x0 = gw / 2
Else
max = 8
x0 = gw / 2 + w / 2
EndIf
For col = 1 To max
ox = x0 + (col - 5) * w
SnowFlake()
For angle = 30 To 330 Step 60
DrawTriangle()
EndFor
EndFor
EndFor
Program.Delay(3000)
EndWhile

Sub DrawTriangle
y = oy
x = ox
GraphicsWindow.BrushColor = bc
_x[1] = x
_y[1] = y
_x[2] = x - (n + 1) * size / 2
_y[2] = y + (n + 1) * root3 * size / 2
_x[3] = x + (n + 1) * size / 2
_y[3] = y + (n + 1) * root3 * size / 2
Rotate()
GraphicsWindow.FillTriangle(_x[1], _y[1], _x[2], _y[2], _x[3], _y[3])
GraphicsWindow.BrushColor = fc
For i = 1 To n
m = (i - 1) * 2 + 1
For j = 1 To m
If snow[i][j] Then
If Math.Remainder(j, 2) = 1 Then
_x[1] = x
_y[1] = y
_x[2] = x - size / 2
_y[2] = y + root3 * size / 2
_x[3] = x + size / 2
_y[3] = y + root3 * size / 2
Else
_x[1] = x
_y[1] = y + root3 * size / 2
_x[2] = x - size / 2
_y[2] = y
_x[3] = x + size / 2
_y[3] = y
EndIf
Rotate()
GraphicsWindow.FillTriangle(_x[1], _y[1], _x[2], _y[2], _x[3], _y[3])
EndIf
x = x + size / 2
EndFor
y = y + root3 * size / 2
x = x - (m + 1) * size / 2
EndFor
EndSub

Sub Init
gw = 598
gh = 428
GraphicsWindow.Width = gw
GraphicsWindow.Height = gh
bc = "Black"
fc = "White"
GraphicsWindow.BackgroundColor = bc
GraphicsWindow.PenWidth = 0
size = 5 ' px
n = 8
root3 = Math.SquareRoot(3)
h = 1.5 * (n + 1) * size
w = root3 * (n + 1) * size
EndSub

Sub Rotate
angle = Math.Remainder(angle, 360)
a = Math.GetRadians(angle)
If angle <> 0 Then
For k = 1 To 3
xx = _x[k] - ox
yy = _y[k] - oy
_x[k] = ox + Math.Cos(a) * xx - Math.Sin(a) * yy
_y[k] = oy + Math.Sin(a) * xx + Math.Cos(a) * yy
EndFor
EndIf
EndSub

Sub SnowFlake
snow = ""
For i = 1 To n * n / 3
_i = Math.GetRandomNumber(n)
m = (_i - 1) * 2 + 1
_j = Math.GetRandomNumber((m - 1) / 2 + 1)
snow[_i][_j] = "True"
snow[_i][m - _j + 1] = "True"
EndFor
EndSub