-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathcreate_animation.cpp
More file actions
86 lines (70 loc) · 1.77 KB
/
create_animation.cpp
File metadata and controls
86 lines (70 loc) · 1.77 KB
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
#include <stdio.h>
#include <iostream>
#include <fstream>
#include <math.h>
#include <cstring>
using namespace std;
bool frame[216];
void set_led(int x, int y, int z, bool value) {
frame[(z * 36) + (y * 6) + x] = value;
}
bool get_led(int x, int y, int z) {
return frame[(z * 36) + (y * 6) + x];
}
void print_frame() {
for (int c = 0; c < 216; c++) {
if (frame[c])
cout << "#";
else
cout << "-";
}
cout << endl;
cout << "50" << endl;
}
void xy_wave(int frame, int x, int y, int z) {
float xval = (sinf((frame / 3.0f) + (x * (3.14 / 6.0f))) * 3) + 2;
float yval = (sinf((frame / 3.0f) + (y * (3.14 / 6.0f))) * 3) + 2;
float val = (xval + yval) * 0.5f;
if (z > val && z < val + 1) {
set_led(x,y,z,true);
}
}
void random_plot(int frame, int x, int y, int z) {
if (rand() % 2 == 0)
set_led(x,y,z,true);
}
void fill(char c) {
for (int i = 0; i < 216; i++) {
frame[i] = c;
}
}
void rain(int frame, int x, int y, int z) {
//spawn rain
//50ms per frame, 20 frames per second
if (z == 0 && (frame % 5) == 1) { //every second
if (rand() % 20 == 0)
set_led(x,y,z,true);
}
if (z > 0 && (frame % 15) == 0) {
if (get_led(x,y,z-1) && !get_led(x,y,z)) {
set_led(x,y,z-1, false);
set_led(x,y,z, true);
}
}
//move rain down
}
int main() {
for (int i = 0; i < 1500; i++) {
for (int x = 0; x < 6; x++) {
for (int y = 0; y < 6; y++) {
for (int z = 5; z > -1; z--) {
rain(i, x, y, z);
}
}
}
fill('#');
//memset(&frame[0], 0, 216);
print_frame();
}
return 0;
}