-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathspiral.py
154 lines (85 loc) · 2.44 KB
/
spiral.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
143
144
145
146
147
148
149
150
151
152
153
154
"""
Spiral animation
by Sam Neurohack
from /team/laser
Based on Wireframe 3D cube simulation.
Developed by Leonel Machava <leonelmachava@gmail.com>
Wipeout style ship
"""
from globalVars import *
import frame
import sys, math, random
SPEED = 4
SIZE = 40
class Spiral(object):
def __init__(self):
self.width = screen_size[0]
self.height = screen_size[1]
self.centerX = self.width / 2
self.centerY = self.height / 2
self.rot = 1
self.dist = 1
self.fov = 256
self.viewer_distance = 90.2
self.angleX = 0
self.angleY = 0
self.angleZ = 0
self.color = 0x000000
def Move(self,centerX,centerY):
self.centerX = centerX
self.centerY = centerY
def Mode(self,centerX,centerY):
self.centerX = centerX
self.centerY = centerY
def Zoom(self, zoom):
self.viewer_distance = zoom
def Draw(self,f):
self.laspoints = []
self.rot -= 0.5
self.dist += 0.5
#f.LineTo((self.centerX,self.centerY), 0x000000)
self.angleX += 0.1
self.angleY += 0.1
self.angleZ += 0.1
for angle in range(0,800,5):
rad = angle * math.pi / 180
''' 2D Form spiral
r = self.rot + (self.dist * rad)
x = self.centerX + (r * math.cos(rad))
y = self.centerY + (r * math.sin(rad))
'''
''' 3D Form Helix '''
x = 10 * math.cos(6*rad)
y = 10 * math.sin(6*rad)
z = 10 * rad
# 3D rotation along self.angleX, self.angleX, self.angleX
rad = self.angleX * math.pi / 180
cosa = math.cos(rad)
sina = math.sin(rad)
y2 = y
y = y2 * cosa - z * sina
z = y2 * sina + z * cosa
rad = self.angleY * math.pi / 180
cosa = math.cos(rad)
sina = math.sin(rad)
z2 = z
z = z2 * cosa - x * sina
x = z2 * sina + x * cosa
rad = self.angleZ * math.pi / 180
cosa = math.cos(rad)
sina = math.sin(rad)
x2 = x
x = x2 * cosa - y * sina
y = x2 * sina + y * cosa
# 3D to 2D projection
factor = self.fov / (self.viewer_distance + z)
x = x * factor + self.centerX
y = - y * factor + self.centerY
# Color cycle
self.color += 420
if self.color > 0xFFFFFF:
self.color = 0x000000
f.LineTo((x,y), self.color)
#print self.laspoints
#f.PolyLineOneColor(self.laspoints, 0xFFFF00,True)
#f.Lineto(())