-
Notifications
You must be signed in to change notification settings - Fork 2
/
Copy pathworm.c
46 lines (34 loc) · 1013 Bytes
/
worm.c
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
#include <stdlib.h>
#include "cube.h"
void effect_wormsqueeze(int size, int axis, int direction, int seconds, int delay)
{
int x, y, i, j, k, dx, dy;
int cube_size;
int origin = 0;
int iterations = seconds * 1000 / delay;
if (direction == -1)
origin = 7;
cube_size = 8-(size-1);
x = rand()%cube_size;
y = rand()%cube_size;
for (i=0; i<iterations; i++) {
dx = ((rand()%3)-1);
dy = ((rand()%3)-1);
if ((x+dx) > 0 && (x+dx) < cube_size)
x += dx;
if ((y+dy) > 0 && (y+dy) < cube_size)
y += dy;
shift(axis, direction);
for (j=0; j<size; j++) {
for (k=0; k<size; k++) {
if (axis == AXIS_Z)
setvoxel(x+j, y+k, origin);
if (axis == AXIS_Y)
setvoxel(x+j, origin, y+k);
if (axis == AXIS_X)
setvoxel(origin, y+j, x+k);
}
}
delay_ms(delay);
}
}