Skip to content

Commit

Permalink
Added polar noise patterns.
Browse files Browse the repository at this point in the history
Added ring arrays.
  • Loading branch information
jasoncoon committed Dec 20, 2020
1 parent 060c096 commit e2103ea
Show file tree
Hide file tree
Showing 3 changed files with 246 additions and 13 deletions.
36 changes: 36 additions & 0 deletions Map.h
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,42 @@ uint8_t radii[NUM_LEDS] = { 13, 13, 13, 13, 26, 26, 26, 26, 26, 26, 26, 26, 26
217, 217, 217, 217, 217, 217, 217, 217, 217, 217, 217, 217, 217, 217, 217, 217, 217, 217, 217, 217, 217, 217, 217, 217, 217, 217, 217, 217, 217, 217, 217, 217, 217, 217, 217, 217, 217, 217, 217, 217, 217, 217, 217, 217, 217, 217, 217, 217, 217, 217, 217, 217, 217, 217, 217, 217, 217, 217, 217, 217, 217, 217, 217, 217, 217, 217, 217, 217, 217, 217, 217, 217, 217, 217, 217, 217, 217, 217, 217, 217, 217, 217, 217, 217, 217, 217, 217, 217, 217, 217, 217, 217, 217, 217, 217, 217, 217, 217, 217, 217, 217, 217, 217, 217, 217, 217, 217, 217, 217, 217, 217, 217, 217, 217, 217, 217, 217, 217, 217, 217, 217, 217, 217, 217, 217, 217, 217, 217, 217, 217, 217, 217, 217, 230, 230, 230, 230, 230, 230, 230, 230, 230, 230, 230, 230, 230, 230, 230, 230, 230, 230, 230, 230, 230, 230, 230, 230, 230, 230, 230, 230, 230, 230, 230, 230, 230, 230, 230, 230, 230, 230, 230, 230, 230, 230, 230, 230, 230, 230, 230, 230, 230, 230, 230, 230, 230, 230, 230, 230, 230, 230, 230, 230, 230, 230, 230, 230, 230, 230, 230, 230, 230, 230, 230, 230, 230, 230, 230, 230, 230, 230, 230, 230, 230, 230, 230, 230, 230, 230, 230, 230, 230, 230, 230, 230, 230, 230, 230, 230, 230, 230, 230, 230, 230, 230, 230, 230, 230, 230, 230, 230, 230, 230, 230, 230, 230, 230, 230, 230, 230, 230, 230, 230, 230, 230, 230, 230, 230, 230, 230, 230, 230, 230, 230, 230, 230, 230, 230, 230, 230, 230, 230, 230, 230, 230, 242, 242, 242, 242, 242, 242, 242, 242, 242, 242, 242, 242, 242, 242, 242, 242, 242, 242, 242, 242, 242, 242, 242, 242, 242, 242, 242, 242, 242, 242, 242, 242, 242, 242, 242, 242, 242, 242, 242, 242, 242, 242, 242, 242, 242, 242, 242, 242, 242, 242, 242, 242, 242, 242, 242, 242, 242, 242, 242, 242, 242,
242, 242, 242, 242, 242, 242, 242, 242, 242, 242, 242, 242, 242, 242, 242, 242, 242, 242, 242, 242, 242, 242, 242, 242, 242, 242, 242, 242, 242, 242, 242, 242, 242, 242, 242, 242, 242, 242, 242, 242, 242, 242, 242, 242, 242, 242, 242, 242, 242, 242, 242, 242, 242, 242, 242, 242, 242, 242, 242, 242, 242, 242, 242, 242, 242, 242, 242, 242, 242, 242, 242, 242, 242, 242, 242, 242, 242, 242, 242, 242, 242, 242, 242, 242, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255 };


// Polar coordinate mapping code for FastLED by Adam Haile, Maniacal Labs:
// http://maniacallabs.com/2015/05/04/review-code-adafruit-dotstar-disk/
// https://gist.github.com/adammhaile/a769f3ff87ff61f22ace

#define ringCount 20 //Total Number of Rings. AdaFruit Disk has 10

//Map rings on disk to indicies.
//This is where all the magic happens.
//Each represents one of the concentric rings.
uint16_t rings[ringCount][2] = {
{ 0, 3 }, // 0 Center Ring
{ 4, 15 }, // 1
{ 16, 36 }, // 2
{ 37, 65 }, // 3
{ 66, 102 }, // 4
{ 103, 147 }, // 5
{ 148, 200 }, // 6
{ 201, 262 }, // 7
{ 263, 332 }, // 8
{ 333, 410 }, // 9
{ 411, 496 }, // 10
{ 497, 590 }, // 11
{ 591, 692 }, // 12
{ 693, 803 }, // 13
{ 804, 920 }, // 14
{ 921, 1045 }, // 15
{ 1046, 1180 }, // 16
{ 1181, 1322 }, // 17
{ 1323, 1467 }, // 18
{ 1468, 1627 }, // 19 Outer Ring
};

//For convenience, last ring index
uint8_t lastRing = ringCount - 1;

void radarSweepPalette() {
fadeToBlackBy(leds, NUM_LEDS, 64);

Expand Down
183 changes: 183 additions & 0 deletions PolarNoise.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,183 @@
/*
Sol: https://github.com/evilgeniuslabs/sol
Copyright (C) 2016 Jason Coon, Evil Genius Labs
This program is free software: you can redistribute it and/or modify
it under the terms of the GNU General Public License as published by
the Free Software Foundation, either version 3 of the License, or
(at your option) any later version.
This program is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU General Public License for more details.
You should have received a copy of the GNU General Public License
along with this program. If not, see <http://www.gnu.org/licenses/>.
*/

void drawPolarNoise(CRGBPalette16 palette, uint8_t hueReduce = 0)
{
for (uint8_t ringIndex = 0; ringIndex < ringCount; ringIndex++) { // y
uint16_t ringStart = rings[ringIndex][0];
uint16_t ringEnd = rings[ringIndex][1];

for (uint16_t i = ringStart; i <= ringEnd; i++) { // x
uint8_t x = (i - ringStart) * (256 / (ringEnd - ringStart));
uint8_t y = ringIndex * (128 / ringCount);

int xoffset = noisescale * x;
int yoffset = noisescale * y;

uint8_t data = inoise8(x + xoffset + noisex, y + yoffset + noisey, noisez);

// The range of the inoise8 function is roughly 16-238.
// These two operations expand those values out to roughly 0..255
// You can comment them out if you want the raw noise data.
data = qsub8(data, 16);
data = qadd8(data, scale8(data, 39));

leds[i] = ColorFromPalette(palette, data, 255, LINEARBLEND);
}

// if(ringIndex != 0) {
// // blend the first pixel in the ring into the last
// nblend(leds[ringStart], leds[ringEnd], 192);
// nblend(leds[ringStart + 1], leds[ringEnd - 1], 128);
// nblend(leds[ringStart + 2], leds[ringEnd - 2], 64);
// }
}

noisex += noisespeedx;
noisey += noisespeedy;
noisez += noisespeedz;
}

void gradientPalettePolarNoise() {
noisespeedx = 4;
noisespeedy = 0;
noisespeedz = 0;
noisescale = 1;
colorLoop = 0;
drawPolarNoise(gCurrentPalette);
}

void palettePolarNoise() {
noisespeedx = 9;
noisespeedy = 0;
noisespeedz = 0;
noisescale = 1;
colorLoop = 0;
drawPolarNoise(palettes[currentPaletteIndex]);
}

void rainbowPolarNoise() {
noisespeedx = 0;
noisespeedy = 2;
noisespeedz = 0;
noisescale = 0;
colorLoop = 0;
drawPolarNoise(RainbowColors_p);
}

void rainbowStripePolarNoise() {
noisespeedx = 0;
noisespeedy = 2;
noisespeedz = 0;
noisescale = 0;
colorLoop = 0;
drawPolarNoise(RainbowStripeColors_p);
}

void partyPolarNoise() {
noisespeedx = 9;
noisespeedy = 0;
noisespeedz = 0;
noisescale = 1;
colorLoop = 0;
drawPolarNoise(PartyColors_p);
}

void forestPolarNoise() {
noisespeedx = 9;
noisespeedy = 0;
noisespeedz = 0;
noisescale = 1;
colorLoop = 0;
drawPolarNoise(ForestColors_p);
}

void cloudPolarNoise() {
noisespeedx = 2;
noisespeedy = 0;
noisespeedz = 0;
noisescale = 0;
colorLoop = 0;
drawPolarNoise(CloudColors_p);
}

void firePolarNoise() {
// noisespeedx = 0; // 24;
// noisespeedy = -24;
// noisespeedz = 0;
// noisescale = 4;
// colorLoop = 0;
noisespeedx = 0; // 24;
noisespeedy = -32;
noisespeedz = 0;
noisescale = 4;
colorLoop = 0;
drawPolarNoise(HeatColors_p, 60);
}

void firePolarNoise2() {
// noisespeedx = 0;
// noisespeedy = -8;
// noisespeedz = 4;
// noisescale = 1;
// colorLoop = 0;
noisespeedx = 0;
noisespeedy = -4;
noisespeedz = 4;
noisescale = 1;
colorLoop = 0;
drawPolarNoise(HeatColors_p);
}

void lavaPolarNoise() {
noisespeedx = 0;
noisespeedy = -1;
noisespeedz = 1;
noisescale = 1;
colorLoop = 0;
drawPolarNoise(LavaColors_p);
}

void oceanPolarNoise() {
noisespeedx = -1; // beatsin8(6, 0, 2) - 1;
noisespeedy = 0;
noisespeedz = 1;
noisescale = 0;
colorLoop = 0;
drawPolarNoise(OceanColors_p);
}

void blackAndWhitePolarNoise() {
SetupBlackAndWhiteStripedPalette();
noisespeedx = -4; // beatsin8(8, 0, 9) - 4;
noisespeedy = 0;
noisespeedz = 0;
noisescale = 0;
colorLoop = 0;
drawPolarNoise(blackAndWhiteStripedPalette);
}

void blackAndBluePolarNoise() {
SetupBlackAndBlueStripedPalette();
noisespeedx = 0;
noisespeedy = -8; // beatsin8(8, 0, 16) - 8;
noisespeedz = 0;
noisescale = 1;
colorLoop = 0;
drawPolarNoise(blackAndBlueStripedPalette);
}
40 changes: 27 additions & 13 deletions esp8266-fastled-webserver.ino
Original file line number Diff line number Diff line change
Expand Up @@ -178,6 +178,7 @@ typedef PatternAndName PatternAndNameList[];
#include "TwinkleFOX.h"
#include "Map.h"
#include "Noise.h"
#include "PolarNoise.h"
#include "Pacifica.h"
#include "PridePlayground.h"
#include "ColorWavesPlayground.h"
Expand Down Expand Up @@ -210,19 +211,32 @@ PatternAndNameList patterns = {
{ yGradientPalette, "Y Axis Gradient Palette" },
{ xyGradientPalette, "XY Axis Gradient Palette" },

// noise patterns
{ fireNoise, "Fire Noise" },
{ fireNoise2, "Fire Noise 2" },
{ lavaNoise, "Lava Noise" },
{ rainbowNoise, "Rainbow Noise" },
{ rainbowStripeNoise, "Rainbow Stripe Noise" },
{ partyNoise, "Party Noise" },
{ forestNoise, "Forest Noise" },
{ cloudNoise, "Cloud Noise" },
{ oceanNoise, "Ocean Noise" },
{ blackAndWhiteNoise, "Black & White Noise" },
{ blackAndBlueNoise, "Black & Blue Noise" },

// noise patterns (XY and Polar variations)
{ gradientPalettePolarNoise, "Gradient Palette Polar Noise" },
{ palettePolarNoise, "Palette Polar Noise" },
{ fireNoise, "Fire Noise" },
{ firePolarNoise, "Fire Polar Noise" },
{ fireNoise2, "Fire Noise 2" },
{ firePolarNoise2, "Fire Polar Noise 2" },
{ lavaNoise, "Lava Noise" },
{ lavaPolarNoise, "Lava Polar Noise" },
{ rainbowNoise, "Rainbow Noise" },
{ rainbowPolarNoise, "Rainbow Polar Noise" },
{ rainbowStripeNoise, "Rainbow Stripe Noise" },
{ rainbowStripePolarNoise, "Rainbow Stripe Polar Noise" },
{ partyNoise, "Party Noise" },
{ partyPolarNoise, "Party Polar Noise" },
{ forestNoise, "Forest Noise" },
{ forestPolarNoise, "Forest Polar Noise" },
{ cloudNoise, "Cloud Noise" },
{ cloudPolarNoise, "Cloud Polar Noise" },
{ oceanNoise, "Ocean Noise" },
{ oceanPolarNoise, "Ocean Polar Noise" },
{ blackAndWhiteNoise, "Black & White Noise" },
{ blackAndWhitePolarNoise, "Black & White Polar Noise" },
{ blackAndBlueNoise, "Black & Blue Noise" },
{ blackAndBluePolarNoise, "Black & Blue Polar Noise" },

{ drawAnalogClock, "Analog Clock" },

{ pridePlayground, "Pride Playground" },
Expand Down

0 comments on commit e2103ea

Please sign in to comment.