Skip to content

Commit c870eb9

Browse files
committed
chore: modify the format of source code for examples/en/09_Simulate/00_Forces
1 parent 82a4c23 commit c870eb9

File tree

1 file changed

+17
-24
lines changed

1 file changed

+17
-24
lines changed

src/data/examples/en/09_Simulate/00_Forces.js

Lines changed: 17 additions & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -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-
5552
function mousePressed() {
5653
reset();
5754
}
@@ -63,7 +60,7 @@ function reset() {
6360
}
6461
}
6562

66-
let Liquid = function(x, y, w, h, c) {
63+
let Liquid = function (x, y, w, h, c) {
6764
this.x = x;
6865
this.y = y;
6966
this.w = w;
@@ -72,14 +69,18 @@ let Liquid = function(x, y, w, h, c) {
7269
};
7370

7471
// Is the Mover in the Liquid?
75-
Liquid.prototype.contains = function(m) {
72+
Liquid.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
82-
Liquid.prototype.calculateDrag = function(m) {
83+
Liquid.prototype.calculateDrag = function (m) {
8384
// Magnitude is coefficient * speed squared
8485
let speed = m.velocity.mag();
8586
let dragMagnitude = this.c * speed * speed;
@@ -95,7 +96,7 @@ Liquid.prototype.calculateDrag = function(m) {
9596
return dragForce;
9697
};
9798

98-
Liquid.prototype.display = function() {
99+
Liquid.prototype.display = function () {
99100
noStroke();
100101
fill(50);
101102
rect(this.x, this.y, this.w, this.h);
@@ -110,12 +111,12 @@ function Mover(m, x, y) {
110111

111112
// Newton's 2nd law: F = M * A
112113
// or A = F / M
113-
Mover.prototype.applyForce = function(force) {
114+
Mover.prototype.applyForce = function (force) {
114115
let f = p5.Vector.div(force, this.mass);
115116
this.acceleration.add(f);
116117
};
117118

118-
Mover.prototype.update = function() {
119+
Mover.prototype.update = function () {
119120
// Velocity changes according to acceleration
120121
this.velocity.add(this.acceleration);
121122
// position changes by velocity
@@ -124,26 +125,18 @@ Mover.prototype.update = function() {
124125
this.acceleration.mult(0);
125126
};
126127

127-
Mover.prototype.display = function() {
128+
Mover.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
135-
Mover.prototype.checkEdges = function() {
136-
if (this.position.y > (height - this.mass * 8)) {
136+
Mover.prototype.checkEdges = function () {
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

Comments
 (0)