How to color one object in an ArrayList?

Hey everyone,

after searching through the internet i really couldn’t find a proper answer so i a make this post. I am currently working through the flocking expample of daniel shiffmann and i would love to finally know, how to change the color of a single object in the arraylist, without coloring the other objects in the list.
its quite some code, so i just post the link to it and hope you can help me:
https://processing.org/examples/flocking.html

1 Like

Hello,

and welcome to this great forum!

1.

make a var

color col = color(255); // white

in the class Boid and use it there with stroke(col); in render()

2.

in setup say at its end:

flock.boids.get(5).col = color(255,0,0); // red

This means we set the color of #5 to red.

or so

Chrisir

3 Likes

Hey Chris, thank you so much for the quick and straight forward answer! it worked perfectly!

1 Like