Skip to content

Commit

Permalink
UserModLive: Enabled by default, slider1, sPC
Browse files Browse the repository at this point in the history
Select effect: Live Scripts
Upload one of these files from the repo:
ballsSL : set NUM_LEDS_Max 1024
OctoSL:  works with NUM_LEDS_Max 8192

ballsSL and octoSL: new StarLight versions
- using slider1
- using sPC

LedEffects: LiveScriptEffect: add slider1

LedFixture: set NUM_LEDS_MAX 1024 (max tested) for Live scriptin

UserModLife:
- addExternalVal slider1
- sPCLive: one extra parameter to get right colors
  • Loading branch information
ewoudwijma committed Aug 5, 2024
1 parent 5f4e16c commit 39736a5
Show file tree
Hide file tree
Showing 4 changed files with 174 additions and 9 deletions.
155 changes: 155 additions & 0 deletions misc/ballsSL.sc
Original file line number Diff line number Diff line change
@@ -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;i<max_nb_balls;i++)
{
vx[i] = rand(280)/255+0.7;
vy[i] = rand(280)/255+0.5;
r[i] = (rmax-rmin)*(rand(280)/180) +rmin;
xc[i] = width/2*(rand(280)/255+0.3)+15;
yc[i] = height/2*(rand(280)/255+0.3)+15;

color[i] = rand(255);
}
}
void updateParams()
{
nb_balls=slider1;
if(nb_balls>max_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<width;i++)
{
for(int j=0;j<height;j++)
{
CRGB gg = hsv(i+h+j,255,180);
sPC(0, i+panel_width*j, gg);
}
}

updateParams();
for (int i = 0; i < nb_balls; i++)
{
updateBall(i);
// drawBall(1,1,1,CRGB(255,255,255));
}

show();
h++;
}


void main()
{
setup();
while (2 > 0)
{
loop();
}
}
8 changes: 6 additions & 2 deletions misc/octo.sc → misc/octoSL.sc
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand All @@ -12,6 +12,7 @@ uint32_t t; //=speed

void setup()
{
t = 0;
C_X = width / 2;
C_Y = height / 2;
mapp = 255 / width;
Expand All @@ -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++) {
Expand All @@ -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;
Expand Down
3 changes: 3 additions & 0 deletions src/App/LedEffects.h
Original file line number Diff line number Diff line change
Expand Up @@ -2981,6 +2981,9 @@ class LiveScriptEffect: public Effect {
return true; }
default: return false;
}}); //script

ui->initSlider(parentVar, "Slider1", &slider1);

}
};

Expand Down
17 changes: 10 additions & 7 deletions src/User/UserModLive.h
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand Down Expand Up @@ -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

Expand Down

0 comments on commit 39736a5

Please sign in to comment.