flocking leds!

yes, and not a spelling mistake!

i have a 16x16 light panel, and I’ve got leds flashing no issue… but i have an idea in my head and i want to get it to panel.

im trying to create an “organic” motion, like when birds are “flocking”… many many birds following a leader, in a haphazard, but fluid motion.

so, imagine a grid,

0>15 width, 0>15 height. for e.g. middle of the grid is 7, 7.

i would like to generate a path for the LEADER, and he will move from the centre bottom, 0, 7 to middle 7, 7, then off to the right, 16, 7.

thats the easy bit, array of the relevant leds, and flash in sequence.

the hard bit, is that i would like to create a collection of following leds that follow this line, but move in the general direction, but with circular / curvy motion, and if there are 15 followers, they all follow a slightly different randomised movement.

now using simple code, i have something that is singular, as in i can highlight one led, have a trail and move it, but im not sure how to have multiple leds on at the same time.

void centreToPoint () {
  x2=(width-1)/2; //  start position centre
  y2=(height-1)/2; // start position centre
  x1=random8(width-1); // end position random width
  y1=random8(height-1); // end position random height
  
  constraints(); // stop crashing by checking x/y and constraining

  while (x2!=x1 || y2!=y1) {
  
  dot1 = x1+width*y1; // convert xy to led grid
  dot2 = x2+width*y2; // convert xy to led grid

  leds[matrix[dot1]] += CHSV (hue, 255, 255); // show the leds, 
  leds[matrix[dot2]] += CHSV (hue+32, 255, 255);

  FastLED.show();

// move the leds
  if (x2>x1) x2--;
  if (y2>y1) y2--;
  if (x2<x1) x2++;
  if (y2<y1) y2++;

//fade out
  fadeToBlackBy(leds, NUM_LEDS, 16);

// not too fast
  delay(40);

// change the colour
  hue++;
  
}
}

guidance or direction is appreciated!

output

youtube

Look up boids :slight_smile:

Two remarks though : 16x16 is pretty low resolution, so I'm not sure the result would be that interesting, but no way to know before trying, and I don't know if an Arduino will have enough power, but it looks like it's mostly float addition and division, no complexe sin or cos so you should be good as long as you don't need a ridiculous framerate or high number of "birds".

Example processing sketch

(this brings back fun memories of my first dabblings in generative "art" programming almost 12 years ago :slight_smile: )