99// Bodies experience gravity continuously
1010// Bodies experience fluid resistance when in "water"
1111
12- // Five moving bodies
12+ // Nine moving bodies
1313let movers = [ ] ;
1414
1515// Liquid
@@ -29,7 +29,6 @@ function draw() {
2929 liquid . display ( ) ;
3030
3131 for ( let i = 0 ; i < movers . length ; i ++ ) {
32-
3332 // Is the Mover in the liquid?
3433 if ( liquid . contains ( movers [ i ] ) ) {
3534 // Calculate drag force
@@ -48,10 +47,8 @@ function draw() {
4847 movers [ i ] . display ( ) ;
4948 movers [ i ] . checkEdges ( ) ;
5049 }
51-
5250}
5351
54-
5552function mousePressed ( ) {
5653 reset ( ) ;
5754}
@@ -74,8 +71,12 @@ let Liquid = function(x, y, w, h, c) {
7471// Is the Mover in the Liquid?
7572Liquid . prototype . contains = function ( m ) {
7673 let l = m . position ;
77- return l . x > this . x && l . x < this . x + this . w &&
78- l . y > this . y && l . y < this . y + this . h ;
74+ return (
75+ l . x > this . x &&
76+ l . x < this . x + this . w &&
77+ l . y > this . y &&
78+ l . y < this . y + this . h
79+ ) ;
7980} ;
8081
8182// Calculate drag force
@@ -127,23 +128,15 @@ Mover.prototype.update = function() {
127128Mover . prototype . display = function ( ) {
128129 stroke ( 0 ) ;
129130 strokeWeight ( 2 ) ;
130- fill ( 255 , 127 ) ;
131+ fill ( 255 , 127 ) ;
131132 ellipse ( this . position . x , this . position . y , this . mass * 16 , this . mass * 16 ) ;
132133} ;
133134
134135// Bounce off bottom of window
135136Mover . prototype . checkEdges = function ( ) {
136- if ( this . position . y > ( height - this . mass * 8 ) ) {
137+ if ( this . position . y > height - this . mass * 8 ) {
137138 // A little dampening when hitting the bottom
138139 this . velocity . y *= - 0.9 ;
139- this . position . y = ( height - this . mass * 8 ) ;
140+ this . position . y = height - this . mass * 8 ;
140141 }
141142} ;
142-
143-
144-
145-
146-
147-
148-
149-
0 commit comments