-
Notifications
You must be signed in to change notification settings - Fork 2
/
Copy pathballs.c
168 lines (161 loc) · 4.3 KB
/
balls.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
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
#include "cube.h"
static const unsigned char dat3[24]= {
0x00, 0x01, 0x02, 0x03, 0x04, 0x05, 0x06, 0x16,
0x26, 0x36, 0x46, 0x56, 0x66, 0x65, 0x64, 0x63,
0x62, 0x61, 0x60, 0x50, 0x40, 0x30, 0x20, 0x10
};
/*
* Reorder two values to make first one smaller than the second one.
*/
static void reorder(int *a, int *b)
{
int t;
if (*a > *b) {
t = *a;
*a = *b;
*b = t;
}
}
static void box(int x1, int y1, int z1, int x2, int y2, int z2, int fill, int le)
{
int i, j, t = 0;
reorder(&x1, &x2);
reorder(&y1, &y2);
reorder(&z1, &z2);
for (i=x1; i<=x2; i++)
t |= 1<<i;
if (!le)
t = ~t;
if (fill) {
if (le) {
for (i=z1; i<=z2; i++) {
for (j=y1; j<=y2; j++)
cube[j][i] |= t;
}
} else {
for (i=z1; i<=z2; i++) {
for (j=y1; j<=y2; j++)
cube[j][i] &= t;
}
}
} else {
if (le) {
cube[y1][z1] |= t;
cube[y2][z1] |= t;
cube[y1][z2] |= t;
cube[y2][z2] |= t;
} else {
cube[y1][z1] &= t;
cube[y2][z1] &= t;
cube[y1][z2] &= t;
cube[y2][z2] &= t;
}
t = (1 << x1) | (1 << x2);
if (!le)
t = ~t;
if (le) {
for (j=z1; j<=z2; j+=(z2-z1)) {
for (i=y1; i<=y2; i++)
cube[i][j] |= t;
}
for (j=y1; j<=y2; j+=(y2-y1)) {
for (i=z1; i<=z2; i++)
cube[j][i] |= t;
}
} else {
for (j=z1; j<=z2; j+=(z2-z1)) {
for (i=y1; i<=y2; i++) {
cube[i][j] &= t;
}
}
for (j=y1; j<=y2; j+=(y2-y1)) {
for (i=z1; i<=z2; i++) {
cube[j][i] &= t;
}
}
}
}
}
void effect_rotating_balls(int delay)
{
int i, j, an[4], x, y, t;
for (i=1; i<7; i++) {
fill(0);
box(0, 6, 6, 1, 7, 7, 1, 1);
box(i, 6, 6-i, i+1, 7, 7-i, 1, 1);
box(i, 6, 6, i+1, 7, 7, 1, 1);
box(0, 6, 6-i, 1, 7, 7-i, 1, 1);
box(0, 6-i, 6, 1, 7-i, 7, 1, 1);
box(i, 6-i, 6-i, i+1, 7-i, 7-i, 1, 1);
box(i, 6-i, 6, i+1, 7-i, 7, 1, 1);
box(0, 6-i, 6-i, 1, 7-i, 7-i, 1, 1);
delay_ms(delay*3);
}
for (i=0; i<4; i++) {
an[i] = 6*i;
}
for (i=0; i<35; i++) {
fill(0);
for (j=0; j<4; j++) {
t = an[j] % 24;
x = dat3[t] >> 4;
y = dat3[t] & 0x0f;
box(x, y, 0, x+1, y+1, 1, 1, 1);
box(x, y, 6, x+1, y+1, 7, 1, 1);
}
for (j=0; j<4; j++)
an[j]++;
delay_ms(delay);
}
for (i=0; i<35; i++) {
fill(0);
for (j=0; j<4; j++) {
t = an[j] % 24;
x = dat3[t] >> 4;
y = dat3[t] & 0x0f;
box(x, y, 0, x+1, y+1, 1, 1, 1);
box(x, y, 6, x+1, y+1, 7, 1, 1);
}
for (j=0; j<4; j++)
an[j]--;
delay_ms(delay);
}
for (i=0; i<35; i++) {
fill(0);
for (j=0; j<4; j++) {
t = an[j] % 24;
x = dat3[t] >> 4;
y = dat3[t] & 0x0f;
box(x, 0, y, x+1, 1, y+1, 1, 1);
box(x, 6, y, x+1, 7, y+1, 1, 1);
}
for (j=0; j<4; j++)
an[j]++;
delay_ms(delay);
}
for (i=0; i<36; i++) {
fill(0);
for (j=0; j<4; j++) {
t = an[j] % 24;
x = dat3[t] >> 4;
y = dat3[t] & 0x0f;
box(x, 0, y, x+1, 1, y+1, 1, 1);
box(x, 6, y, x+1, 7, y+1, 1, 1);
}
for (j=0; j<4; j++)
an[j]--;
delay_ms(delay);
}
for (i=6; i>0; i--) {
fill(0);
box(0, 6, 6, 1, 7, 7, 1, 1);
box(i, 6, 6-i, i+1, 7, 7-i, 1, 1);
box(i, 6, 6, i+1, 7, 7, 1, 1);
box(0, 6, 6-i, 1, 7, 7-i, 1, 1);
box(0, 6-i, 6, 1, 7-i, 7, 1, 1);
box(i, 6-i, 6-i, i+1, 7-i, 7-i, 1, 1);
box(i, 6-i, 6, i+1, 7-i, 7, 1, 1);
box(0, 6-i, 6-i, 1, 7-i, 7-i, 1, 1);
delay_ms(delay*3);
}
}