Skip to content

Instantly share code, notes, and snippets.

@hpwit
Created December 9, 2018 18:16
Show Gist options
  • Star 1 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save hpwit/5b9df75a0aae6dcb7387e3ea2ae1075f to your computer and use it in GitHub Desktop.
Save hpwit/5b9df75a0aae6dcb7387e3ea2ae1075f to your computer and use it in GitHub Desktop.
CODE FOR ANIMATION
void PixelOn(int x,int y,CRGB Color)
{
if (x<0 or y<0 or x>=LED_WIDTH or y>=LED_HEIGHT)
return ;
if(y%2==0)
leds[x+y*LED_WIDTH]=Color;
else
{
leds[(LED_WIDTH<<1) * ((y >>1) + 1) - 1 - x]=Color;
}
}
long r=0;
void loop()
{
//anim 1
float ab=(float)(r/10)*2*PI/720;
int offx=-LED_WIDTH*(sin(3*ab)+1)/2;
int offy=-LED_HEIGHT*(sin(10*ab)+1)/2;
//these offset are used to have the pattern move around the panel also just a bit more fun. you can change this
for(int x1=1;x1<LED_WIDTH-1;x1++)
for(int y1=0;y1<LED_HEIGHT;y1++)
{
int x=x1+offx;
int y=y1+offy;
int coloor=
(
sin8(x * 9.0)
+ sin8(y *5.0)
+ sin8((x + y) *10.0)
+ sin8(sqrt(double(x * x + y * y)) * 6.0)
) / 4;
PixelOn(x1,y1,CHSV((coloor+r)%256,255,255));
}
r=r+5;
//anim2
for(int x1=1;x1<LED_WIDTH-1;x1++)
for(int y1=0;y1<LED_HEIGHT;y1++)
{
int coloor= int(sin8(sqrt(((x1-(triwave8(r/5) + LED_WIDTH) / 2.0) * (x1-(triwave8(r/5) + LED_WIDTH) / 2.0) + (y1 - LED_HEIGHT / 2.0) * (y1 - LED_HEIGHT / 2.0)) )*5));
PixelOn(x1,y1,CHSV((coloor+r)%256,255,255));
}
r=r+5;
//anim3
float ab=(float)(r/10)*2*PI/720;
int offx=-LED_WIDTH*(sin(3*ab)+1)/2;
int offy=-LED_HEIGHT*(sin(10*ab)+1)/2;
for(int x1=1;x1<LED_WIDTH-1;x1++)
for(int y1=0;y1<LED_HEIGHT;y1++)
{
int x=x1+offx;
int y=y1+offy;
int coloor=(sin8((double)(x)*8 )+ sin8((double)(y)*8)) / 2;
PixelOn(x1,y1,CHSV((coloor+r)%256,255,255));
}
r=r+5;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment