-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathmain.cpp
80 lines (64 loc) · 1.75 KB
/
main.cpp
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
#include "Adafruit_PixelDust.h"
#include <stdlib.h>
#include <stdio.h>
#include <fstream>
#define WIDTH 128
#define HEIGHT 64
#define DEPTH 16
#define N_GRAINS 500
#define MAX_ROUND 300
int _round = 0;
Adafruit_PixelDust sand(WIDTH, HEIGHT, DEPTH, N_GRAINS, 1, 128);
uint8_t pixelBuf[WIDTH * HEIGHT * DEPTH];
int main()
{
memset(pixelBuf, 0, sizeof(pixelBuf));
sand.begin();
for (int z = 6; z < 10; z++)
{
for (int y = 30; y < 34; y++)
{
for (int x = 60; x < 68; x++)
{
sand.setPixel(x, y, z);
pixelBuf[z * WIDTH * HEIGHT + y * WIDTH + x] = 3;
}
}
}
sand.randomize();
FILE *out = fopen("./out.txt", "w");
dimension_t x, y, z;
for (int i = 0; i < N_GRAINS; i++)
{
sand.getPosition(i, &x, &y, &z);
// printf("%d\t%d\t%d\n", x, y, z);
pixelBuf[z * WIDTH * HEIGHT + y * WIDTH + x] = 1;
}
for (int i = 0; i < sizeof(pixelBuf); i++)
{
fprintf(out, "%d,", pixelBuf[i]);
}
fprintf(out, "\n");
while (_round++ < MAX_ROUND)
{
for (int i = 0; i < N_GRAINS; i++)
{
sand.getPosition(i, &x, &y, &z);
pixelBuf[z * WIDTH * HEIGHT + y * WIDTH + x] = 0;
}
sand.iterate(1000, 1000, -1000);
// printf(" ************** round %d **************\n", _round);
for (int i = 0; i < N_GRAINS; i++)
{
sand.getPosition(i, &x, &y, &z);
// printf("%d\t%d\t%d\n", x, y, z);
pixelBuf[z * WIDTH * HEIGHT + y * WIDTH + x] = 1;
}
for (int i = 0; i < sizeof(pixelBuf); i++)
{
fprintf(out, "%d,", pixelBuf[i]);
}
fprintf(out, "\n");
}
fclose(out);
}