processingObjective.002: collision & reaction

Working with the code used in objective001, add a second object to the space. Program the ball to detect collisions with that object, and react accordingly.

Update: Objective complete.

Notes:

  • The image above does not reflect the final version of the sketch.
  • Though not stipulated by the original objective, the second object (or “paddle”) is interactive, and can be controlled with the mouse cursor.
  • Once the applet loads, click it to allow the mouse to interact.
  • Because of the speed at which the cursor moves the paddle, it was possible for the ball to accidentally pass through the paddle while the paddle was in motion, rather than colliding and bouncing off. To circumvent this issue, I instructed the ball to only interact with the paddle while the paddle was black. Moving the paddle now causes it to turn white, and once the paddle has stopped moving it must “cool down” in order to interact with the ball again. A practical solution, but one that has interesting design potential.
  • Additionally, the paddle had to be instructed to remain white while the ball was passing through it, to prevent a bug where the ball would bounce in the interior of the paddle.
  • The background colors are controlled by the position of the paddle, using the same RGB-calculation code written for objective001. This was done to add a little color to the sketch, which was otherwise a bit boring to look at and play with.

Leave a Reply

Your email address will not be published. Required fields are marked *