//sun radiation circular
//fastled circular 241 leds demo
//Yaroslaw Turbin 22.01.2020
//https://vk.com/ldirko
//https://www.reddit.com/user/ldirko/
//https://wokwi.com/arduino/projects/288134661735973389
#include "FastLED.h"
// Matrix size
#define NUM_ROWS 17
#define NUM_COLS 17
#define NUM_LEDS NUM_ROWS * NUM_COLS
// LEDs pin
#define DATA_PIN 3
// LED brightness
#define BRIGHTNESS 255
// Define the array of leds
CRGB leds[NUM_LEDS+1];
byte bump[(NUM_COLS+2)*(NUM_ROWS+2)];
CRGB chsvLut[256];
void setup() {
FastLED.addLeds<NEOPIXEL, DATA_PIN>(leds, NUM_LEDS);
FastLED.setBrightness(BRIGHTNESS);
generateCHSVlut();
}
void generateCHSVlut(){
for (int j= 0; j<256; j++)
chsvLut[j] = HeatColor(j/1.4); //256 pallette color
}
void generatebump (){
int t=millis()/2;
int index=0;
for (byte j= 0; j< (NUM_ROWS+2); j++) {
for (byte i=0; i< (NUM_COLS+2); i++) {
byte col = (inoise8_raw(i * 40, j *40,t))/2;
bump[index++] = col;
}}
}
void Bumpmap(){
int yindex=(NUM_COLS+3);
int8_t vly=-(NUM_ROWS/2+1);
for (byte y = 0; y < NUM_ROWS; y++) {
++vly;
int8_t vlx=-(NUM_COLS/2+1);
for (byte x = 0; x < NUM_COLS; x++) {
++vlx;
int8_t nx=bump[x+yindex+1]-bump[x+yindex-1];
int8_t ny=bump[x+yindex+(NUM_COLS+2)]-bump[x+yindex-(NUM_COLS+2)];
byte difx=abs8(vlx*7-nx);
byte dify=abs8(vly*7-ny);
int temp = difx*difx+dify*dify;
int col = 255-temp/13;
if (col<0) col=0;
leds[XY(x,y)] = chsvLut[col]; //thx satubarosu ))
}
yindex+=(NUM_COLS+2);
}
}
void loop() {
generatebump();
Bumpmap();
FastLED.show();
}
byte XY (byte x, byte y) {
static byte PlanarLookTable [] = { //i made this lookup table in Excel ))))
241, 53, 54, 55, 56, 57, 58, 59, 0, 1, 2, 3, 4, 5, 6, 7, 241,
52, 241, 241, 103, 104, 105, 106, 107, 60, 61, 62, 63, 64, 65, 241, 241, 8,
51, 241, 102, 241, 144, 145, 146, 147, 108, 109, 110, 111, 112, 241, 66, 241, 9,
50, 101, 241, 143, 241, 177, 178, 179, 148, 149, 150, 151, 241, 113, 241, 67, 10,
49, 100, 142, 241, 176, 241, 202, 203, 180, 181, 182, 241, 152, 241, 114, 68, 11,
48, 99, 141, 175, 241, 201, 241, 219, 204, 205, 241, 183, 241, 153, 115, 69, 12,
47, 98, 140, 174, 200, 241, 218, 231, 220, 221, 206, 241, 184, 154, 116, 70, 13,
46, 97, 139, 173, 199, 217, 230, 239, 232, 233, 222, 207, 185, 155, 117, 71, 14,
45, 96, 138, 172, 198, 216, 229, 238, 241, 234, 223, 208, 186, 156, 118, 72, 15,
44, 95, 137, 171, 197, 215, 228, 237, 236, 235, 224, 209, 187, 157, 119, 73, 16,
43, 94, 136, 170, 196, 241, 214, 227, 226, 225, 210, 241, 188, 158, 120, 74, 17,
42, 93, 135, 169, 241, 195, 241, 213, 212, 211, 241, 189, 241, 159, 121, 75, 18,
41, 92, 134, 241, 168, 241, 194, 193, 192, 191, 190, 241, 160, 241, 122, 76, 19,
40, 91, 241, 133, 241, 167, 166, 165, 164, 163, 162, 161, 241, 123, 241, 77, 20,
39, 241, 90, 241, 132, 131, 130, 129, 128, 127, 126, 125, 124, 241, 78, 241, 21,
38, 241, 241, 89, 88, 87, 86, 85, 84, 83, 82, 81, 80, 79, 241, 241, 22,
241, 37, 36, 35, 34, 33, 32, 31, 30, 29, 28, 27, 26, 25, 24, 23, 241};
return (PlanarLookTable[y*NUM_COLS+x]);
}