# 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++;

// not too fast
delay(40);

// change the colour
hue++;

}
}
``````

guidance or direction is appreciated!

output