The Dance Floor
Lab 04 · A grid of dancers that react to the mouse in p5.js.
Notes
Move the mouse across the dance floor and watch the dancers react!
- Move the mouse left and right — changes how many columns of dancers are on the floor.
- Dancers close to the mouse dance faster, get bigger, and turn into a dancing piece of bread; dancers far away slow down, shrink, and fade.
What I added
-
Speed from the mouse:
dist()measures how far each dancer is from the mouse.map()uses that distance to change the dancer’s speed: close dancers go faster, far ones slower. - New dancers: I added a 4-frame jump dancer and a 6-frame bread.
-
Bug fix:
getFrameIndex()always used the global 8-poseframes, so I added aframestogetFrameIndex(frames, speed), so each dancer loops through its own poses. I also check that the mouse is inside the canvas.
Bonus
- Distance for more than speed: the distance to the mouse sets each dancer’s speed, size, and transparency. Close dancers are faster, bigger, and solid; far ones are slower, smaller, and faded.
- Distance picks the dance: dancers within 150 pixels of the mouse turn into bread; the rest keep the dance/jump checkerboard.
- A third dance: a 6-frame dancing bread.
The git repo: Lab04