From 5a4778c3137752738a9c16960614707385097239 Mon Sep 17 00:00:00 2001 From: Ewoud Date: Thu, 8 Aug 2024 12:32:03 +0200 Subject: [PATCH] UserModLive: artifx effects testing (WIP) Added beatMania and Green Ripple Reflections pio.ini move to asmParser 2.1.1 LedEffects: add slider2 UserModLive: - add triangle, time, beatSin8, fadeToBlackBy, sCFP (Set color from pixel) --- misc/beatmaniaSL.sc | 55 ++++++++++++++++++++++++++++++ misc/green_ripple_reflectionsSL.sc | 54 +++++++++++++++++++++++++++++ platformio.ini | 2 +- src/App/LedEffects.h | 1 + src/User/UserModLive.h | 29 ++++++++++++++-- 5 files changed, 137 insertions(+), 4 deletions(-) create mode 100644 misc/beatmaniaSL.sc create mode 100644 misc/green_ripple_reflectionsSL.sc diff --git a/misc/beatmaniaSL.sc b/misc/beatmaniaSL.sc new file mode 100644 index 00000000..625f1a61 --- /dev/null +++ b/misc/beatmaniaSL.sc @@ -0,0 +1,55 @@ +//from https://github.com/MoonModules/WLED-Effects/blob/master/ARTIFX/wled/beatmania.wled +//Created by Andrew Tuline Converted by Ewoud Wijma + +uint8_t locn1; +uint8_t locn2; +uint8_t locn3; +uint8_t locn12; + +uint8_t colr1; +uint8_t colr2; +uint8_t colr3; +uint8_t colr12; + +uint8_t bri1; +uint8_t bri2; +uint8_t bri3; +uint8_t bri12; + +void setup() +{ +} + + +void loop() { + + //fadeToBlackBy(slider2/8); // Adjustable fade rate. + + locn1 = beatSin8(slider1/3+1,0,width) ; // Adjustable speed. + locn2 = beatSin8(slider1/4+1,0,width); + locn3 = beatSin8(slider1/5+1,0,width/2+width/3); + + colr1 = beatSin8(slider2/6+1,0,255); + colr2 = beatSin8(slider2/7+1,0,255); + colr3 = beatSin8(slider2/8+1,0,255); + + bri1 = beatSin8(slider2/6+1,32,255); + bri2 = beatSin8(slider2/7+1,32,255); + bri3 = beatSin8(slider2/8+1,32,255) ; // One too many beats. + + locn12 = locn1+locn2; + colr12 = colr1+colr2; + bri12 = bri1+bri2; + sCFP(locn12,colr12,bri12); + sCFP(locn1,colr2,bri1); + sCFP(locn2%(width-1),colr1,bri2); +} + +void main() { + resetStat(); + setup(); + while (2>1) { + loop(); + show(); + } +} \ No newline at end of file diff --git a/misc/green_ripple_reflectionsSL.sc b/misc/green_ripple_reflectionsSL.sc new file mode 100644 index 00000000..5fec1d7a --- /dev/null +++ b/misc/green_ripple_reflectionsSL.sc @@ -0,0 +1,54 @@ +//https://github.com/MoonModules/WLED-Effects/blob/master/ARTIFX/wled/green_ripple_reflections.wled +//original from https://patterns.electromage.com/pattern/Ktjben4j36Wqxnk8N +//Converted by Andrew Tuline and Ewoud Wijma + +float PI2; +float PI6; +float PI10; + +float t1; +float t2; +float t3; + +float a; +float b; +float c; +float v; + +void setup() +{ + PI2 = 6.28318; + PI6 = PI2 * 3; + PI10 = PI2 * 5; +} + + +void loop() { + + t1 = time(0.03) * PI2; + t2 = time(0.05) * PI2; + t3 = time(0.04) * PI2; + + for (uint8_t index = 0; index < width; index++) { + a = sin(index * PI10 / width + t1); + a = a * a; + b = sin(index * PI6 / width - t2); + c = triangle(index * 3 / width + 1 + sin(t3) / 2 % 1); + v = (a + b + c) / 3; + v = v * v; + //printCustom((float)index,a,b,c,v); + CRGB gg = hsv(0.3 * 255, a * 255, v * 255); + for (uint8_t y = 0; y < height; y++) { + sPC(0, y*panel_width+index, gg); + } + } +} + +void main() { + resetStat(); + setup(); + while (2>1) { + loop(); + show(); + } +} \ No newline at end of file diff --git a/platformio.ini b/platformio.ini index 45733857..cdc511f2 100644 --- a/platformio.ini +++ b/platformio.ini @@ -70,7 +70,7 @@ build_flags = -D STARBASE_USERMOD_LIVE lib_deps = ; https://github.com/hpwit/ASMParser.git#4b2da1a ; mem branche commit of 20240716 - https://github.com/hpwit/ASMParser.git#v2 ; + https://github.com/hpwit/ASMParser.git#v2.1.1 ; [STARLIGHT_CLOCKLESS_LED_DRIVER] build_flags = diff --git a/src/App/LedEffects.h b/src/App/LedEffects.h index 881f13ca..b50e355f 100644 --- a/src/App/LedEffects.h +++ b/src/App/LedEffects.h @@ -2983,6 +2983,7 @@ class LiveScriptEffect: public Effect { }}); //script ui->initSlider(parentVar, "Slider1", &slider1); + ui->initSlider(parentVar, "Slider2", &slider2); } }; diff --git a/src/User/UserModLive.h b/src/User/UserModLive.h index f3bb030a..c4b0996b 100644 --- a/src/User/UserModLive.h +++ b/src/User/UserModLive.h @@ -72,16 +72,25 @@ static void resetShowStats() static void dispshit(int g) { ppf("coming from assembly int %x %d", g, g);} static void __print(char *s) {ppf("from assembly :%s\r\n", s);} static void showError(int line, uint32_t size, uint32_t got) { ppf("Overflow error line %d max size: %d got %d", line, size, got);} -static void displayfloat(float j) {ppf("display float %f", j);} +static void displayfloat(float j) {ppf(" %f", j);} static float _hypot(float x,float y) {return hypot(x,y);} static float _atan2(float x,float y) { return atan2(x,y);} static float _sin(float j) {return sin(j);} +static float _triangle(float j) {return 1.0 - fabs(fmod(2 * j, 2.0) - 1.0);} +static float _time(float j) { + float myVal = sys->now(); + myVal = myVal / 65535 / j; // PixelBlaze uses 1000/65535 = .015259. + myVal = fmod(myVal, 1.0); // ewowi: with 0.015 as input, you get fmod(millis/1000,1.0), which has a period of 1 second, sounds right + return myVal; +} //LEDS specific -static CRGB POSV(uint8_t h, uint8_t s, uint8_t v) {return CHSV(h, s, v);} +static CRGB POSV(uint8_t h, uint8_t s, uint8_t v) {return CHSV(h, s, v);} //why call POSV and not hsv? static uint8_t _sin8(uint8_t a) {return sin8(a);} +static float _beatSin8(uint8_t a1, uint8_t a2, uint8_t a3) {return beatsin8(a1, a2, a3);} static LedsLayer *gLeds = nullptr; +static void _fadeToBlackBy(uint8_t a1) {gLeds->fadeToBlackBy(a1);} static void sPCLive(int t, uint16_t pixel, CRGB color) { // int t needed - otherwise wrong colors, very strange if (gLeds) { @@ -89,7 +98,15 @@ static void sPCLive(int t, uint16_t pixel, CRGB color) { // int t needed - other gLeds->setPixelColor(pixel, color); } } -uint8_t slider1 = 10; +static void sCFPLive(uint16_t pixel, uint8_t index, uint8_t brightness) { // int t needed - otherwise wrong colors, very strange + if (gLeds) + { + // if (t == 0) ppf(" %d,%d,%d", color.r, color.g, color.b); + gLeds->setPixelColor(pixel, ColorFromPalette(gLeds->palette, index, brightness)); + } +} +uint8_t slider1 = 128; +uint8_t slider2 = 128; //End LEDS specific @@ -160,6 +177,9 @@ class UserModLive:public SysModule { addExternalFun("float", "atan2","(float a1, float a2)",(void*)_atan2); addExternalFun("float", "hypot","(float a1, float a2)",(void*)_hypot); addExternalFun("float", "sin", "(float a1)", (void *)_sin); + addExternalFun("float", "time", "(float a1)", (void *)_time); + addExternalFun("float", "triangle", "(float a1)", (void *)_triangle); + addExternalFun("uint8_t", "beatSin8", "(uint8_t a1, uint8_t a2, uint8_t a3)", (void *)_beatSin8); // added by StarBase addExternalFun("void", "pinMode", "(int a1, int a2)", (void *)&pinMode); @@ -173,10 +193,13 @@ class UserModLive:public SysModule { addExternalFun("CRGB", "hsv", "(int a1, int a2, int a3)", (void *)POSV); addExternalFun("uint8_t", "sin8","(uint8_t a1)",(void*)_sin8); //using int here causes value must be between 0 and 16 error!!! addExternalFun("void", "sPC", "(int a0, int a1, CRGB a2)", (void *)sPCLive); // int t needed - otherwise wrong colors, very strange + addExternalFun("void", "sCFP", "(uint16_t pixel, uint8_t index, uint8_t brightness)", (void *)sCFPLive); + addExternalFun("void", "fadeToBlackBy", "(uint8_t a1)", (void *)_fadeToBlackBy); //address of overloaded function with no contextual type information: setPixelColorLive //ISO C++ forbids taking the address of a bound member function to form a pointer to member function. Say '&LedsLayer::setPixelColorLive' [-fpermissive] //converting from 'void (LedsLayer::*)(uint16_t, uint32_t)' {aka 'void (LedsLayer::*)(short unsigned int, unsigned int)'} to 'void*' [-Wpmf-conversions] addExternalVal("uint8_t", "slider1", &slider1); //used in map function + addExternalVal("uint8_t", "slider2", &slider2); //used in map function //End LEDS specific