Skip to content

Instantly share code, notes, and snippets.

Created October 9, 2014 09:08
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save anonymous/691a9ac3fd56be8cbfd7 to your computer and use it in GitHub Desktop.
Save anonymous/691a9ac3fd56be8cbfd7 to your computer and use it in GitHub Desktop.
problematic scaling
#include<FastLED.h>
#define LED_PIN 13
#define BRIGHTNESS 100
#define LED_TYPE WS2812B
#define COLOR_ORDER GRB
const uint8_t kMatrixWidth = 16;
const uint8_t kMatrixHeight = 16;
const bool kMatrixSerpentineLayout = true;
// some counters for moving the edge
byte c1 = 0;
byte c2 = 64;
byte c3;
#define NUM_LEDS (kMatrixWidth * kMatrixHeight)
#define MAX_DIMENSION ((kMatrixWidth>kMatrixHeight) ? kMatrixWidth : kMatrixHeight)
CRGB leds[kMatrixWidth * kMatrixHeight];
uint8_t noise[MAX_DIMENSION][MAX_DIMENSION];
CRGBPalette16 currentPalette( RainbowStripeColors_p );
uint8_t colorLoop = 0;
void setup() {
delay(500);
LEDS.addLeds<LED_TYPE,LED_PIN,COLOR_ORDER>(leds+5,NUM_LEDS-5);
LEDS.setBrightness(BRIGHTNESS);
}
// fills the array with 0-255
void fillnoise8() {
for(int i = 0; i < MAX_DIMENSION; i++) {
for(int j = 0; j < MAX_DIMENSION; j++) {
byte data = i * kMatrixWidth + j;
noise[i][j] = data;
}
}
}
void MapNoiseToRectangle(uint8_t x1, uint8_t y1, uint8_t x2, uint8_t y2)
{
static uint8_t ihue=0;
for(int i = x1; i <= x2; i++) {
for(int j = y1; j <= y2; j++) {
uint8_t index = noise[i * (kMatrixWidth-1) / (x2-x1)][j * (kMatrixHeight-1) / (y2-y1)];
uint8_t bri = 255;
if( colorLoop) {
index += ihue;
}
CRGB color = ColorFromPalette( currentPalette, index, bri);
leds[XY(i,j)] = color;
}
}
ihue+=1;
}
void CLS() {
for(int i = 0; i <NUM_LEDS; i++) {
leds[i]=0x000000;
}
}
void loop() {
CLS();
fillnoise8();
c3++;
if (c3%4==0) {
c1++;
c2+=2;
}
MapNoiseToRectangle(sin8(c1)/20, sin8(c2)/20, 15, 15);
LEDS.show();
}
uint16_t XY( uint8_t x, uint8_t y)
{
uint16_t i;
if( kMatrixSerpentineLayout == false) {
i = (y * kMatrixWidth) + x;
}
if( kMatrixSerpentineLayout == true) {
if( y & 0x01) {
uint8_t reverseX = (kMatrixWidth - 1) - x;
i = (y * kMatrixWidth) + reverseX;
}
else {
i = (y * kMatrixWidth) + x;
}
}
return i;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment