# Week 10: Tut 17

## The Process Compendium (Part 2)

• Show Sketch
``````/** @peep sketchcode **/
int NUM_LARGE_CIRCLES = 3;
int NUM_CIRCLES = 150;

float DELTA_ANGLE = TWO_PI/random(10,40);

Circle[] largeCircles;
Circle[] circles;

void setup() {
size(300, 300);
frameRate(15);
background(random(0,255), random(0,255), random(0,255),random(0,100));
smooth();
largeCircles = new Circle[NUM_LARGE_CIRCLES];
for (int i = 0; i < largeCircles.length; i++) {
largeCircles[i] = new Circle(random(width), random(height), random(0.4*width, 0.6*width));
}
circles = new Circle[NUM_CIRCLES];
for (int i = 0; i < circles.length; i++) {
int r = int(random(NUM_LARGE_CIRCLES)); // Choose a large circle at random
}
}

void update() {
for (int i = 0; i < circles.length; i++) {
circles[i].update();
if (!circles[i].touching(circles[i].parent)) {
circles[i].respawn();
}
}
}

void draw() {
update(); // Update all of the circles
strokeWeight(0.5);
for (int i = 0; i < circles.length; i++) {
// Get a first circle
Circle circle1 = circles[i];
for (int j = i+1; j < circles.length; j++) {
// Get a second circle
Circle circle2 = circles[j];
// If the circles are touching
if (circle1.touching(circle2)) {
// Calculate the grey value using the map function based on the distance between the circles
// Draw a line between the centres of the circles
line(circle1.x, circle1.y, circle2.x, circle2.y);
}
}
}
}

class Circle {
float x;
float y;

float speed;

Circle parent;

parent = _parent;
}

Circle(float _x, float _y, float _radius) {
x = _x;
y = _y;
speed = 1;
parent = null;
}

void respawn() {
if (parent != null) {
x = parent.x;
y = parent.y;
}
}

void draw() {
pushStyle();
noFill();
stroke(0);
strokeWeight(1);
pushMatrix();
translate(x, y);
popMatrix();
stroke(192, 0, 0, 64);
for (int i = 0; i < circles.length; i++) {
Circle other = circles[i];
if (touching(other)) {
line(x, y, other.x, other.y);
}
}
popStyle();
}

void update() {
behaviour1();
behaviour2();
behaviour3();
// behaviour4();
}

void behaviour1() {
// Constant linear motion
float dx = speed * cos(heading);
float dy = speed * sin(heading);
x += dx;
y += dy;
}

void behaviour2() {
// Constrain to surface
}

void behaviour3() {
// While touching another, change direction
for (int i = 0; i < circles.length; i++) {
if (circles[i] != this) {
if (touching(circles[i])) {
}
}
}
}

void behaviour4() {
// While touching another, move away from its centre
for (int i = 0; i < circles; i++) {
if (circles[i] != this) {
if (touching(circles[i])) {
Circle other = circles[i];
float d = distance(other);
float dx = (other.x - x)/d;
float dy = (other.y - y)/d;
x -= speed * dx;
y -= speed * dy;
}
}
}
}

void touching(Circle other) {