-
Notifications
You must be signed in to change notification settings - Fork 4
/
3D_Sprigograph.bas
288 lines (238 loc) · 7.6 KB
/
3D_Sprigograph.bas
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
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
'Coded By Ashish on 7 March, 2018
_TITLE "3D Spirograph"
SCREEN _NEWIMAGE(800, 600, 32)
TYPE vec3
x AS SINGLE
y AS SINGLE
z AS SINGLE
END TYPE
TYPE sphere
pos AS vec3
r AS SINGLE
theta as double
phi as double
angStp AS DOUBLE
END TYPE
DECLARE LIBRARY
SUB gluLookAt (BYVAL eyeX#, BYVAL eyeY#, BYVAL eyeZ#, BYVAL centerX#, BYVAL centerY#, BYVAL centerZ#, BYVAL upX#, BYVAL upY#, BYVAL upZ#)
SUB glutWireSphere (BYVAL radius AS DOUBLE, BYVAL slices AS LONG, BYVAL stack AS LONG)
END DECLARE
DIM SHARED __sphere(6) AS sphere, glAllow AS _BYTE
DIM SHARED tracer(12000) AS vec3, f
init:
ERASE tracer
v = 0
f = 0
__sphere(0).pos.x = 0
__sphere(0).pos.y = 0
__sphere(0).pos.z = 0
__sphere(0).r = 1
__sphere(0).angStp = p5random(.001, .1)
__sphere(0).phi = p5random(0,_pi(2))
__sphere(0).theta = p5random(0,_pi)
FOR i = 1 TO UBOUND(__sphere)
__sphere(i).r = __sphere(i - 1).r / 2
__sphere(i).angStp = p5random(-.1, .1)
__sphere(i).theta = p5random(0,_pi)
__sphere(i).phi = p5random(0,_pi(2))
NEXT
_GLRENDER _BEHIND
glAllow = -1
DO
k& = _KEYHIT
IF k& = ASC(" ") THEN GOTO init
FOR i = 0 TO UBOUND(__sphere)
__sphere(i).theta = __sphere(i).theta + __sphere(i).angStp/2
__sphere(i).phi = __sphere(i).phi + __sphere(i).angStp
NEXT
f = f + 1
IF f > 4 THEN
v = v + 1
tracer(v) = __sphere(UBOUND(__sphere)).pos
END IF
_LIMIT 60
_DISPLAY
LOOP
SUB _GL ()
STATIC clock!, glInit AS _BYTE, aspect#
IF NOT glAllow THEN EXIT SUB
IF NOT glInit THEN
glInit = -1
_glViewport 0, 0, _WIDTH, _HEIGHT
aspect# = _WIDTH / _HEIGHT
END IF
_glEnable _GL_DEPTH_TEST
'_glEnable _GL_BLEND
_glEnable _GL_LIGHTING
_glEnable _GL_LIGHT0
_glShadeModel _GL_SMOOTH
_glMatrixMode _GL_PROJECTION
_glLoadIdentity
_gluPerspective 45.0, aspect#, 1.0, 100.0
_glMatrixMode _GL_MODELVIEW
_glLoadIdentity
gluLookAt 0, 0, -8, 0, 0, 0, 0, -1, 0
_glTranslatef 0, 0, 0
_glRotatef clock! * 90, 0, 1, 0
_glColor4f 1, 1, 1, .3
_glLineWidth 1.0
glutWireSphere __sphere(0).r, UBOUND(__sphere) * 20, UBOUND(__sphere) * 20
FOR i = 1 TO UBOUND(__sphere)
__sphere(i).pos.x = SIN(__sphere(i - 1).theta) * cos(__sphere(i - 1).phi)*(__sphere(i - 1).r + __sphere(i).r) + (__sphere(i - 1).pos.x)
__sphere(i).pos.y = COS(__sphere(i - 1).theta) * sin(__sphere(i-1).phi)*(__sphere(i - 1).r + __sphere(i).r) + (__sphere(i - 1).pos.y)
__sphere(i).pos.z = cos(__sphere(i - 1).theta) * (__sphere(i - 1).r + __sphere(i).r) + (__sphere(i - 1).pos.z)
_glPushMatrix
_glTranslatef __sphere(i).pos.x, __sphere(i).pos.y, __sphere(i).pos.z
glutWireSphere __sphere(i).r, (UBOUND(__sphere) + 1 - i) * 20, (UBOUND(__sphere) + 1 - i) * 20
_glPopMatrix
NEXT
IF f > 6 THEN
_glDisable _GL_LIGHTING
_glDisable _GL_LIGHT0
_glTranslatef 0, 0, 0
_glLineWidth 2.0
_glPushMatrix
_glColor3f 1, 0, 0
FOR i = 1 TO f - 2
_glBegin _GL_LINES
_glColor3f map(tracer(i).x * tracer(i).y, -9, 9, .4, .1), map(tracer(i).x, -3, 3, .2, 1), map(tracer(i).y, -3, 3, 1, .2)
_glVertex3f tracer(i).x, tracer(i).y, tracer(i).z
_glVertex3f tracer(i + 1).x, tracer(i + 1).y, tracer(i + 1).z
_glEnd
NEXT
_glPopMatrix
END IF
clock! = clock! + .01
_glFlush
END SUB
'taken from p5js.bas
'https://bit.ly/p5jsbas
FUNCTION p5random! (mn!, mx!)
IF mn! > mx! THEN
SWAP mn!, mx!
END IF
p5random! = RND * (mx! - mn!) + mn!
END FUNCTION
FUNCTION map! (value!, minRange!, maxRange!, newMinRange!, newMaxRange!)
map! = ((value! - minRange!) / (maxRange! - minRange!)) * (newMaxRange! - newMinRange!) + newMinRange!
END FUNCTION
=======
'Coded By Ashish on 7 March, 2018
_TITLE "3D Spirograph"
SCREEN _NEWIMAGE(800, 600, 32)
TYPE vec3
x AS SINGLE
y AS SINGLE
z AS SINGLE
END TYPE
TYPE sphere
pos AS vec3
r AS SINGLE
theta as double
phi as double
angStp AS DOUBLE
END TYPE
DECLARE LIBRARY
SUB gluLookAt (BYVAL eyeX#, BYVAL eyeY#, BYVAL eyeZ#, BYVAL centerX#, BYVAL centerY#, BYVAL centerZ#, BYVAL upX#, BYVAL upY#, BYVAL upZ#)
SUB glutWireSphere (BYVAL radius AS DOUBLE, BYVAL slices AS LONG, BYVAL stack AS LONG)
END DECLARE
DIM SHARED __sphere(6) AS sphere, glAllow AS _BYTE
DIM SHARED tracer(12000) AS vec3, f
init:
ERASE tracer
v = 0
f = 0
__sphere(0).pos.x = 0
__sphere(0).pos.y = 0
__sphere(0).pos.z = 0
__sphere(0).r = 1
__sphere(0).angStp = p5random(.001, .1)
__sphere(0).phi = p5random(0,_pi(2))
__sphere(0).theta = p5random(0,_pi)
FOR i = 1 TO UBOUND(__sphere)
__sphere(i).r = __sphere(i - 1).r / 2
__sphere(i).angStp = p5random(-.1, .1)
__sphere(i).theta = p5random(0,_pi)
__sphere(i).phi = p5random(0,_pi(2))
NEXT
_GLRENDER _BEHIND
glAllow = -1
DO
k& = _KEYHIT
IF k& = ASC(" ") THEN GOTO init
FOR i = 0 TO UBOUND(__sphere)
__sphere(i).theta = __sphere(i).theta + __sphere(i).angStp/2
__sphere(i).phi = __sphere(i).phi + __sphere(i).angStp
NEXT
f = f + 1
IF f > 4 THEN
v = v + 1
tracer(v) = __sphere(UBOUND(__sphere)).pos
END IF
_LIMIT 60
_DISPLAY
LOOP
SUB _GL ()
STATIC clock!, glInit AS _BYTE, aspect#
IF NOT glAllow THEN EXIT SUB
IF NOT glInit THEN
glInit = -1
_glViewport 0, 0, _WIDTH, _HEIGHT
aspect# = _WIDTH / _HEIGHT
END IF
_glEnable _GL_DEPTH_TEST
'_glEnable _GL_BLEND
_glEnable _GL_LIGHTING
_glEnable _GL_LIGHT0
_glShadeModel _GL_SMOOTH
_glMatrixMode _GL_PROJECTION
_glLoadIdentity
_gluPerspective 45.0, aspect#, 1.0, 100.0
_glMatrixMode _GL_MODELVIEW
_glLoadIdentity
gluLookAt 0, 0, -8, 0, 0, 0, 0, -1, 0
_glTranslatef 0, 0, 0
_glRotatef clock! * 90, 0, 1, 0
_glColor4f 1, 1, 1, .3
_glLineWidth 1.0
glutWireSphere __sphere(0).r, UBOUND(__sphere) * 20, UBOUND(__sphere) * 20
FOR i = 1 TO UBOUND(__sphere)
__sphere(i).pos.x = SIN(__sphere(i - 1).theta) * cos(__sphere(i - 1).phi)*(__sphere(i - 1).r + __sphere(i).r) + (__sphere(i - 1).pos.x)
__sphere(i).pos.y = COS(__sphere(i - 1).theta) * sin(__sphere(i-1).phi)*(__sphere(i - 1).r + __sphere(i).r) + (__sphere(i - 1).pos.y)
__sphere(i).pos.z = cos(__sphere(i - 1).theta) * (__sphere(i - 1).r + __sphere(i).r) + (__sphere(i - 1).pos.z)
_glPushMatrix
_glTranslatef __sphere(i).pos.x, __sphere(i).pos.y, __sphere(i).pos.z
glutWireSphere __sphere(i).r, (UBOUND(__sphere) + 1 - i) * 20, (UBOUND(__sphere) + 1 - i) * 20
_glPopMatrix
NEXT
IF f > 6 THEN
_glDisable _GL_LIGHTING
_glDisable _GL_LIGHT0
_glTranslatef 0, 0, 0
_glLineWidth 2.0
_glPushMatrix
_glColor3f 1, 0, 0
FOR i = 1 TO f - 2
_glBegin _GL_LINES
_glColor3f map(tracer(i).x * tracer(i).y, -9, 9, .4, .1), map(tracer(i).x, -3, 3, .2, 1), map(tracer(i).y, -3, 3, 1, .2)
_glVertex3f tracer(i).x, tracer(i).y, tracer(i).z
_glVertex3f tracer(i + 1).x, tracer(i + 1).y, tracer(i + 1).z
_glEnd
NEXT
_glPopMatrix
END IF
clock! = clock! + .01
_glFlush
END SUB
'taken from p5js.bas
'https://bit.ly/p5jsbas
FUNCTION p5random! (mn!, mx!)
IF mn! > mx! THEN
SWAP mn!, mx!
END IF
p5random! = RND * (mx! - mn!) + mn!
END FUNCTION
FUNCTION map! (value!, minRange!, maxRange!, newMinRange!, newMaxRange!)
map! = ((value! - minRange!) / (maxRange! - minRange!)) * (newMaxRange! - newMinRange!) + newMinRange!
END FUNCTION
>>>>>>> db1670cd8b28c1e4d58790c7f4d29c0d649f9e56