Skip to content

Commit 2f4e862

Browse files
authored
updated to ES6 in es
1 parent c6ebfce commit 2f4e862

File tree

1 file changed

+15
-17
lines changed

1 file changed

+15
-17
lines changed
Lines changed: 15 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
1-
/*
1+
/**
22
* @name Graphing 2D Equations
33
* @frame 710, 400
4-
* @description Graphics the following equation: sin(n*cos(r) + 5*theta) where n is a function of horizontal mouse location. Original by Daniel Shiffman
4+
* @description Graphics the following equation: sin(n*cos(r) + 5*theta) where n is a function of horizontal mouse location. Original by Daniel Shiffman
55
*/
66
function setup() {
77
createCanvas(710, 400);
@@ -10,17 +10,17 @@ function setup() {
1010

1111
function draw() {
1212
loadPixels();
13-
var n = (mouseX * 10.0) / width;
14-
var w = 16.0; // 2D space width
15-
var h = 16.0; // 2D space height
16-
var dx = w / width; // Increment x this amount per pixel
17-
var dy = h / height; // Increment y this amount per pixel
18-
var x = -w / 2; // Start x at -1 * width / 2
19-
var y;
13+
let n = (mouseX * 10.0) / width;
14+
const w = 16.0; // 2D space width
15+
const h = 16.0; // 2D space height
16+
const dx = w / width; // Increment x this amount per pixel
17+
const dy = h / height; // Increment y this amount per pixel
18+
let x = -w / 2; // Start x at -1 * width / 2
19+
let y;
2020

21-
var r;
22-
var theta;
23-
var val;
21+
let r;
22+
let theta;
23+
let val;
2424

2525
let bw; //variable to store grayscale
2626
let i;
@@ -30,25 +30,23 @@ function draw() {
3030

3131
for (i = 0; i < cols; i += 1) {
3232
y = -h / 2;
33-
3433
for (j = 0; j < rows; j += 1) {
35-
r = sqrt((x * x) + (y * y)); // Convert cartesian to polar
34+
r = sqrt(x * x + y * y); // Convert cartesian to polar
3635
theta = atan2(y, x); // Convert cartesian to polar
3736
// Compute 2D polar coordinate function
3837
val = sin(n * cos(r) + 5 * theta); // Results in a value between -1 and 1
3938
//var val = cos(r); // Another simple function
4039
//var val = sin(theta); // Another simple function
4140
bw = color(((val + 1) * 255) / 2);
4241
index = 4 * (i + j * width);
43-
pixels[index] = red(bw);
42+
pixels[index] = red(bw);
4443
pixels[index + 1] = green(bw);
4544
pixels[index + 2] = blue(bw);
4645
pixels[index + 3] = alpha(bw);
4746

4847
y += dy;
4948
}
50-
5149
x += dx;
5250
}
5351
updatePixels();
54-
}
52+
}

0 commit comments

Comments
 (0)