ICM Week 4: Bouncing (and Disappearing!) Balloons

Published October 03, 2017

This week was a challenge to place all of our p5.js sketch’s functionality within functions defined outside of the main draw loop. My sketch (a variation on the bouncing balloon we made in previous weeks) placed all functionality within ball objects created every time the mouse is clicked.

In addition to the standard functionality (bouncing, moving, drawing), I attempted to add several other features (some successfully, many not).  Please note that the balls are called ‘magnets’ because I originally wanted them to attract and repel based on their N&S poles, but this proved a bit too complicated for this week’s project.

  • WORKS: Every 200 frames, the balls reverse direction,

  • WORKS: When the balls approach their ‘birthplace,’ they disappear (are spliced from the ball array),

  • WORKS: A new ball object is created at mouseX,mouseY when the mouse is clicked,

  • DOES NOT WORK: Repelling function, which would have each ball adjust its speed to avoid other balls,

  • DOES NOT WORK: Gravity (updateSpeed) function, which would update each ball’s yspeed based on a function which mimicked gravity…

Below is the current status of the code:


And the sketch in the editor.