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
|
#include "draw.h"
#include "draw_3d.h"
#include "3d.h"
#include <math.h>
#include <stdlib.h>
#include <stdint.h>
#include <stdio.h>
#include <string.h>
void linespin (int iterations, int delay)
{
float top_x, top_y, top_z, bot_x, bot_y, bot_z, sin_base;
float center_x, center_y;
center_x = 4;
center_y = 4;
int i, z;
for (i=0;i<iterations;i++)
{
//printf("Sin base %f \n",sin_base);
for (z = 0; z < 8; z++)
{
sin_base = (float)i/50 + (float)z/(10+(7*sin((float)i/200)));
top_x = center_x + sin(sin_base)*5;
top_y = center_x + cos(sin_base)*5;
//top_z = center_x + cos(sin_base/100)*2.5;
bot_x = center_x + sin(sin_base+3.14)*10;
bot_y = center_x + cos(sin_base+3.14)*10;
//bot_z = 7-top_z;
bot_z = z;
top_z = z;
//setvoxel((int) top_x, (int) top_y, 7);
//setvoxel((int) bot_x, (int) bot_y, 0);
//printf("P1: %i %i %i P2: %i %i %i \n", (int) top_x, (int) top_y, 7, (int) bot_x, (int) bot_y, 0);
//line_3d((int) top_x, (int) top_y, (int) top_z, (int) bot_x, (int) bot_y, (int) bot_z);
line_3d((int) top_z, (int) top_x, (int) top_y, (int) bot_z, (int) bot_x, (int) bot_y);
}
delay_ms(120);
fill(0x00);
}
}
void sinelines (int iterations, int delay)
{
int i,x;
float left, right, sine_base, x_dividor,ripple_height;
for (i=0; i<iterations; i++)
{
for (x=0; x<8 ;x++)
{
x_dividor = 2 + sin((float)i/100)+1;
ripple_height = 3 + (sin((float)i/200)+1)*6;
sine_base = (float) i/40 + (float) x/x_dividor;
left = 4 + sin(sine_base)*ripple_height;
right = 4 + cos(sine_base)*ripple_height;
right = 7-left;
//printf("%i %i \n", (int) left, (int) right);
line_3d(0-3, x, (int) left, 7+3, x, (int) right);
//line_3d((int) right, 7, x);
}
delay_ms(delay);
fill(0x00);
}
}
// Display a sine wave running out from the center of the cube.
void ripples (int iterations, int delay)
{
float origin_x, origin_y, distance, height, ripple_interval;
int x,y,i;
fill(0x00);
for (i=0;i<iterations;i++)
{
for (x=0;x<8;x++)
{
for (y=0;y<8;y++)
{
distance = distance2d(3.5,3.5,x,y)/9.899495*8;
//distance = distance2d(3.5,3.5,x,y);
ripple_interval =1.3;
height = 4+sin(distance/ripple_interval+(float) i/50)*4;
setvoxel(x,y,(int) height);
}
}
delay_ms(delay);
fill(0x00);
}
}
void sidewaves (int iterations, int delay)
{
float origin_x, origin_y, distance, height, ripple_interval;
int x,y,i;
fill(0x00);
for (i=0;i<iterations;i++)
{
origin_x = 3.5+sin((float)i/500)*4;
origin_y = 3.5+cos((float)i/500)*4;
for (x=0;x<8;x++)
{
for (y=0;y<8;y++)
{
distance = distance2d(origin_x,origin_y,x,y)/9.899495*8;
ripple_interval =2;
height = 4+sin(distance/ripple_interval+(float) i/50)*3.6;
setvoxel(x,y,(int) height);
setvoxel(x,y,(int) height);
}
}
delay_ms(delay);
fill(0x00);
}
}
void spheremove (int iterations, int delay)
{
fill(0x00);
float origin_x, origin_y, origin_z, distance, diameter;
origin_x = 0;
origin_y = 3.5;
origin_z = 3.5;
diameter = 3;
int x, y, z, i;
for (i=0; i<iterations; i++)
{
origin_x = 3.5+sin((float)i/50)*2.5;
origin_y = 3.5+cos((float)i/50)*2.5;
origin_z = 3.5+cos((float)i/30)*2;
diameter = 2+sin((float)i/150);
for (x=0; x<8; x++)
{
for (y=0; y<8; y++)
{
for (z=0; z<8; z++)
{
distance = distance3d(x,y,z, origin_x, origin_y, origin_z);
//printf("Distance: %f \n", distance);
if (distance>diameter && distance<diameter+1)
{
setvoxel(x,y,z);
}
}
}
}
delay_ms(delay);
fill(0x00);
}
}
void fireworks (int iterations, int n, int delay)
{
fill(0x00);
int i,f,e;
float origin_x = 3;
float origin_y = 3;
float origin_z = 3;
int rand_y, rand_x, rand_z;
float slowrate, gravity;
// Particles and their position, x,y,z and their movement, dx, dy, dz
float particles[n][6];
for (i=0; i<iterations; i++)
{
origin_x = rand()%4;
origin_y = rand()%4;
origin_z = rand()%2;
origin_z +=5;
origin_x +=2;
origin_y +=2;
// shoot a particle up in the air
for (e=0;e<origin_z;e++)
{
setvoxel(origin_x,origin_y,e);
delay_ms(600+500*e);
fill(0x00);
}
// Fill particle array
for (f=0; f<n; f++)
{
// Position
particles[f][0] = origin_x;
particles[f][1] = origin_y;
particles[f][2] = origin_z;
rand_x = rand()%200;
rand_y = rand()%200;
rand_z = rand()%200;
// Movement
particles[f][3] = 1-(float)rand_x/100; // dx
particles[f][4] = 1-(float)rand_y/100; // dy
particles[f][5] = 1-(float)rand_z/100; // dz
}
// explode
for (e=0; e<25; e++)
{
slowrate = 1+tan((e+0.1)/20)*10;
gravity = tan((e+0.1)/20)/2;
for (f=0; f<n; f++)
{
particles[f][0] += particles[f][3]/slowrate;
particles[f][1] += particles[f][4]/slowrate;
particles[f][2] += particles[f][5]/slowrate;
particles[f][2] -= gravity;
setvoxel(particles[f][0],particles[f][1],particles[f][2]);
}
delay_ms(delay);
fill(0x00);
}
}
}
void effect_rotate_random_pixels (int iterations, int delay, int pixels)
{
vertex points[pixels];
vertex rotated[pixels];
float fy, fx, fz;
int x,y,z;
int i,p;
float rot_x = 0;
float rot_y = 0;
float rot_z = 0;
vertex cube_center = {3.5, 3.5, 3.5};
for (i=0; i<pixels; i++)
{
x = rand()%1200-200;
y = rand()%1200-200;
z = rand()%1200-200;
fx = (float)x/100;
fy = (float)y/100;
fz = (float)z/100;
points[i].x = fx;
points[i].y = fy;
points[i].z = fz;
setvoxel((int)points[i].x, (int)points[i].y, (int)points[i].z);
delay_ms(100);
}
delay_ms(10000);
for (i=0; i<iterations; i++)
{
rot_x = (float)i/75;
rot_y = (float)i/150;
rot_z = (float)i/200;
for (p=0; p<pixels; p++)
{
rotated[p] = point_rotate_around_point (points[p], cube_center, rot_x, rot_y, rot_z);
}
fill(0x00);
for (p=0; p<pixels; p++)
{
setvoxel((int)rotated[p].x, (int)rotated[p].y, (int)rotated[p].z);
}
delay_ms(delay);
}
fill(0x00);
}
float distance2d (float x1, float y1, float x2, float y2)
{
float dist;
dist = sqrt((x1-x2)*(x1-x2) + (y1-y2)*(y1-y2));
return dist;
}
float distance3d (float x1, float y1, float z1, float x2, float y2, float z2)
{
float dist;
dist = sqrt((x1-x2)*(x1-x2) + (y1-y2)*(y1-y2) + (z1-z2)*(z1-z2));
return dist;
}
|