Controls:

Hold Left Mouse Button = Randomly change the diameter and step distance of the agents in a subtle way.

Hold Middle Mouse Button = Randomly change the diameter and step distance of the agents in a dramatic way.

Press Left Arrow Key = Set agent amount to 10.

Press Right Arrow Key = Set agent amount to 100.

Press Up Arrow Key = Set alpha to 10%.

Press Down Arrow Key = Set alpha to 100%.

Mix & match these configurations to get different animations.


The purpose of this project is to allow the student to get an understanding of the concepts of agents. To begin with, the agent must have a set of probabilities of directions of which they can move to. Those array of probabilities are then called out as a variable with randomised parameter values to be used to determine the directions of the agents. For instance, the global variable let optionsX = [-1, -1, 1, 1, 1, 1]; describes the agents having a 4/6 (66.67%) chance of moving to the right.

Link to Full Codes

                        for (let i = 0; i < objAmt; i++) {
                            //Choose a value from each array:
                            let randomPosX = floor(random(0, optionsX.length));
                            let randomPosY = floor(random(0, optionsY.length));
                        
                            // Move the Objects:
                            xPos += optionsX[randomPosX] * stepSize;
                            yPos += optionsY[randomPosY] * stepSize;
                        
                            // If objects is greater than the width & height, transfer objects to the appropriate opposite sides of canvas borders (and vice versa).  
                            xPos > width ? xPos = 0 : null; 
                            xPos < 0 ? xPos = width : null; 
                            yPos > height ? yPos = 0 : null;
                            yPos < 0 ? yPos = height : null;
                    
                            // Additional Probability Function (50/50) - To Draw Objects.
                            let randomNum = round(random(0, 1));
                            if (randomNum == 0) {
                                noStroke();
                                fill(17, 100, 100); // Blue-Green Fill
                                ellipse(xPos, yPos, diameter, diameter);
                            } else {
                                noFill();
                                strokeWeight(2);
                                stroke(277, 100, 100); // Red Stroke
                                ellipse(xPos, yPos, diameter, diameter);
                            }
                        
                            // Interactions with Mouse Keys:
                            if (mouseIsPressed) {
                                if (mouseButton === LEFT) {
                                    stepSize = random(20, 50);
                                    diameter = random(10, 20);
                                }
                            
                                if (mouseButton === CENTER) {
                                    stepSize = 60;
                                    diameter = random(20, 90);
                                }
                            }
                        }