Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- //Simple sand automata
- //fastled 16x16 matrix demo
- //Yaroslaw Turbin 14.12.2020
- //https://vk.com/ldirko
- //https://www.reddit.com/user/ldirko/
- //for non commercial use! ))
- #define hue 30
- void randomdot(){
- byte a= LED_COLS/2; //random8(LED_COLS/4)+LED_COLS*3/8; //
- if (!random8(4)) leds[XY(a,LED_ROWS-1)].setHue(random8(hue,hue+45)); // 0 or 1
- }
- void updatesand (){
- int index, indexXadd1Y, indexXsub1Y, indexXYadd1;
- for (int y=0; y<LED_ROWS-1; y++) {
- for (int x=1; x<LED_COLS-1; x++) {
- index = XY(x,y); indexXadd1Y = XY(x+1,y); indexXsub1Y = XY(x-1,y); indexXYadd1 = XY(x,y+1);
- if (!leds[index] && !leds[indexXYadd1]) continue;
- if (!leds[index] && leds[indexXYadd1]) {leds[index]=leds[indexXYadd1]; leds[indexXYadd1]=0;}
- if (leds[index] && leds[indexXYadd1] && !leds[indexXsub1Y] && !leds[indexXadd1Y])
- if (random8(2)) {leds[indexXsub1Y]=leds[indexXYadd1]; leds[indexXYadd1]=0;}
- else {leds[indexXadd1Y]=leds[indexXYadd1]; leds[indexXYadd1]=0;}
- if (leds[index] && leds[indexXYadd1] && !leds[indexXsub1Y] && leds[indexXadd1Y]) {leds[indexXsub1Y]=leds[indexXYadd1]; leds[indexXYadd1]=0;}
- if (leds[index] && leds[indexXYadd1] && leds[indexXsub1Y] && !leds[indexXadd1Y]) {leds[indexXadd1Y]=leds[indexXYadd1]; leds[indexXYadd1]=0;}
- }}
- }
- void randomdel(){
- for (int i=0; i<N_LEDS; i++) {
- if (!random8(3)) leds[i]=0;
- }
- }
- void falldown(){
- for (int y=0; y<LED_ROWS-1; y++) {
- for (int x=0; x<LED_COLS; x++) {
- if (!leds[XY(x,y)] && leds[XY(x,y+1)]) {leds[XY(x,y)]=leds[XY(x,y+1)]; leds[XY(x,y+1)]=0;}
- }}
- }
- void draw() {
- EVERY_N_MILLISECONDS(80) {updatesand(); randomdot(); }
- EVERY_N_MILLISECONDS(10000) {randomdel(); falldown(); falldown(); falldown();}
- }
Add Comment
Please, Sign In to add comment