//Hipnotic_RGB
//241 LED ring cilindrical map
//Fastled rgb led demo
//Yaroslaw Turbin, 25-03-2021
//https://vk.com/ldirko
//https://www.reddit.com/user/ldirko/
//https://twitter.com/ldir_ko
#include <FastLED.h>
#define DATA_PIN 3
#define LED_COLS 32 // resolution for cilindrical lookup table
#define LED_ROWS 32 // resolution for cinindrical lookup table
#define NUM_LEDS 1024
#define LED_TYPE WS2812B //leds type
#define COLOR_ORDER GRB //color order of leds
#define BRIGHTNESS 255
CRGB leds[NUM_LEDS+1]; //one safe pixel in bottom. its index 2410
#define petals 1
bool setupm = 1;
const uint8_t C_X = LED_COLS / 2;
const uint8_t C_Y = LED_ROWS / 2;
const uint8_t mapp = 255 / LED_COLS;
struct{
uint8_t angle;
uint8_t radius;
} rMap[NUM_LEDS];
void setup() {
FastLED.addLeds<LED_TYPE, DATA_PIN, COLOR_ORDER>(leds, NUM_LEDS)
.setCorrection( TypicalLEDStrip );
FastLED.clear();
}
void loop() {
// FastLED.clear();
static byte speed = 6;
LEDS.show();
if (setupm) {
setupm = 0;
for (int8_t x = -C_X; x < C_X + (LED_COLS % 2); x++) {
for (int8_t y = -C_Y; y < C_Y + (LED_ROWS % 2); y++) {
uint16_t coord = XY(x + C_X, y + C_Y);
rMap[coord].angle = 128 * (atan2(y, x) / PI);
rMap[coord].radius = hypot(x, y) * mapp; //thanks Sutaburosu
}
}
}
// static byte speed = 2;
static uint16_t t;
t += speed;
uint16_t t1 = t / 2;
for (uint8_t x = 0; x < LED_COLS; x++) {
for (uint8_t y = 0; y < LED_ROWS; y++) {
uint16_t coord = XY(x,y);
uint8_t angle = sin8(t1 / 2 + rMap[coord].angle * 5);
uint8_t radius = (rMap[coord].radius) * 2 - t;
uint8_t noise[3] = { inoise8(angle, radius, t1), inoise8(angle, 12032 + t1, radius), inoise8(radius, 120021 + t1, angle) };
for(uint8_t i = 0; i <3; i++){
noise[i] = (noise[i] < 128) ? 0 : constrain((noise[i] - 128) * 3,0,255);
}
leds[coord] = CRGB(noise[0], noise[1], noise[2]);
}
}
delay(16);
}
uint16_t XY (uint8_t x, uint8_t y) { return (y * LED_COLS + x);}