Microsoft Small Basic

Program Listing: QLG339-0
' Draw Web
' Version 0.2
' Copyright © 2019 Nonki Takahashi. The MIT License.
' Last update 2019-10-05
' Program ID QLG339-0

GraphicsWindow.Title = "Web 0.2"
GraphicsWindow.BackgroundColor = "DimGray"
pc = "LightGray"
gw = GraphicsWindow.Width
gh = GraphicsWindow.Height
debug = "False"
If debug Then
GraphicsWindow.Width = gw + 200
GraphicsWindow.Height = gh + 200
EndIf
GraphicsWindow.BrushColor = "Black"
GraphicsWindow.FillRectangle(0, 0, gw, gh)
gd = Math.SquareRoot(gw * gw + gh * gh) * 0.8
x[0] = gw / 2
y[0] = gh / 2
size = 6
gap = 16
GraphicsWindow.PenWidth = 0
GraphicsWindow.BrushColor = "#6633FFFF"
shp[0] = Shapes.AddEllipse(size, size)
Shapes.Move(shp[0], x[0] - size / 2, y[0] - size / 2)
a = 22.5
For i = 1 To 8
' end point
_a = Math.GetRadians(a)
x[i] = x[0] + Math.Round(gd * Math.Cos(_a))
y[i] = y[0] + Math.Round(gd * Math.Sin(_a))
a = a + 45
EndFor
a = 22.5
r = gap
sx = x[0]
While r < gd
' spiral point
_a = Math.GetRadians(a)
n = i
x[i] = x[0] + Math.Round(r * Math.Cos(_a))
e2 = Math.Remainder(i - 1, 8) + 1
ex = x[e2]
s = 0.4 / Math.Abs(sx - ex)
dy[i] = s * Math.Abs((x[i] - sx) * (x[i] - ex))
y[i] = y[0] + Math.Round(r * Math.Sin(_a))
shp[i] = Shapes.AddEllipse(size, size)
Shapes.Move(shp[i], x[i] - size / 2, y[i] - size / 2 + dy[i])
i = i + 1
a = a + 45
r = r * 1.07
EndWhile
GraphicsWindow.PenWidth = 2
GraphicsWindow.PenColor = pc
spiral = "False"
For k = 1 To 8
' connect center to end
i1 = 0
sx = x[i1]
e2 = k
ex = x[e2]
ey = y[e2]
s = 0.4 / Math.Abs(sx - ex)
_i = 0
For j = k + 8 To n Step 8
i2 = j
AddDots()
i1 = i2
_i = j
EndFor
i2 = e2
AddDots()
EndFor
_i = 9
spiral = "True"
For j = 9 To n
' connect spiral
i2 = j
If 9 < j Then
sx = x[i1]
ex = x[i2]
AddDots()
_i = j
EndIf
i1 = i2
EndFor

Sub AddDots
' param i1, i2 - start and end point index
' param gap - minimum gap between points
_x = x[i2] - x[i1]
_y = y[i2] - y[i1]
len = Math.SquareRoot(_x * _x + _y * _y)
m = Math.Floor(len / gap)
If 2 <= m Then
r = 1 / m
For l = 1 To m - 1
i = i + 1
x[i] = x[i1] * (1 - r) + x[i2] * r
dy[i] = s * Math.Abs((x[i] - sx) * (x[i] - ex))
If spiral Then
y[i] = (y[i1] + dy[i1]) * (1 - r) + (y[i2] + dy[i2]) * r
Else
y[i] = y[i1] * (1 - r) + y[i2] * r
EndIf
GraphicsWindow.PenWidth = 0
shp[i] = Shapes.AddEllipse(size, size)
Shapes.Move(shp[i], x[i] - size / 2, y[i] - size / 2 + dy[i])
If _i <> "" Then
GraphicsWindow.PenWidth = 2
GraphicsWindow.DrawLine(x[_i], y[_i] + dy[_i], x[i], y[i] + dy[i])
EndIf
_i = i
r = r + 1 / m
EndFor
EndIf
If spiral Or (_i <> "") Then
GraphicsWindow.PenWidth = 2
GraphicsWindow.DrawLine(x[_i], y[_i] + dy[_i], x[i2], y[i2] + dy[i2])
GraphicsWindow.PenColor = pc
EndIf
EndSub