-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathSpiral.py
More file actions
174 lines (116 loc) · 6.15 KB
/
Spiral.py
File metadata and controls
174 lines (116 loc) · 6.15 KB
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
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
from Util import Util
import pygame
LINE_WIDTH = 5
NUM_OF_STEPS = 5
NUM_OF_RENDERED_LINES = 5
SPIRAL_STEP_SIZE = 1.4
lineColour = (0, 0, 0)
class Spiral:
def __init__(self, head, tail):
self._head = head
self._tail = tail
self.lines = []
@property
def head(self):
return self._head
@property
def tail(self):
return self._tail
@head.setter
def head(self, newHead):
self._head = newHead
@tail.setter
def tail(self, newTail):
self._tail = newTail
def GenerateNewLinesLeftDown( self, prevLineHead, prevLineTail, counter):
# Identification string
positionOfSpiral = "Left-Down Hand Side"
# To get the radius of the L_1 unit sphere respective to previous head
lenOfPhantomLine = (prevLineTail[1] - prevLineHead[1])
Hypotenuse = Util.ModifySpiralStep(lenOfPhantomLine, SPIRAL_STEP_SIZE)
radius = int(Hypotenuse)
#print(f'Left-Down Hand Side: Length of the radius in Manhattan Metric unit sphere {radius} Loop No {counter}. \n')
# Counter is used as a switch to change the direction of the each line generated
if ( counter % 2 == 0):
newLineHead = Util.ComputeNewLineThirdQuadrant(radius, prevLineHead)
else:
newLineHead = Util.ComputeNewLineFourthQuadrant(-radius, prevLineHead)
#print(f'Left-Down Side: New point after function compute newline: {newLineHead} Loop No {counter}. \n')
return newLineHead
def GenerateNewLinesRightDown( self, prevLineHead, prevLineTail, counter):
# Identification string
positionOfSpiral = "Right-Down Hand Side"
# To get the radius of the L_1 unit sphere respective to previous head
lenOfPhantomLine = (prevLineTail[1] - prevLineHead[1])
Hypotenuse = Util.ModifySpiralStep(lenOfPhantomLine, SPIRAL_STEP_SIZE)
radius = int(Hypotenuse)
#print(f'Right-Down Hand Side: Length of the radius in Manhattan Metric unit sphere {radius} Loop No {counter}. \n')
# Counter is used as a switch to change the direction of the each line generated
if ( counter % 2 == 0):
newLineHead = Util.ComputeNewLineThirdQuadrant(-radius, prevLineHead)
else:
newLineHead = Util.ComputeNewLineFourthQuadrant(radius, prevLineHead)
#print(f'Right-Down Hand Side: New point after function compute newline: {newLineHead} Loop No {counter}. \n')
return newLineHead
# Left side spiral
def GenerateNewLinesLEFT( self, prevLineHead, prevLineTail, counter):
# Identification string
positionOfSpiral = "Left Hand Side"
# To get the radius of the L_1 unit sphere respective to previous head
lenOfPhantomLine = (prevLineTail[1] - prevLineHead[1])
Hypotenuse = Util.ModifySpiralStep(lenOfPhantomLine, SPIRAL_STEP_SIZE)
radius = int(Hypotenuse)
#print(f'Left Hand Side: Length of the radius in Manhattan Metric unit sphere {radius} Loop No {counter}. \n')
# Counter is used as a switch to change the direction of the each line generated
if ( counter % 2 == 0):
newLineHead = Util.ComputeNewLineSecondQuadrant(radius, prevLineHead)
else:
newLineHead = Util.ComputeNewLineThirdQuadrant(radius, prevLineHead)
#print(f'Left Hand Side: New point after function compute newline: {newLineHead} Loop No {counter}. \n')
return newLineHead
def GenerateNewLinesRIGHT(self, prevHead, prevTail, counter):
#print(f"prevTail: {prevTail}, type: {type(prevTail)}")
#print(f"prevHead: {prevHead}, type: {type(prevHead)}")
# Identification string
positionOfSpiral = "Right Hand Side"
# To get the radius of the L_1 unit sphere respective to previous head
lenOfPhantomLine = (prevTail[1] - prevHead[1])
Hypotenuse = Util.ModifySpiralStep(lenOfPhantomLine, SPIRAL_STEP_SIZE)
radius = int(Hypotenuse)
#print(f'Right Hand Side: Value of y {prevTail[1]} Loop No {counter}. \n')
# Counter is used as a switch to change the direction of the each line generated
if ( counter % 2 == 0):
newLineHead = Util.ComputeNewLineFourthQuadrant(radius, prevHead)
else:
newLineHead = Util.ComputeNewLineFirstQuadrant(radius, prevHead)
#print(f'Right Hand Side: New point after function compute newline: {newLineHead} Loop No {counter}. \n')
return newLineHead
def GenerateSpiralPattern(self, spiralPattern):
if spiralPattern == 0:
for i in range(NUM_OF_STEPS):
newLineHead = self.GenerateNewLinesRIGHT(self._head , self._tail, i)
self.lines.append([newLineHead, self._head])
self._tail = self._head
self._head = newLineHead
elif spiralPattern == 1:
for i in range(NUM_OF_STEPS):
newLineHead = self.GenerateNewLinesLEFT(self._head , self._tail, i)
self.lines.append([newLineHead, self._head])
self._tail = self._head
self._head = newLineHead
elif spiralPattern == 2:
for i in range(NUM_OF_STEPS):
newLineHead = self.GenerateNewLinesRightDown(self._head , self._tail, i)
self.lines.append([newLineHead, self._head])
self._tail = self._head
self._head = newLineHead
elif spiralPattern == 3:
for i in range(NUM_OF_STEPS):
newLineHead = self.GenerateNewLinesLeftDown(self._head , self._tail, i)
self.lines.append([newLineHead, self._head])
self._tail = self._head
self._head = newLineHead
#For debugging
def drawLines(self, window):
for line in range(NUM_OF_RENDERED_LINES):
pygame.draw.line(window, lineColour,self.lines[line][0], self.lines[line][1] , LINE_WIDTH)