Microsoft Small Basic

Program Listing: ZZF466-1
' Tulip
' Version 0.3
' Copyright © 2016-2017 Nonki Takahashi. The MIT License.
' Program ID ZZF466-1

GraphicsWindow.Title = "Tulip 0.3"
Init()
size = 70
y = y0 - size
nLine = 0
For j = 1 To 3
delta = 30 * j
x = gw * j / 4
Windmill()
EndFor
size = 70
mag = 1.05
y = y0 - Math.Floor(size / 10) * 2
For i = 1 To 18
size = size * mag
color = fc[Math.Remainder(Math.Floor((i - 1) / 3), 3) + 1]
y = y + Math.Floor(size / 10)
For x = 0 To gw + size Step Math.Floor(size / 5)
Tulip()
EndFor
EndFor
While "True"
For a = 1 To 360
For iLine = 1 To nLine
Shapes.Rotate(line[iLine], a + la[iLine])
EndFor
Program.Delay(10)
EndFor
EndWhile

Sub AddLine
' param angle - [radian]
' param _x1, _y1 - start point
' param _x2, _y2 - end point
' param xo, yo - rotation center
nLine = nLine + 1
line[nLine] = Shapes.AddLine(_x1, _y1, _x2, _y2)
Shapes.Move(line[nLine], xo, yo)
Shapes.Rotate(line[nLine], angle)
la[nLine] = angle
EndSub

Sub Init
gw = 598
gh = 428
GraphicsWindow.Width = gw
GraphicsWindow.Height = gh
GraphicsWindow.BackgroundColor = "SkyBlue"
y0 = Math.Floor(gh / 3)
GraphicsWindow.BrushColor = "Sienna"
GraphicsWindow.FillRectangle(0, y0, gw, gh - y0)
fc = "1=Pink;2=Red;3=White;"
cs["White"] = "1=#DDDDDD;2=#EEEEEE;3=#FFFFFF;"
cs["Yellow"] = "1=#DDDD00;2=#FFFF00;3=#FFFF99;"
cs["Red"] = "1=#DD0000;2=#FF0000;3=#FF3333;"
cs["Pink"] = "1=#DD4444;2=#FF6666;3=#FF9999;"
cs["Brown"] = "1=#CC9966;2=#996633;3=#663300;"
cs["Black"] = "1=#444444;2=#222222;3=#000000;"
EndSub

Sub Windmill
' param x, y - position
' param size - height
' param delta - angle [degree]
' house
height = size
width = size / 3
color = "Brown"
FillCorn()
color = "Black"
height = size / 3
width = size / 8
FillCorn()
width = size / 12
' window
GraphicsWindow.BrushColor = "#66000000"
GraphicsWindow.FillRectangle(x - width / 2, y + width * 5, width, width * 2)
GraphicsWindow.PenColor = "White"
GraphicsWindow.DrawRectangle(x - width / 2, y + width * 5, width, width * 2)
' sails
width = size / 12
GraphicsWindow.BrushColor = "White"
GraphicsWindow.FillEllipse(x - width / 2, y + width * 2, width, width)
xo = x
yo = y + width * 2.5
len = size * 0.7
For angle = delta To delta + 270 Step 90
DrawSail()
EndFor
EndSub

Sub DrawSail
' param xo, yo - center
' param len - length
' param angle
GraphicsWindow.PenColor = "Black"
_a = angle
_x1 = 0
_y1 = 0
_x2 = -len
_y2 = 0
AddLine()
GraphicsWindow.PenColor = "White"
_x1 = -len * 0.2
_y1 = -len * 0.05
_x2 = -len
_y2 = -len * 0.05
AddLine()
_x1 = -len * 0.2
_y1 = -len * 0.2
_x2 = -len
_y2 = -len * 0.2
AddLine()
For i = 1 To 5
_x1 = -len * 0.2 * i
_y1 = -len * 0.05
_x2 = -len * 0.2 * i
_y2 = -len * 0.2
AddLine()
EndFor
EndSub

Sub FillCorn
' param color
GraphicsWindow.BrushColor = cs[color][1]
GraphicsWindow.FillTriangle(x, y, x - width, y + height, x - width / 2, y + height)
GraphicsWindow.BrushColor = cs[color][2]
GraphicsWindow.FillTriangle(x, y, x + width / 2, y + height, x - width / 2, y + height)
GraphicsWindow.BrushColor = cs[color][3]
GraphicsWindow.FillTriangle(x, y, x + width, y + height, x + width / 2, y + height)
EndSub

Sub Tulip
' param x, y
' param size
' param color
width = Math.Floor(size / 15)
height = width * 4
' stem
GraphicsWindow.PenColor = "#00CC00"
yBottom = y + size
GraphicsWindow.DrawLine(x, y + height / 2, x, y + size)
' leaves
GraphicsWindow.BrushColor = "#006600"
GraphicsWindow.FillTriangle(x, yBottom, x - width / 2, yBottom - height, x + width* 1.5, yBottom - height * 3)
GraphicsWindow.BrushColor = "#009900"
GraphicsWindow.FillTriangle(x, yBottom, x + width / 2, yBottom - height, x - width* 1.5, yBottom - height * 3)
' flower
GraphicsWindow.BrushColor = cs[color][1]
GraphicsWindow.FillEllipse(x, y, width, height)
GraphicsWindow.BrushColor = cs[color][2]
GraphicsWindow.FillEllipse(x - width / 2, y, width, height)
GraphicsWindow.FillEllipse(x - width, y + height / 2, width * 2, height / 2)
GraphicsWindow.BrushColor = cs[color][3]
GraphicsWindow.FillEllipse(x - width, y, width, height)
EndSub