9
9
// Bodies experience gravity continuously
10
10
// Bodies experience fluid resistance when in "water"
11
11
12
- // Five moving bodies
12
+ // Nine moving bodies
13
13
let movers = [ ] ;
14
14
15
15
// Liquid
@@ -29,7 +29,6 @@ function draw() {
29
29
liquid . display ( ) ;
30
30
31
31
for ( let i = 0 ; i < movers . length ; i ++ ) {
32
-
33
32
// Is the Mover in the liquid?
34
33
if ( liquid . contains ( movers [ i ] ) ) {
35
34
// Calculate drag force
@@ -48,10 +47,8 @@ function draw() {
48
47
movers [ i ] . display ( ) ;
49
48
movers [ i ] . checkEdges ( ) ;
50
49
}
51
-
52
50
}
53
51
54
-
55
52
function mousePressed ( ) {
56
53
reset ( ) ;
57
54
}
@@ -74,8 +71,12 @@ let Liquid = function(x, y, w, h, c) {
74
71
// Is the Mover in the Liquid?
75
72
Liquid . prototype . contains = function ( m ) {
76
73
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
+ ) ;
79
80
} ;
80
81
81
82
// Calculate drag force
@@ -127,23 +128,15 @@ Mover.prototype.update = function() {
127
128
Mover . prototype . display = function ( ) {
128
129
stroke ( 0 ) ;
129
130
strokeWeight ( 2 ) ;
130
- fill ( 255 , 127 ) ;
131
+ fill ( 255 , 127 ) ;
131
132
ellipse ( this . position . x , this . position . y , this . mass * 16 , this . mass * 16 ) ;
132
133
} ;
133
134
134
135
// Bounce off bottom of window
135
136
Mover . prototype . checkEdges = function ( ) {
136
- if ( this . position . y > ( height - this . mass * 8 ) ) {
137
+ if ( this . position . y > height - this . mass * 8 ) {
137
138
// A little dampening when hitting the bottom
138
139
this . velocity . y *= - 0.9 ;
139
- this . position . y = ( height - this . mass * 8 ) ;
140
+ this . position . y = height - this . mass * 8 ;
140
141
}
141
142
} ;
142
-
143
-
144
-
145
-
146
-
147
-
148
-
149
-
0 commit comments