-
Notifications
You must be signed in to change notification settings - Fork 0
/
Snow.pde
77 lines (72 loc) · 1.34 KB
/
Snow.pde
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
char Twirlix(unsigned int i) {
char t[] = ".-*";
return t[i % (sizeof(t) - 1)];
}
typedef struct flake {
unsigned int position;
unsigned int speed;
unsigned int angle;
} flake_t;
flake_t storm[20] = {
{0, 1, 0},
{0, 3, 0},
{0, 5, 0},
{0, 7, 0},
{0, 9, 0},
{0, 11, 0},
{0, 8, 0},
{0, 6, 0},
{0, 4, 0},
{0, 2, 0},
{0, 9, 0},
{0, 7, 0},
{0, 5, 0},
{0, 3, 0},
{0, 1, 0},
{0, 10, 0},
{0, 8, 0},
{0, 6, 0},
{0, 4, 0},
{0, 2, 0},
};
void snow (view_ptr view, viewport_ptr port) {
int r, c;
fputc(0x0C, &LCD.dev);
for (r=0; r < LCD.h; r++) {
for (c=0; c < LCD.w; c++) {
storm[c].position += storm[c].speed;
if (storm[c].position / 111 > LCD.h) storm[c].position = 0;
if (storm[c].position / 111 != r) fputc(' ', &LCD.dev);
else {
fputc(Twirlix(storm[c].angle), &LCD.dev);
storm[c].angle++;
}
}
fputc('\n', &LCD.dev);
}
Disp_RC(1,2); fprintf(&LCD.dev, "Love me tender...\n");
}
void snowkey(view_ptr me, char key) {
uint8_t temp;
if (key==0) me->eject(me);
//if (key==3) PORTL ^= 0x04;
if (key==2) {
// Save PWM and gate
//temp = PORTL & 0x04;
//PORTL &= 0xFF & 0x04;
// IN A
PORTL ^= 0x01;
// IN B
PORTD ^= 0x04;
// Restore PWM
//PORTL |= temp;
}
}
view_ptr SnowFactory() {
view_ptr v = (view_ptr) malloc(sizeof(view_t));
if (v) {
ViewConstruct(v, snow);
v->key = snowkey;
}
return v;
}