Entry 7 – Creating my first Flock composition

Having learned the theoretical background behind flock algorithms in processing, it is time to compose a sketch.

My idea for this sketch was to introduce a little variation from the typical flock algorithm. I wanted there to be a competition between two classes of Agents, the regular agents and another class I decided to call Enemies.

First, there is an additional class called Enemies which uses the inheritance feature of OOP to acquire and expand the capabilities of the regular Agent class:

diagram-5

The separation, alignment and cohesion behaviors follow the same guidelines as explained in my previous entry. But the agent class carries  the addition of a repel method in charge of creating repelling steering of the agents from the enemies:

diagram-4

By having this function take on a different range parameter, I can tailor how close an object has to be to another based on the type. For example, I can have the enemies have a greater influence against the agents along a larger distance. I can also use it to introduce a repel force among the enemies themselves

Finally, I must call on all the functionality of the agents and enemies and apply the repelling method accordingly:

diagram-6

The result is really organic. With the red and green colors, even though we are technically seeing a war between organisms, the forms that are visualized kinda almost give a Christmas feeling.

2039 1317

 

In order to automate the process of acquiring an image from the sketch, I invoked the keyPressed() method  and connected it to an image function which uses the built-in jpeg export saveFrame.

 

diagram-7