-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathmultiroses.py
45 lines (39 loc) · 1.06 KB
/
multiroses.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
from pythroses import nest_squares
def gcd(a, b):
if b > a:
a, b = b, a
if b == 0:
return 0
if b == 1:
return 1
q = int(a / b)
r = a - b * q
while r != 0:
a, b = b, r
q = int(a / b)
r = a - b * q
return b
def generate_pairs(start, finish):
if finish <= start:
return []
pairs = []
n = start
while n < finish:
m = n + 1
while m <= finish:
if gcd(m, n) == 1 and (m + n) % 2 == 1:
a = m * m - n * n
b = 2 * m * n
if b < a:
a, b = b, a
pairs.append([a, b])
m += 1
n += 1
return pairs
def make_pyth_roses(leg_pairs, num, scale, color, prec):
for pair in leg_pairs:
nest_squares(pair[0], pair[1], num, scale, color, prec)
def make_roses(start, finish, num, scale, color):
make_pyth_roses(generate_pairs(start, finish), num, scale, color, 4)
# example use
make_roses(1, 5, 16, 5, "purple")