48 lines
1.2 KiB
Python
Executable File
48 lines
1.2 KiB
Python
Executable File
#!/usr/bin/env python
|
|
|
|
import math
|
|
|
|
def fibomod(n):
|
|
values = [0, 1]
|
|
while not ( values[-2] == 1 and values[-1] == 0):
|
|
x = (values[-1] + values[-2]) % n
|
|
values.append(x)
|
|
return values[:-1]
|
|
|
|
def fibopoint(cx, cy, r, p, n):
|
|
theta = 2 * math.pi * p / n
|
|
return ( cx + r * math.sin(theta), cy - r * math.cos(theta) )
|
|
|
|
def fibopoly(cx, cy, r, n):
|
|
return [ fibopoint(cx, cy, r, p, n) for p in fibomod(n) ]
|
|
|
|
def svgpoly(points):
|
|
ps = " ".join([ f"{x},{y}" for (x, y) in points ])
|
|
return f'<polygon points="{ps}" stroke="black" opacity="50%" fill="none" />'
|
|
|
|
def svgline(p1, p2):
|
|
return f'<line x1="{p1[0]}" y1="{p1[1]}" x2="{p2[0]}" y2="{p2[1]}" stroke="black" opacity="20%"/>\n'
|
|
|
|
def svglines(points):
|
|
lines = ""
|
|
for i in range(1, len(points)):
|
|
p2 = points[i]
|
|
p1 = points[i - 1]
|
|
lines += svgline(p1, p2)
|
|
lines += svgline(points[-1], points[0])
|
|
return lines
|
|
|
|
print('<svg width="800" height="1200" xmlns="http://www.w3.org/2000/svg">')
|
|
|
|
n = 2
|
|
for j in range(11):
|
|
for i in range(7):
|
|
cx = 50 + i * 100
|
|
cy = 50 + j * 100
|
|
r = 40
|
|
print(svglines(fibopoly(cx, cy, r, n)))
|
|
n += 1
|
|
|
|
print('</svg>')
|
|
|