Skip to content

Commit 5b0becd

Browse files
Perfect pass on ESlint
Fixed spacing, line end, etc. and a couple more var to let.
1 parent f6695e2 commit 5b0becd

17 files changed

+221
-217
lines changed

src/data/examples/zh-Hans/08_Math/00_incrementdecrement.js

Lines changed: 9 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -18,25 +18,25 @@ function setup() {
1818

1919
function draw() {
2020
a++;
21-
if(a > width) {
21+
if (a > width) {
2222
a = 0;
2323
direction = !direction;
2424
}
25-
if(direction == true){
25+
if (direction === true) {
2626
stroke(a);
2727
} else {
28-
stroke(width-a);
28+
stroke(width - a);
2929
}
30-
line(a, 0, a, height/2);
30+
line(a, 0, a, height / 2);
3131

3232
b--;
33-
if(b < 0) {
33+
if (b < 0) {
3434
b = width;
3535
}
36-
if(direction == true) {
37-
stroke(width-b);
36+
if (direction === true) {
37+
stroke(width - b);
3838
} else {
3939
stroke(b);
4040
}
41-
line(b, height/2+1, b, height);
42-
}
41+
line(b, height / 2 + 1, b, height);
42+
}

src/data/examples/zh-Hans/08_Math/01_operatorprecedence.js

Lines changed: 10 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
/*
22
* @name Operator Precedence
33
* @description If you don't explicitly state the order in which an
4-
* expression is evaluated, they are evaluated based on the operator
4+
* expression is evaluated, they are evaluated based on the operator
55
* precedence. For example, in the statement "4+2*8", the 2 will
66
* first be multiplied by 8 and then the result will be added to 4.
77
* This is because the "*" has a higher precedence than the "+". To avoid
@@ -10,7 +10,7 @@
1010
* through placement of parenthesis in the code. A table of operator
1111
* precedence follows below.
1212
*/
13-
// The highest precedence is at the top of the list and
13+
// The highest precedence is at the top of the list and
1414
// the lowest is at the bottom.
1515
// Multiplicative: * / %
1616
// Additive: + -
@@ -26,7 +26,7 @@ function setup() {
2626
stroke(51);
2727

2828
stroke(204);
29-
for(let i=0; i< width-20; i+= 4) {
29+
for (let i = 0; i < width - 20; i += 4) {
3030
// The 30 is added to 70 and then evaluated
3131
// if it is greater than the current value of "i"
3232
// For clarity, write as "if (i > (30 + 70)) {"
@@ -42,14 +42,13 @@ function setup() {
4242
rect((4 + 2) * 8, 100, 290, 49);
4343

4444
stroke(153);
45-
for (let i = 0; i < width; i+= 2) {
46-
// The relational statements are evaluated
47-
// first, and then the logical AND statements and
45+
for (let i = 0; i < width; i += 2) {
46+
// The relational statements are evaluated
47+
// first, and then the logical AND statements and
4848
// finally the logical OR. For clarity, write as:
4949
// "if(((i > 20) && (i < 50)) || ((i > 100) && (i < width-20))) {"
50-
if (i > 20 && i < 50 || i > 100 && i < width-20) {
51-
line(i, 151, i, height-1);
52-
}
50+
if ((i > 20 && i < 50) || (i > 100 && i < width - 20)) {
51+
line(i, 151, i, height - 1);
52+
}
5353
}
54-
55-
}
54+
}

src/data/examples/zh-Hans/08_Math/02_distance1d.js

Lines changed: 41 additions & 25 deletions
Original file line numberDiff line numberDiff line change
@@ -13,37 +13,53 @@ let thick = 36;
1313
function setup() {
1414
createCanvas(710, 400);
1515
noStroke();
16-
xpos1 = width/2;
17-
xpos2 = width/2;
18-
xpos3 = width/2;
19-
xpos4 = width/2;
16+
xpos1 = width / 2;
17+
xpos2 = width / 2;
18+
xpos3 = width / 2;
19+
xpos4 = width / 2;
2020
}
2121

2222
function draw() {
2323
background(0);
24-
25-
let mx = mouseX * 0.4 - width/5.0;
26-
24+
25+
let mx = mouseX * 0.4 - width / 5.0;
26+
2727
fill(102);
28-
rect(xpos2, 0, thick, height/2);
28+
rect(xpos2, 0, thick, height / 2);
2929
fill(204);
30-
rect(xpos1, 0, thin, height/2);
30+
rect(xpos1, 0, thin, height / 2);
3131
fill(102);
32-
rect(xpos4, height/2, thick, height/2);
32+
rect(xpos4, height / 2, thick, height / 2);
3333
fill(204);
34-
rect(xpos3, height/2, thin, height/2);
35-
36-
xpos1 += mx/16;
37-
xpos2 += mx/64;
38-
xpos3 -= mx/16;
39-
xpos4 -= mx/64;
40-
41-
if(xpos1 < -thin) { xpos1 = width; }
42-
if(xpos1 > width) { xpos1 = -thin; }
43-
if(xpos2 < -thick) { xpos2 = width; }
44-
if(xpos2 > width) { xpos2 = -thick; }
45-
if(xpos3 < -thin) { xpos3 = width; }
46-
if(xpos3 > width) { xpos3 = -thin; }
47-
if(xpos4 < -thick) { xpos4 = width; }
48-
if(xpos4 > width) { xpos4 = -thick; }
34+
rect(xpos3, height / 2, thin, height / 2);
35+
36+
xpos1 += mx / 16;
37+
xpos2 += mx / 64;
38+
xpos3 -= mx / 16;
39+
xpos4 -= mx / 64;
40+
41+
if (xpos1 < -thin) {
42+
xpos1 = width;
43+
}
44+
if (xpos1 > width) {
45+
xpos1 = -thin;
46+
}
47+
if (xpos2 < -thick) {
48+
xpos2 = width;
49+
}
50+
if (xpos2 > width) {
51+
xpos2 = -thick;
52+
}
53+
if (xpos3 < -thin) {
54+
xpos3 = width;
55+
}
56+
if (xpos3 > width) {
57+
xpos3 = -thin;
58+
}
59+
if (xpos4 < -thick) {
60+
xpos4 = width;
61+
}
62+
if (xpos4 > width) {
63+
xpos4 = -thick;
64+
}
4965
}

src/data/examples/zh-Hans/08_Math/03_distance2d.js

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
/*
22
* @name Distance 2D
3-
* @description Move the mouse across the image to obscure
3+
* @description Move the mouse across the image to obscure
44
* and reveal the matrix. Measures the distance from the mouse
55
* to each square and sets the size proportionally.
66
*/
@@ -15,11 +15,11 @@ function setup() {
1515
function draw() {
1616
background(0);
1717

18-
for(let i = 0; i <= width; i += 20) {
19-
for(let j = 0; j <= height; j += 20) {
20-
var size = dist(mouseX, mouseY, i, j);
21-
size = size/max_distance * 66;
18+
for (let i = 0; i <= width; i += 20) {
19+
for (let j = 0; j <= height; j += 20) {
20+
let size = dist(mouseX, mouseY, i, j);
21+
size = (size / max_distance) * 66;
2222
ellipse(i, j, size, size);
2323
}
2424
}
25-
}
25+
}

src/data/examples/zh-Hans/08_Math/04_sine.js

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -15,13 +15,13 @@ function setup() {
1515
function draw() {
1616
background(0);
1717

18-
let d1 = 10 + (sin(angle) * diameter/2) + diameter/2;
19-
let d2 = 10 + (sin(angle + PI/2) * diameter/2) + diameter/2;
20-
let d3 = 10 + (sin(angle + PI) * diameter/2) + diameter/2;
21-
22-
ellipse(0, height/2, d1, d1);
23-
ellipse(width/2, height/2, d2, d2);
24-
ellipse(width, height/2, d3, d3);
25-
18+
let d1 = 10 + (sin(angle) * diameter) / 2 + diameter / 2;
19+
let d2 = 10 + (sin(angle + PI / 2) * diameter) / 2 + diameter / 2;
20+
let d3 = 10 + (sin(angle + PI) * diameter) / 2 + diameter / 2;
21+
22+
ellipse(0, height / 2, d1, d1);
23+
ellipse(width / 2, height / 2, d2, d2);
24+
ellipse(width, height / 2, d3, d3);
25+
2626
angle += 0.02;
2727
}
Lines changed: 16 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,12 @@
11
/*
22
* @name Sine Cosine
3-
* @description Linear movement with sin() and cos().
3+
* @description Linear movement with sin() and cos().
44
* Numbers between 0 and PI*2 (TWO_PI which angles roughly 6.28)
55
* are put into these functions and numbers between -1 and 1 are returned.
66
* These values are then scaled to produce larger movements.
77
*/
8-
let angle1=0;
9-
let angle2=0;
8+
let angle1 = 0;
9+
let angle2 = 0;
1010
let scalar = 70;
1111

1212
function setup() {
@@ -21,23 +21,23 @@ function draw() {
2121
let ang1 = radians(angle1);
2222
let ang2 = radians(angle2);
2323

24-
let x1 = width/2 + (scalar * cos(ang1));
25-
let x2 = width/2 + (scalar * cos(ang2));
26-
27-
let y1 = height/2 + (scalar * sin(ang1));
28-
let y2 = height/2 + (scalar * sin(ang2));
29-
24+
let x1 = width / 2 + scalar * cos(ang1);
25+
let x2 = width / 2 + scalar * cos(ang2);
26+
27+
let y1 = height / 2 + scalar * sin(ang1);
28+
let y2 = height / 2 + scalar * sin(ang2);
29+
3030
fill(255);
31-
rect(width*0.5, height*0.5, 140, 140);
31+
rect(width * 0.5, height * 0.5, 140, 140);
3232

3333
fill(0, 102, 153);
34-
ellipse(x1, height*0.5 - 120, scalar, scalar);
35-
ellipse(x2, height*0.5 + 120, scalar, scalar);
36-
34+
ellipse(x1, height * 0.5 - 120, scalar, scalar);
35+
ellipse(x2, height * 0.5 + 120, scalar, scalar);
36+
3737
fill(255, 204, 0);
38-
ellipse(width*0.5 - 120, y1, scalar, scalar);
39-
ellipse(width*0.5 + 120, y2, scalar, scalar);
38+
ellipse(width * 0.5 - 120, y1, scalar, scalar);
39+
ellipse(width * 0.5 + 120, y2, scalar, scalar);
4040

4141
angle1 += 2;
42-
angle2 += 3;
42+
angle2 += 3;
4343
}

src/data/examples/zh-Hans/08_Math/06_sinewave.js

Lines changed: 15 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -4,19 +4,19 @@
44
* Original by Daniel Shiffman.
55
*/
66

7-
let xspacing = 16; // Distance between each horizontal location
8-
let w; // Width of entire wave
9-
let theta = 0.0; // Start angle at 0
7+
let xspacing = 16; // Distance between each horizontal location
8+
let w; // Width of entire wave
9+
let theta = 0.0; // Start angle at 0
1010
let amplitude = 75.0; // Height of wave
11-
let period = 500.0; // How many pixels before the wave repeats
12-
let dx; // Value for incrementing x
13-
let yvalues; // Using an array to store height values for the wave
11+
let period = 500.0; // How many pixels before the wave repeats
12+
let dx; // Value for incrementing x
13+
let yvalues; // Using an array to store height values for the wave
1414

1515
function setup() {
1616
createCanvas(710, 400);
17-
w = width+16;
17+
w = width + 16;
1818
dx = (TWO_PI / period) * xspacing;
19-
yvalues = new Array(floor(w/xspacing));
19+
yvalues = new Array(floor(w / xspacing));
2020
}
2121

2222
function draw() {
@@ -26,23 +26,23 @@ function draw() {
2626
}
2727

2828
function calcWave() {
29-
// Increment theta (try different values for
29+
// Increment theta (try different values for
3030
// 'angular velocity' here)
3131
theta += 0.02;
3232

3333
// For every x value, calculate a y value with sine function
34-
var x = theta;
35-
for (var i = 0; i < yvalues.length; i++) {
36-
yvalues[i] = sin(x)*amplitude;
37-
x+=dx;
34+
let x = theta;
35+
for (let i = 0; i < yvalues.length; i++) {
36+
yvalues[i] = sin(x) * amplitude;
37+
x += dx;
3838
}
3939
}
4040

4141
function renderWave() {
4242
noStroke();
4343
fill(255);
4444
// A simple way to draw the wave with an ellipse at each location
45-
for (var x = 0; x < yvalues.length; x++) {
46-
ellipse(x*xspacing, height/2+yvalues[x], 16, 16);
45+
for (let x = 0; x < yvalues.length; x++) {
46+
ellipse(x * xspacing, height / 2 + yvalues[x], 16, 16);
4747
}
4848
}

src/data/examples/zh-Hans/08_Math/07_additivewave.js

Lines changed: 14 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -3,13 +3,13 @@
33
* @description Create a more complex wave by adding two waves together.
44
* Original by Daniel Shiffman
55
*/
6-
let xspacing = 8; // Distance between each horizontal location
7-
let w; // Width of entire wave
8-
let maxwaves = 4; // total # of waves to add together
6+
let xspacing = 8; // Distance between each horizontal location
7+
let w; // Width of entire wave
8+
let maxwaves = 4; // total # of waves to add together
99

1010
let theta = 0.0;
11-
let amplitude = new Array(maxwaves); // Height of wave
12-
// Value for incrementing X, to be calculated
11+
let amplitude = new Array(maxwaves); // Height of wave
12+
// Value for incrementing X, to be calculated
1313
// as a function of period and xspacing
1414
let dx = new Array(maxwaves);
1515
// Using an array to store height values
@@ -23,12 +23,12 @@ function setup() {
2323
w = width + 16;
2424

2525
for (let i = 0; i < maxwaves; i++) {
26-
amplitude[i] = random(10,30);
27-
let period = random(100,300); // Num pixels before wave repeats
26+
amplitude[i] = random(10, 30);
27+
let period = random(100, 300); // Num pixels before wave repeats
2828
dx[i] = (TWO_PI / period) * xspacing;
2929
}
3030

31-
yvalues = new Array(floor(w/xspacing));
31+
yvalues = new Array(floor(w / xspacing));
3232
}
3333

3434
function draw() {
@@ -38,7 +38,7 @@ function draw() {
3838
}
3939

4040
function calcWave() {
41-
// Increment theta (try different values
41+
// Increment theta (try different values
4242
// for 'angular velocity' here
4343
theta += 0.02;
4444

@@ -52,19 +52,19 @@ function calcWave() {
5252
let x = theta;
5353
for (let i = 0; i < yvalues.length; i++) {
5454
// Every other wave is cosine instead of sine
55-
if (j % 2 == 0) yvalues[i] += sin(x)*amplitude[j];
56-
else yvalues[i] += cos(x)*amplitude[j];
57-
x+=dx[j];
55+
if (j % 2 === 0) yvalues[i] += sin(x) * amplitude[j];
56+
else yvalues[i] += cos(x) * amplitude[j];
57+
x += dx[j];
5858
}
5959
}
6060
}
6161

6262
function renderWave() {
6363
// A simple way to draw the wave with an ellipse at each location
6464
noStroke();
65-
fill(255,50);
65+
fill(255, 50);
6666
ellipseMode(CENTER);
6767
for (let x = 0; x < yvalues.length; x++) {
68-
ellipse(x*xspacing,width/2+yvalues[x],16,16);
68+
ellipse(x * xspacing, width / 2 + yvalues[x], 16, 16);
6969
}
7070
}

0 commit comments

Comments
 (0)