From 0f65cd1f9256db9f8ac99c7d7b8498bc5675b49a Mon Sep 17 00:00:00 2001 From: Neale Pickett Date: Sat, 1 Jan 2022 09:35:06 -0700 Subject: [PATCH] Make it less visually busy, for living on our wall --- picker.cpp | 16 ++++++++++++++ picker.h | 11 ++++++++++ wallart.ino | 62 ++++++++++++++++++++++++++++++++++++++++++----------- 3 files changed, 77 insertions(+), 12 deletions(-) create mode 100644 picker.cpp create mode 100644 picker.h diff --git a/picker.cpp b/picker.cpp new file mode 100644 index 0000000..1bd2c3e --- /dev/null +++ b/picker.cpp @@ -0,0 +1,16 @@ +#include +#include +#include "picker.h" + +Picker::Picker() { + val = random(1, 256); +} + +bool Picker::Pick(uint8_t likelihood) { + if ((val > 0) && (val <= likelihood)) { + val = 0; + return true; + } + val -= likelihood; + return false; +} \ No newline at end of file diff --git a/picker.h b/picker.h new file mode 100644 index 0000000..1b29e06 --- /dev/null +++ b/picker.h @@ -0,0 +1,11 @@ +#pragma once + +#include + +class Picker { +public: + Picker(); + bool Pick(uint8_t); +private: + uint8_t val; +}; diff --git a/wallart.ino b/wallart.ino index b6dd84e..da497f4 100644 --- a/wallart.ino +++ b/wallart.ino @@ -1,4 +1,5 @@ #include +#include "picker.h" #define NEOPIXEL_PIN 2 #define GRIDLEN 50 @@ -8,8 +9,8 @@ CRGB grid[GRIDLEN]; -void fade() { - int reps = 300 + random(GRIDLEN); +void fade(int cycles = 2) { + int reps = (cycles*GRIDLEN) + random(GRIDLEN); int hue = random(256); for (int i = 0; i < reps; i++) { for (int pos = 0; pos < 8; pos++) { @@ -20,7 +21,7 @@ void fade() { } } -void singleCursor() { +void singleCursor(int count = 80) { for (int i = 0; i < 80; i++) { grid[20] = CHSV(0, 210, 127 * (i%2)); FastLED.show(); @@ -29,10 +30,10 @@ void singleCursor() { } #define NUM_SPARKS 3 -void sparkle() { +void sparkle(int cycles=50) { int pos[NUM_SPARKS] = {0}; - for (int i = 0; i < 50; i++) { - for (int j = 0; j < NUM_SPARKS; j++) { + for (int i = 0; i < cycles; i++) { + for (int j = 0; j < GRIDLEN/16; j++) { pos[j] = random(GRIDLEN); grid[pos[j]] = CRGB::Gray; } @@ -46,7 +47,7 @@ void sparkle() { #define NUM_GLITCH 4 #define GLITCH_FRAMES 64 -void glitchPulse() { +void glitchPulse(int cycles=1000) { int steps[NUM_GLITCH] = {0}; int pos[NUM_GLITCH] = {0}; CRGB color[NUM_GLITCH]; @@ -56,7 +57,7 @@ void glitchPulse() { color[i] = CRGB::Brown; } - for (int frame = 0; frame < 1000; frame++) { + for (int frame = 0; frame < cycles; frame++) { for (int i = 0; i < NUM_GLITCH; i++) { if (steps[i] == 0) { steps[i] = GLITCH_FRAMES; @@ -77,7 +78,34 @@ void glitchPulse() { FastLED.show(); delay(100); } +} +void conwayish(int cycles=1000) { + uint8_t total[GRIDLEN]; + uint8_t left[GRIDLEN] = {0}; + uint8_t hue = random(0, 64); + + for (int i = 0; i < GRIDLEN; i++) { + total[i] = random(64, 256); + left[i] = total[i]; + } + + for (int frame = 0; frame < cycles; frame++) { + for (int i = 0; i < GRIDLEN; i++) { + if (left[i] == 0) { + left[i] = total[i]; + if (grid[i].getLuma() == 0) { + grid[i].setHSV(hue, 180, 192); + } else { + grid[i] = CRGB::Black; + } + } else { + left[i]--; + } + } + FastLED.show(); + delay(20); + } } void setup() { @@ -87,8 +115,18 @@ void setup() { } void loop() { - fade(); - singleCursor(); - sparkle(); - glitchPulse(); + Picker p; + + if (p.Pick(1)) { + fade(); + singleCursor(20); + } else if (p.Pick(1)) { + sparkle(); + } else if (p.Pick(4)) { + singleCursor(); + } else if (p.Pick(8)) { + conwayish(); + } else if (p.Pick(8)) { + glitchPulse(); + } } \ No newline at end of file