├── README.md ├── circles_intersect_noise.pde ├── Timer.pde └── Ball.pde /README.md: -------------------------------------------------------------------------------- 1 | # circles-intersect-noise 2 | Intersecting circles that produce noise and colors. 3 | -------------------------------------------------------------------------------- /circles_intersect_noise.pde: -------------------------------------------------------------------------------- 1 | import processing.sound.*; 2 | Ball ball1; 3 | Ball ball2; 4 | Timer timer; 5 | WhiteNoise noise; 6 | 7 | void setup() { 8 | size(400, 300); 9 | background(random(155, 255), random(155, 255), random(155, 255)); 10 | noise = new WhiteNoise(this); 11 | ball1 = new Ball(100, 100, 50, 1, 1); 12 | ball2 = new Ball(250, 150, 50, -1, -2); 13 | timer = new Timer(2000); 14 | timer.start(); 15 | } 16 | 17 | void draw() { 18 | if (timer.isFinished()) { 19 | background(random(155, 255), random(155, 255), random(155, 255)); 20 | timer.start(); 21 | } 22 | 23 | ball1.display(); 24 | ball1.move(); 25 | ball1.intersect(ball2); 26 | ball2.display(); 27 | ball2.move(); 28 | } 29 | -------------------------------------------------------------------------------- /Timer.pde: -------------------------------------------------------------------------------- 1 | class Timer { 2 | 3 | int savedTime; // When Timer started 4 | int totalTime; // How long Timer should last 5 | 6 | Timer(int tempTotalTime) { 7 | totalTime = tempTotalTime; 8 | } 9 | 10 | // Starting the timer 11 | void start() { 12 | // When the timer starts it stores the current time in milliseconds. 13 | savedTime = millis(); 14 | } 15 | 16 | // The function isFinished() returns true if 5,000 ms have passed. 17 | // The work of the timer is farmed out to this method. 18 | boolean isFinished() { 19 | // Check how much time has passed 20 | int passedTime = millis() - savedTime; 21 | if (passedTime > totalTime) { 22 | return true; 23 | } else { 24 | return false; 25 | } 26 | } 27 | } 28 | -------------------------------------------------------------------------------- /Ball.pde: -------------------------------------------------------------------------------- 1 | class Ball { 2 | float x; 3 | float y; 4 | float r; 5 | float speedX; 6 | float speedY; 7 | 8 | Ball (float x_, float y_, float r_, float speedX_, float speedY_) { 9 | x = x_; 10 | y = y_; 11 | r = r_; 12 | speedX = speedX_; 13 | speedY = speedY_; 14 | } 15 | 16 | void display() { 17 | ellipseMode(CENTER); 18 | noStroke(); 19 | ellipse(x, y, 2*r, 2*r); 20 | } 21 | 22 | void move() { 23 | x += speedX; 24 | y += speedY; 25 | 26 | if (x == 0 + r || x == width - r) { 27 | speedX *= -1; 28 | } 29 | if (y == 0 + r || y == height - r) { 30 | speedY *= -1; 31 | } 32 | } 33 | 34 | void intersect(Ball b) { 35 | if (dist(x, y, b.x, b.y) < r + b.r) { 36 | fill(random(155, 255), random(155, 255), random(155, 255)); 37 | noise.play(); 38 | } else { 39 | fill(255); 40 | noise.stop(); 41 | } 42 | } 43 | } 44 | --------------------------------------------------------------------------------