-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathflow.bas
346 lines (346 loc) · 12.3 KB
/
flow.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
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
100 ' Flow
110 ' Gilbert Francois Duivesteijn
120 '
200 COLOR 15,1,1: CLS
210 ' setup perlin noise
220 NX=2: NY=8
230 OX=0: OY=0
231 NP=20: ' nr of particles
232 ST=5.3: ' step size
233 NC=3: ' nr of colors
234 NS=29: ' nr of steps
238 ' setup noise
239 GOSUB 16000
240 ' setup fast sin/cos
250 GOSUB 18000
260 ' setup particles
270 DIM PA(NP,2)
271 ' setup palette
272 DIM CO(NC)
273 CO(0)=4
274 CO(1)=5
275 CO(2)=7
276 CO(3)=14
280 ' init particles
281 FOR I=0 TO NP
290 GOSUB 1600
310 NEXT I
315 SCREEN 2
316 FC=0
320 ' update
330 FOR I=0 TO NP
331 IF PA(I,0)<1 OR PA(I,0)>254 GOTO 332 ELSE 335
332 GOSUB 1600
335 IF PA(I,1)<1 OR PA(I,1)>191 GOTO 336 ELSE 340
336 GOSUB 1600
340 X=PA(I,0)
350 Y=PA(I,1)
360 GOSUB 16600
370 TH=4*180*Z+180
371 IF TH<0 THEN TH=TH+360
380 PA(I,0)=PA(I,0)+ST*FN FC(TH)
390 PA(I,1)=PA(I,1)+ST*FN FS(TH)
391 CP=POINT(PA(I,0),PA(I,1)): ' prev color
392 CN=CO(INT(FC/NS*(NC))): 'new color
393 IF CN>CP GOTO 400 ELSE 410
400 PSET(PA(I,0),PA(I,1)),CN
410 NEXT I
411 FC=FC+1
412 IF FC>NS GOTO 414 ELSE 420
414 FOR I=0 TO NP
415 GOSUB 1600
416 NEXT I
417 FC=0
420 GOTO 320
1600 '
1610 ' init particle
1620 ' in: PA, I
1630 '
1640 PA(I,0)=INT(RND(1)*255)
1650 PA(I,1)=INT(RND(1)*191)
1660 RETURN
16000 ' libnoise
16010 ' Perlin noise generator
16020 ' Gilbert Francois Duivesteijn
16030 '
16040 ' init: 16000
16050 ' run: 16600
16060 '
16070 ' Init Perlin noise
16080 ' in: NX,NY: nr of cells
16090 ' OX,OY: offset in pxls
16100 ' out: GX,GY: grad in nodes
16110 ' PX,PY: pxls per cell
16120 '
16130 PRINT "[i] Generating random gradient."
16140 T0=TIME
16150 PX=(256-2*OX)/NX
16160 PY=(192-2*OY)/NY
16170 PRINT "[i] px: " + STR$(PX)
16180 PRINT "[i] py: " + STR$(PY)
16190 DIM GX(NX,NY): ' grad dv/dx
16200 DIM GY(NX,NY): ' grad dv/dy
16210 FOR I=0 TO NX
16220 FOR J=0 TO NY
16230 GX(I,J) = 2*RND(TIME)-1
16240 GY(I,J) = 2*RND(TIME)-1
16250 NEXT J
16260 NEXT I
16270 T1=TIME
16280 PRINT " Done, " + STR$((T1-T0)/50) + " sec."
16290 RETURN
16300 '
16310 ' Dot gradient
16320 ' in: x,ix,y,iy,gx,gy
16330 ' out: dg
16340 '
16350 DX=XP-IX
16360 DY=YP-IY
16370 DG=GX(IX,IY)*DX + GY(IX,IY)*DY
16380 RETURN
16390 '
16400 ' Interpolate
16410 ' in: n0,n1,w
16420 ' out: n2
16430 '
16440 A2=(A1-A0)*W+A0
16450 RETURN
16600 '
16610 ' Perlin noise
16620 ' in: X, Y
16630 ' out: Z
16640 '
16650 XP=(X-OX)/PX
16660 YP=(Y-OY)/PY
16670 IX=INT(XP)
16680 IY=INT(YP)
16690 GOSUB 16300
16700 Z0=DG: DG=0
16710 IX=INT(XP)+1
16720 IY=INT(YP)
16730 GOSUB 16300
16740 Z1=DG: DG=0
16750 ' point(ix0,iy1)
16760 IX=INT(XP)
16770 IY=INT(YP)+1
16780 GOSUB 16300
16790 Z2=DG: DG=0
16800 ' point(ix1,iy1)
16810 IX=INT(XP)+1
16820 IY=INT(YP)+1
16830 GOSUB 16300
16840 Z3=DG: DG=0
16850 ' interpolate
16860 A0=Z0: A1=Z1: W=XP-INT(XP)
16870 GOSUB 16390
16880 Z4=A2: A2=0
16890 A0=Z2: A1=Z3: W=XP-INT(XP)
16900 GOSUB 16390
16910 Z5=A2: A2=0
16920 A0=Z4: A1=Z5: W=YP-INT(YP)
16930 GOSUB 16390
16940 Z=A2: A2=0
16950 RETURN
18000 ' libsin
18010 ' Library for fast goniometric
18020 ' functions.
18030 ' Gilbert Francois Duivesteijn
18040 '
18050 ' init: 18000
18060 ' run: fn fs(x)
18070 ' run: fn fc(x)
18080 PI=ATN(1)*4
18090 DIM TS(360): ' table sin
18100 PRINT "[i] Building lookup table..."
18110 ' Fast sin(x) function
18120 DEF FN FS(X)=TS((X+.5) MOD 360)
18130 ' Fast cos(x) function
18140 DEF FN FC(X)=TS((X+90.5) MOD 360)
18150 ' Create lookup table
18160 ' out: ts, fn fs, fn fc, pi
18170 FOR I=0 TO 359
18180 READ TS(I)
18190 NEXT I
18200 RETURN
18210 END
18220 DATA 0.000000000000000, 0.017452406437284
18230 DATA 0.034899496702501, 0.052335956242944
18240 DATA 0.069756473744125, 0.087155742747658
18250 DATA 0.104528463267653, 0.121869343405147
18260 DATA 0.139173100960065, 0.156434465040231
18270 DATA 0.173648177666930, 0.190808995376545
18280 DATA 0.207911690817759, 0.224951054343865
18290 DATA 0.241921895599668, 0.258819045102521
18300 DATA 0.275637355816999, 0.292371704722737
18310 DATA 0.309016994374947, 0.325568154457157
18320 DATA 0.342020143325669, 0.358367949545300
18330 DATA 0.374606593415912, 0.390731128489274
18340 DATA 0.406736643075800, 0.422618261740699
18350 DATA 0.438371146789077, 0.453990499739547
18360 DATA 0.469471562785891, 0.484809620246337
18370 DATA 0.500000000000000, 0.515038074910054
18380 DATA 0.529919264233205, 0.544639035015027
18390 DATA 0.559192903470747, 0.573576436351046
18400 DATA 0.587785252292473, 0.601815023152048
18410 DATA 0.615661475325658, 0.629320391049837
18420 DATA 0.642787609686539, 0.656059028990507
18430 DATA 0.669130606358858, 0.681998360062498
18440 DATA 0.694658370458997, 0.707106781186547
18450 DATA 0.719339800338651, 0.731353701619170
18460 DATA 0.743144825477394, 0.754709580222772
18470 DATA 0.766044443118978, 0.777145961456971
18480 DATA 0.788010753606722, 0.798635510047293
18490 DATA 0.809016994374947, 0.819152044288992
18500 DATA 0.829037572555042, 0.838670567945424
18510 DATA 0.848048096156426, 0.857167300702112
18520 DATA 0.866025403784439, 0.874619707139396
18530 DATA 0.882947592858927, 0.891006524188368
18540 DATA 0.898794046299167, 0.906307787036650
18550 DATA 0.913545457642601, 0.920504853452440
18560 DATA 0.927183854566787, 0.933580426497202
18570 DATA 0.939692620785908, 0.945518575599317
18580 DATA 0.951056516295154, 0.956304755963035
18590 DATA 0.961261695938319, 0.965925826289068
18600 DATA 0.970295726275996, 0.974370064785235
18610 DATA 0.978147600733806, 0.981627183447664
18620 DATA 0.984807753012208, 0.987688340595138
18630 DATA 0.990268068741570, 0.992546151641322
18640 DATA 0.994521895368273, 0.996194698091746
18650 DATA 0.997564050259824, 0.998629534754574
18660 DATA 0.999390827019096, 0.999847695156391
18670 DATA 1.000000000000000, 0.999847695156391
18680 DATA 0.999390827019096, 0.998629534754574
18690 DATA 0.997564050259824, 0.996194698091746
18700 DATA 0.994521895368273, 0.992546151641322
18710 DATA 0.990268068741570, 0.987688340595138
18720 DATA 0.984807753012208, 0.981627183447664
18730 DATA 0.978147600733806, 0.974370064785235
18740 DATA 0.970295726275996, 0.965925826289068
18750 DATA 0.961261695938319, 0.956304755963036
18760 DATA 0.951056516295154, 0.945518575599317
18770 DATA 0.939692620785908, 0.933580426497202
18780 DATA 0.927183854566787, 0.920504853452440
18790 DATA 0.913545457642601, 0.906307787036650
18800 DATA 0.898794046299167, 0.891006524188368
18810 DATA 0.882947592858927, 0.874619707139396
18820 DATA 0.866025403784439, 0.857167300702112
18830 DATA 0.848048096156426, 0.838670567945424
18840 DATA 0.829037572555042, 0.819152044288992
18850 DATA 0.809016994374947, 0.798635510047293
18860 DATA 0.788010753606722, 0.777145961456971
18870 DATA 0.766044443118978, 0.754709580222772
18880 DATA 0.743144825477394, 0.731353701619171
18890 DATA 0.719339800338651, 0.707106781186548
18900 DATA 0.694658370458997, 0.681998360062498
18910 DATA 0.669130606358858, 0.656059028990507
18920 DATA 0.642787609686539, 0.629320391049837
18930 DATA 0.615661475325658, 0.601815023152048
18940 DATA 0.587785252292473, 0.573576436351046
18950 DATA 0.559192903470747, 0.544639035015027
18960 DATA 0.529919264233205, 0.515038074910054
18970 DATA 0.500000000000000, 0.484809620246337
18980 DATA 0.469471562785891, 0.453990499739547
18990 DATA 0.438371146789077, 0.422618261740699
19000 DATA 0.406736643075800, 0.390731128489274
19010 DATA 0.374606593415912, 0.358367949545300
19020 DATA 0.342020143325669, 0.325568154457157
19030 DATA 0.309016994374948, 0.292371704722737
19040 DATA 0.275637355816999, 0.258819045102521
19050 DATA 0.241921895599668, 0.224951054343865
19060 DATA 0.207911690817759, 0.190808995376545
19070 DATA 0.173648177666930, 0.156434465040231
19080 DATA 0.139173100960065, 0.121869343405148
19090 DATA 0.104528463267654, 0.087155742747658
19100 DATA 0.069756473744126, 0.052335956242944
19110 DATA 0.034899496702501, 0.017452406437283
19120 DATA 0.000000000000000, -0.017452406437284
19130 DATA -0.034899496702501, -0.052335956242944
19140 DATA -0.069756473744125, -0.087155742747658
19150 DATA -0.104528463267653, -0.121869343405147
19160 DATA -0.139173100960066, -0.156434465040231
19170 DATA -0.173648177666930, -0.190808995376545
19180 DATA -0.207911690817760, -0.224951054343865
19190 DATA -0.241921895599668, -0.258819045102521
19200 DATA -0.275637355816999, -0.292371704722737
19210 DATA -0.309016994374947, -0.325568154457157
19220 DATA -0.342020143325669, -0.358367949545300
19230 DATA -0.374606593415912, -0.390731128489274
19240 DATA -0.406736643075800, -0.422618261740699
19250 DATA -0.438371146789077, -0.453990499739547
19260 DATA -0.469471562785891, -0.484809620246337
19270 DATA -0.500000000000000, -0.515038074910054
19280 DATA -0.529919264233205, -0.544639035015027
19290 DATA -0.559192903470747, -0.573576436351046
19300 DATA -0.587785252292473, -0.601815023152048
19310 DATA -0.615661475325658, -0.629320391049838
19320 DATA -0.642787609686539, -0.656059028990507
19330 DATA -0.669130606358858, -0.681998360062498
19340 DATA -0.694658370458997, -0.707106781186547
19350 DATA -0.719339800338651, -0.731353701619170
19360 DATA -0.743144825477394, -0.754709580222772
19370 DATA -0.766044443118978, -0.777145961456971
19380 DATA -0.788010753606722, -0.798635510047293
19390 DATA -0.809016994374947, -0.819152044288992
19400 DATA -0.829037572555042, -0.838670567945424
19410 DATA -0.848048096156426, -0.857167300702112
19420 DATA -0.866025403784438, -0.874619707139396
19430 DATA -0.882947592858927, -0.891006524188368
19440 DATA -0.898794046299167, -0.906307787036650
19450 DATA -0.913545457642601, -0.920504853452440
19460 DATA -0.927183854566787, -0.933580426497202
19470 DATA -0.939692620785908, -0.945518575599317
19480 DATA -0.951056516295154, -0.956304755963035
19490 DATA -0.961261695938319, -0.965925826289068
19500 DATA -0.970295726275996, -0.974370064785235
19510 DATA -0.978147600733806, -0.981627183447664
19520 DATA -0.984807753012208, -0.987688340595138
19530 DATA -0.990268068741570, -0.992546151641322
19540 DATA -0.994521895368273, -0.996194698091746
19550 DATA -0.997564050259824, -0.998629534754574
19560 DATA -0.999390827019096, -0.999847695156391
19570 DATA -1.000000000000000, -0.999847695156391
19580 DATA -0.999390827019096, -0.998629534754574
19590 DATA -0.997564050259824, -0.996194698091746
19600 DATA -0.994521895368273, -0.992546151641322
19610 DATA -0.990268068741570, -0.987688340595138
19620 DATA -0.984807753012208, -0.981627183447664
19630 DATA -0.978147600733806, -0.974370064785235
19640 DATA -0.970295726275997, -0.965925826289068
19650 DATA -0.961261695938319, -0.956304755963035
19660 DATA -0.951056516295154, -0.945518575599317
19670 DATA -0.939692620785908, -0.933580426497202
19680 DATA -0.927183854566787, -0.920504853452440
19690 DATA -0.913545457642601, -0.906307787036650
19700 DATA -0.898794046299167, -0.891006524188368
19710 DATA -0.882947592858927, -0.874619707139396
19720 DATA -0.866025403784439, -0.857167300702112
19730 DATA -0.848048096156426, -0.838670567945424
19740 DATA -0.829037572555042, -0.819152044288992
19750 DATA -0.809016994374948, -0.798635510047293
19760 DATA -0.788010753606722, -0.777145961456971
19770 DATA -0.766044443118978, -0.754709580222772
19780 DATA -0.743144825477395, -0.731353701619170
19790 DATA -0.719339800338651, -0.707106781186548
19800 DATA -0.694658370458998, -0.681998360062498
19810 DATA -0.669130606358858, -0.656059028990507
19820 DATA -0.642787609686540, -0.629320391049838
19830 DATA -0.615661475325658, -0.601815023152048
19840 DATA -0.587785252292473, -0.573576436351046
19850 DATA -0.559192903470747, -0.544639035015027
19860 DATA -0.529919264233205, -0.515038074910054
19870 DATA -0.500000000000000, -0.484809620246337
19880 DATA -0.469471562785891, -0.453990499739547
19890 DATA -0.438371146789078, -0.422618261740699
19900 DATA -0.406736643075800, -0.390731128489274
19910 DATA -0.374606593415912, -0.358367949545301
19920 DATA -0.342020143325669, -0.325568154457157
19930 DATA -0.309016994374948, -0.292371704722737
19940 DATA -0.275637355816999, -0.258819045102521
19950 DATA -0.241921895599668, -0.224951054343865
19960 DATA -0.207911690817760, -0.190808995376545
19970 DATA -0.173648177666930, -0.156434465040231
19980 DATA -0.139173100960066, -0.121869343405147
19990 DATA -0.104528463267653, -0.087155742747658
20000 DATA -0.069756473744126, -0.052335956242944
20010 DATA -0.034899496702501, -0.017452406437284