-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathdraw.py
142 lines (120 loc) · 9.32 KB
/
draw.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
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
import pygame
import math
import json
import random
window = pygame.display.set_mode((1000,700))
clock = pygame.time.Clock()
exit_window = False
width = window.get_width()
height = window.get_height()
# freq = [1,1.1,2,1,2,1]
# freq = [1,0,-1,2,-2]
# inital = [0,0,0,0,0]
# radius = [
# -12.64 + 20.90j,
# 10.72+16.52j,
# -135.66 - 45.57j,
# -44.85 - 23.71j,
# 66.75 - 53.07j]
freq = []
radius = []
inital = []
dt = 1/300
lines = []
append = True
count = 0
colors = []
data = {"x":[315,315,314,314,313,313,313,313,313,313,312,313,312,312,312,313,312,312,312,312,312,311,311,311,311,311,311,311,311,311,311,311,311,311,311,311,311,311,311,312,313,313,314,314,315,315,316,317,318,319,320,324,327,332,342,344,347,348,355,358,360,362,365,366,367,369,370,371,372,373,374,374,375,375,375,375,375,376,376,376,377,377,377,377,377,377,377,376,376,376,375,374,374,373,373,373,373,373,372,372,372,372,373,372,372,372,372,372,372,372,372,372,372,372,373,373,373,373,373,375,375,375,375,375,375,375,375,375,375,375,375,375,375,375,375,375,374,374,374,374,374,374,374,374,374,374,374,374,374,374,374,374,374,374,374,374,374,375,375,375,376,376,376,377,378,378,378,378,378,383,384,385,387,394,398,401,407,410,412,417,419,421,422,423,423,424,424,425,425,425,425,425,425,425,425,425,425,425,425,425,425,425,425,425,425,425,425,425,425,425,425,425,424,424,424,424,424,424,424,424,424,424,424,424,424,424,424,424,424,424,424,423,423,423,423,423,423,423,423,423,423,423,424,424,424,424,424,424,424,424,424,424,423,423,423,422,422,422,422,422,422,422,421,421,421,421,420,421,421,421,421,421,421,420,420,420,420,420,420,420,421,421,421,421,421,421,422,423,423,423,423,423,423,423,424,424,424,424,426,427,428,428,428,429,432,432,433,434,435,435,435,436,446,450,454,457,461,467,468,470,473,473,474,475,476,477,478,479,479,481,481,482,483,483,483,482,481,481,481,481,481,481,481,480,480,479,479,479,479,478,478,477,477,476,475,475,475,474,474,474,473,473,472,472,470,470,469,468,468,468,466,466,466,466,464,463,462,462,460,460,460,459,458,458,457,457,457,457,457,465,469,470,471,472,473,473,474,474,474,474,474,474,474,474,474,475,475,475,475,475,475,475,475,476,476,477,478,480,481,482,483,483,484,485,488,489,489,489,489,493,495,496,497,501,504,506,509,512,515,515,515,516,518,518,520,520,522,522,524,524,524,524,524,524,524,524,523,523,523,520,519,517,515,515,514,513,512,510,508,505,505,504,503,501,501,500,500,499,498,498,498,497,497,496,495,495,495,495,495,496,498,499,500,503,508,509,512,513,514,515,518,519,520,520,520,521,522,522,523,524,524,524,525,526,526,527,527,528,530,531,531,531,533,534,535,536,536,538,540,541,541,541,541,543,544,545,546,547,547,548,548,552,554,556,561,562,566,567,570,572,574,578,579,580,581,582,583,584,585,585,585,585,585,584,584,582,582,581,580,576,575,574,573,572,570,569,567,565,563,562,561,560,557,556,556,556,556,553,553,552,552,552,552,552,551,549,549,548,548,547,547,547,547,545,544,544,544,544,542,541,541,540,540,540,540,539,539,538,536,536,535,535,534,534,533,532,529,528,526,523,522,521,519,516,512,509,507,503,502,500,497,495,494,492,490,489,489,487,486,485,485,483,483,482,481,480,478,477,473,469,465,461,452,449,447,440,440,440,439,439,436,434,433,432,431,430,429,429,429,429,429,428,427,425,424,424,421,419,417,413,411,409,408,405,398,395,390,389,387,385,381,380,378,377,376,374,373,372,371,370,370,369,368,368,367,367,366,366,365,364,363,363,363,363,363,363,362,362,361,360,357,356,354,353,352,350,349,347,345,343,341,338,335,334,333,331,330,330,329,328,328,327,327,326,325,325,324,323,322,322,321,321,320,319,319,319,318,318,318,318,318,317,317,317,317,317,317,317,317,317,317,317,317,317,316,316,316,316,316,316,316,316],"y":[390,388,383,380,377,376,374,374,373,365,361,358,353,351,350,348,345,344,342,341,340,339,338,335,334,332,331,329,327,322,317,311,305,299,296,295,290,290,288,286,281,279,275,273,270,268,265,262,260,258,256,252,250,248,244,243,243,243,243,244,244,245,246,246,248,251,253,256,259,265,268,272,276,278,280,283,284,286,288,291,297,301,303,312,319,322,328,330,331,333,335,338,342,345,349,351,353,354,355,355,356,361,363,365,366,366,366,367,367,367,367,363,361,357,353,350,347,347,347,343,342,342,341,341,340,339,339,339,338,337,335,334,334,329,327,326,325,323,320,317,315,310,308,306,306,303,299,297,295,293,292,291,289,287,286,285,283,279,277,274,271,270,268,261,258,257,256,256,256,247,246,244,242,240,239,239,238,238,238,238,238,239,239,239,239,241,242,246,248,251,254,261,266,269,274,277,279,280,282,284,286,290,293,294,296,302,305,309,313,320,324,327,332,333,336,337,341,342,344,348,351,352,353,353,353,353,352,352,352,351,350,349,348,348,347,346,346,346,341,339,337,333,331,329,327,323,317,315,312,309,308,306,304,302,300,299,297,297,296,296,296,292,291,291,290,289,287,285,284,281,280,278,276,270,264,259,257,253,250,247,237,235,232,230,223,217,207,200,193,191,189,186,183,178,175,169,166,163,151,147,142,140,139,137,128,127,125,120,117,117,117,116,110,108,108,108,108,109,110,112,116,118,119,121,123,124,126,127,129,133,135,142,146,150,156,167,172,175,178,182,184,186,191,193,199,203,209,215,219,222,229,231,233,234,240,243,245,249,255,257,261,265,273,275,281,286,288,291,293,296,302,305,309,314,327,330,332,332,338,339,340,341,342,343,343,344,344,344,343,334,330,325,321,315,311,309,306,301,299,298,295,294,293,291,289,285,284,282,282,282,281,280,279,279,275,272,269,263,260,257,254,254,252,250,247,245,245,245,244,243,242,242,242,242,243,243,243,244,245,245,245,246,247,248,250,252,258,260,266,270,271,275,278,280,282,286,287,288,289,292,294,298,299,300,301,302,306,308,312,320,323,327,329,335,337,340,341,342,344,346,346,347,349,353,354,355,355,355,354,348,346,344,341,338,333,331,327,325,323,320,313,309,307,305,305,303,302,301,300,297,296,296,294,293,293,292,292,291,288,288,287,287,285,284,283,282,282,280,279,278,278,277,277,277,277,276,276,276,276,276,276,277,277,277,278,278,279,280,281,282,282,285,286,288,289,290,292,293,295,298,299,302,303,308,310,318,322,325,328,334,337,339,340,341,343,345,347,350,353,355,356,357,367,369,370,371,372,382,385,388,389,391,392,393,395,400,402,404,406,407,411,414,416,425,434,435,437,438,444,447,449,450,450,450,450,450,451,453,454,457,459,459,460,460,461,463,467,469,470,475,475,477,478,481,482,483,484,486,487,488,490,492,492,493,495,496,496,498,499,499,499,500,501,501,503,503,504,505,507,507,508,509,510,511,511,514,514,514,514,514,514,514,514,515,515,516,516,516,516,516,515,515,514,513,512,512,510,509,507,505,504,503,503,502,499,499,497,496,495,494,490,488,487,485,482,479,477,471,468,467,465,462,460,459,456,454,452,451,449,445,444,444,444,444,443,443,441,440,439,438,432,431,429,427,424,422,421,418,416,415,413,411,409,409,408,406,406,406,405,404,404,404,403,403,402,402,401,401,400,400,400,400,398,397,396,396,396,396,396,395,395,395,395,394,394,394,394,394,393,393,393,393,392,392,392,391,391,391,391,391,391,390]}
array = [data["x"][i] + data["y"][i]*1j for i in range(len(data["x"]))]
# array = []
FILENAME = 'coordinator(7).json'
# FILENAME = 'data.json'
with open(FILENAME) as f:
data = json.load(f)
f.close()
contor = [
-100,-100,
100,-100,
100, 100,
-100, 100,
-100,-100]
contor = [2*i for i in contor]
array = [i - 300 + 1j*j - 340j for i,j in data]
const = sum(array)/len(array)
#array = [i - const for i in array]
#print(array)
# for i in range(4):
# start_x , start_y = contor[2*i:2*i+2]
# end_x,end_y = contor[2*i+2 : 2*i+4]
# steps = 100
# dx = (end_x-start_x)/steps
# dy = (end_y-start_y)/steps
# print(dx,dy)
# for i in range(steps):
# final = (start_x+dx*i) + (start_y + dy*i)*1j
# array.append(final)
# print(array)
N = len(array)
print(N)
for i in range(-500,500):
sum = complex(0)
for k in range(N):
phi = -2*math.pi*i*k/N
comp = math.cos(phi) - 1j*math.sin(phi)
sum += comp*array[k]
sum /= N
mag = abs(sum)
phase = math.atan2(sum.imag,sum.real)
index = 0
mini = None
while(index<len(radius)):
if mag > radius[index]:
mini = index
break
index += 1
if mini == None:
radius.append(mag)
inital.append(phase)
freq.append(i)
else:
radius.insert(mini,mag)
inital.insert(mini,phase)
freq.insert(mini,i)
colors.append((100,100,100))
# print(colors)
# print(inital)
#radius = [100,100]
#inital = [0,0]
#freq = [1,(math.sqrt(5)+1)/2]
#print(freq)
while not exit_window:
for event in pygame.event.get():
if event.type == pygame.QUIT:
exit_window = True
window.fill((0,0,0,255))
i_x , i_y = window.get_width()//2,window.get_height()//2
# i_x , i_y = 0,0
for i in range(len(freq)):
pygame.draw.circle(window,colors[i],(i_x,i_y),abs(radius[i]),1)
comp = radius[i]*math.e**(inital[i]*1j)
new_x,new_y = comp.real + i_x,comp.imag + i_y
pygame.draw.line(window,(255,255,255,255),(i_x,i_y),(new_x,new_y))
inital[i] += 2*math.pi*freq[i]*dt
i_x,i_y = new_x,new_y
if append:
lines.append((i_x,i_y))
if len(lines) > 2:
pygame.draw.lines(window,(40,163,255),False,lines)
if len(lines) > count+1 and append:
if int(lines[count][0]) == int(i_x) and int(lines[count][1]) == int(i_y):
count += 1
else :
count = 0
if count>2 and append:
append = False
print("Stopped")
if len(lines) > 100000:
lines.pop(0)
# print(lines)
pygame.display.update()
clock.tick(60)