Skip to content

Instantly share code, notes, and snippets.

@fangel
Created July 26, 2014 12:37
Show Gist options
  • Save fangel/094ee09dcb9778ff10ae to your computer and use it in GitHub Desktop.
Save fangel/094ee09dcb9778ff10ae to your computer and use it in GitHub Desktop.
int leds = 25;
int _rows = 3;
int _size = 25;
int _spacing = 5;
int round = 0;
float speed_r = 1.0;
float speed_g = 1.5;
void setup() {
size((_spacing+_size)*leds + _spacing, (_spacing+_size)*_rows + _spacing);
ellipseMode(CORNER);
for(int i=0; i < leds; i++) {
for (int j=0; j < _rows; j++) {
ellipse(_spacing+i*(_size+_spacing), _spacing + j*(_size+_spacing), _size, _size);
}
}
}
void setColor(int offset, int row, int r, int g, int b) {
fill(r, g, b);
ellipse(_spacing+offset*(_size+_spacing), _spacing+row*(_size+_spacing), _size, _size);
}
void draw() {
float x;
for(int i=0; i < leds; i++) {
float intensity_r = (sin(((i + round*speed_r) % leds)/2) + 1) / 2.0;
float intensity_g = (sin(((i + round*speed_g) % leds)) + 1) / 2.0;
setColor(i, 0, floor(intensity_r * 155)+100, 0, 0);
setColor(i, 1, floor(intensity_g * 155)+100, 0, 0);
//setColor(i, 2, floor((intensity_r+intensity_g)/2.0 * 155)+100, 0, 0);
// setColor(i, floor(intensity_r * 155)+100, floor(intensity_g * 155)+100, 0);
}
round += 1;
delay(250);
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment