diff --git a/misc/ballsSL.sc b/misc/ballsSL.sc new file mode 100644 index 00000000..98ba69bd --- /dev/null +++ b/misc/ballsSL.sc @@ -0,0 +1,155 @@ +import rand +define max_nb_balls 20 +define rmax 4 +define rmin 3 +int nb_balls; +float vx[max_nb_balls]; +float vy[max_nb_balls]; +float xc[max_nb_balls]; +float yc[max_nb_balls]; +float r[max_nb_balls]; +int color[max_nb_balls]; + +//CRGB cc; + +void drawBall(float xc, float yc, float r, int c) +{ + int startx = (float)(xc - r); + int r2 =(float) (r * r); + float r4=r*r*r*r; + // int endx=(float)(xc+r); + int starty = (float)(yc - r); + // int endy=(float)(yc+r); + int _xc=xc; + int _yc=yc; + // CRGB *_leds=leds; + for (int i = startx; i <= _xc; i++) + { + for (int j = starty; j <= _yc; j++) + { + int v; + + int distance = (float)((i - xc) * (i - xc) + (j - yc) * (j - yc)); + + if (distance <= r2) + { + v = (float)(255 * (1 - distance * distance / (r4))); + CRGB cc=hsv(c,255,v); + sPC(0, i + j * panel_width, cc); + // int h=(int)(2 * xc - i) + j * panel_width; + sPC(0, (int)(2 * xc - i) + j * panel_width,cc); + // h=(int)(2 * xc - i) + (int)(2 * yc - j) * panel_widthsdfsdf; + sPC(0, (int)(2 * xc - i) + (int)(2 * yc - j) * panel_width, cc); + // h=i + (int)(2 * yc - j) * panel_width; + sPC(0, i + (int)(2 * yc - j) * panel_width, cc); + } + } + } +} + +void updateBall(int index) +{ + float _r =r[index]; + float _xc = xc[index]; + float _yc = yc[index]; + float _vx = vx[index]; + float _vy = vy[index]; + + _xc = _xc + _vx; + _yc = _yc + _vy; + if ((int)(_xc) >= (int)(width - _r - 1)) + { + _xc =width - _r - 1; + _vx = -_vx; + } + if ((int)(_xc) < (int)(_r + 1)) + { + _xc=_r + 1; + _vx = -_vx; + } + if ((int)(_yc) >= (int)(height - _r - 1)) + { + _yc=height - _r - 1; + _vy = -_vy; + } + if ((int)(_yc) < (int)(_r + 1)) + { + _yc = _r + 1; + _vy = -_vy; + } + + xc[index] = _xc; + yc[index] = _yc; + vx[index] = _vx; + vy[index] = _vy; + int _color = color[index]; + drawBall(_xc, _yc, _r, _color); +} + +void init() +{ + for(int i=0;imax_nb_balls) + { + nb_balls=max_nb_balls; + } + if(nb_balls<=0) + { + nb_balls=1; + } +} + +int h; +void setup() +{ + resetStat(); + //initleds(pins,NUM_STRIPS,NUM_LEDS_PER_STRIP); + init(); + h=0; +} + +void loop() +{ + + for(int i=0;i 0) + { + loop(); + } +} \ No newline at end of file diff --git a/misc/octo.sc b/misc/octoSL.sc similarity index 86% rename from misc/octo.sc rename to misc/octoSL.sc index 6859c6ab..b251e2b1 100644 --- a/misc/octo.sc +++ b/misc/octoSL.sc @@ -2,7 +2,7 @@ //save_reg define PI 3.1415926535 define speed 1 -define nb_branches 5 +int nb_branches; uint8_t C_X ; uint8_t C_Y; uint8_t mapp; @@ -12,6 +12,7 @@ uint32_t t; //=speed void setup() { + t = 0; C_X = width / 2; C_Y = height / 2; mapp = 255 / width; @@ -29,6 +30,8 @@ void setup() void loop() { + nb_branches = slider1 / 25; + // memset(leds, 0, width * height * 3); for (uint8_t x = 0; x < width; x++) { for (uint8_t y = 0; y < height; y++) { @@ -39,7 +42,8 @@ void loop() { // int h=sin8(t*4+sin8(t * 4 - radius)+angle*nb_branches); // leds[y*panel_width+x] = hsv(t + radius, 255, h); - sPC(y*panel_width+x, hsv(t + radius, 255, sin8(t*4+sin8(t * 4 - radius)+angle*nb_branches))); + CRGB gg = hsv(t + radius, 255, sin8(t*4+sin8(t * 4 - radius)+angle*nb_branches)); + sPC(t, y*panel_width+x, gg); } } t=t+speed; diff --git a/src/App/LedEffects.h b/src/App/LedEffects.h index 7807c90c..881f13ca 100644 --- a/src/App/LedEffects.h +++ b/src/App/LedEffects.h @@ -2981,6 +2981,9 @@ class LiveScriptEffect: public Effect { return true; } default: return false; }}); //script + + ui->initSlider(parentVar, "Slider1", &slider1); + } }; diff --git a/src/User/UserModLive.h b/src/User/UserModLive.h index 4dc14de1..f3bb030a 100644 --- a/src/User/UserModLive.h +++ b/src/User/UserModLive.h @@ -82,13 +82,15 @@ static float _sin(float j) {return sin(j);} static CRGB POSV(uint8_t h, uint8_t s, uint8_t v) {return CHSV(h, s, v);} static uint8_t _sin8(uint8_t a) {return sin8(a);} static LedsLayer *gLeds = nullptr; -static void sPCLive(uint16_t pixel, CRGB color) { - // if (pixel == 0) ppf("."); - // if (pixel < 10) - // ppf(" %d <- %d-%d-%d", pixel, color.r, color.g, color.b); - // gLeds->setPixelColor(pixel, CRGB(random8(), random8(), random8())); - if (gLeds) gLeds->setPixelColor(pixel, color); +static void sPCLive(int t, uint16_t pixel, CRGB color) { // 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, color); + } } +uint8_t slider1 = 10; + //End LEDS specific class UserModLive:public SysModule { @@ -170,10 +172,11 @@ class UserModLive:public SysModule { //LEDS specific 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 a1, CRGB a2)", (void *)sPCLive); + addExternalFun("void", "sPC", "(int a0, int a1, CRGB a2)", (void *)sPCLive); // int t needed - otherwise wrong colors, very strange //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 //End LEDS specific