Skip to content

Commit cb0f092

Browse files
Converted to ES6 syntax
Updated code for data module.
1 parent b8f0025 commit cb0f092

24 files changed

+291
-250
lines changed
Lines changed: 10 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -1,16 +1,15 @@
11
/*
22
* @name Points and Lines
3-
* @description Points and lines can be used to draw basic geometry.
4-
* Change the value of the variable 'd' to scale the form. The four
3+
* @description Points and lines can be used to draw basic geometry.
4+
* Change the value of the variable 'd' to scale the form. The four
55
* variables set the positions based on the value of 'd'.
66
*/
77
function setup() {
8-
9-
var d = 70;
10-
var p1 = d;
11-
var p2 = p1+d;
12-
var p3 = p2+d;
13-
var p4 = p3+d;
8+
let d = 70;
9+
let p1 = d;
10+
let p2 = p1 + d;
11+
let p3 = p2 + d;
12+
let p4 = p3 + d;
1413

1514
// Sets the screen to be 720 pixels wide and 400 pixels high
1615
createCanvas(720, 400);
@@ -29,9 +28,9 @@ function setup() {
2928
// Draw white points
3029
stroke(255);
3130
point(p1, p1);
32-
point(p1, p3);
31+
point(p1, p3);
3332
point(p2, p4);
34-
point(p3, p1);
33+
point(p3, p1);
3534
point(p4, p2);
3635
point(p4, p4);
37-
}
36+
}

src/data/examples/en/01_Form/01_Shape_Primitives.js

Lines changed: 5 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,11 @@
11
/*
22
* @name Shape Primitives
3-
* @description The basic shape primitive functions are triangle(),
4-
* rect(), quad(), ellipse(), and arc(). Squares are made with rect()
5-
* and circles are made with ellipse(). Each of these functions requires
3+
* @description The basic shape primitive functions are triangle(),
4+
* rect(), quad(), ellipse(), and arc(). Squares are made with rect()
5+
* and circles are made with ellipse(). Each of these functions requires
66
* a number of parameters to determine the shape's position and size.
77
*/
88
function setup() {
9-
109
// Sets the screen to be 720 pixels wide and 400 pixels high
1110
createCanvas(720, 400);
1211
background(0);
@@ -25,8 +24,8 @@ function setup() {
2524
ellipse(252, 144, 72, 72);
2625

2726
fill(204);
28-
triangle(288, 18, 351, 360, 288, 360);
27+
triangle(288, 18, 351, 360, 288, 360);
2928

3029
fill(255);
3130
arc(479, 300, 280, 280, PI, TWO_PI);
32-
}
31+
}
Lines changed: 15 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1,14 +1,14 @@
11
/*
22
* @name Pie Chart
3-
* @description Uses the arc() function to generate a pie chart from the data
3+
* @description Uses the arc() function to generate a pie chart from the data
44
* stored in an array.
55
*/
6-
var angles = [ 30, 10, 45, 35, 60, 38, 75, 67 ];
6+
let angles = [30, 10, 45, 35, 60, 38, 75, 67];
77

88
function setup() {
99
createCanvas(720, 400);
1010
noStroke();
11-
noLoop(); // Run once and stop
11+
noLoop(); // Run once and stop
1212
}
1313

1414
function draw() {
@@ -17,11 +17,18 @@ function draw() {
1717
}
1818

1919
function pieChart(diameter, data) {
20-
var lastAngle = 0;
21-
for (var i = 0; i < data.length; i++) {
22-
var gray = map(i, 0, data.length, 0, 255);
20+
let lastAngle = 0;
21+
for (let i = 0; i < data.length; i++) {
22+
let gray = map(i, 0, data.length, 0, 255);
2323
fill(gray);
24-
arc(width/2, height/2, diameter, diameter, lastAngle, lastAngle+radians(angles[i]));
24+
arc(
25+
width / 2,
26+
height / 2,
27+
diameter,
28+
diameter,
29+
lastAngle,
30+
lastAngle + radians(angles[i])
31+
);
2532
lastAngle += radians(angles[i]);
2633
}
27-
}
34+
}
Lines changed: 17 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,8 @@
11
/*
22
* @name Regular Polygon
3-
* @description What is your favorite? Pentagon? Hexagon? Heptagon? No?
4-
* What about the icosagon? The polygon() function created for this example is
5-
* capable of drawing any regular polygon. Try placing different numbers into
3+
* @description What is your favorite? Pentagon? Hexagon? Heptagon? No?
4+
* What about the icosagon? The polygon() function created for this example is
5+
* capable of drawing any regular polygon. Try placing different numbers into
66
* the polygon() function calls within draw() to explore.
77
*/
88
function setup() {
@@ -11,33 +11,33 @@ function setup() {
1111

1212
function draw() {
1313
background(102);
14-
14+
1515
push();
16-
translate(width*0.2, height*0.5);
16+
translate(width * 0.2, height * 0.5);
1717
rotate(frameCount / 200.0);
18-
polygon(0, 0, 82, 3);
18+
polygon(0, 0, 82, 3);
1919
pop();
20-
20+
2121
push();
22-
translate(width*0.5, height*0.5);
22+
translate(width * 0.5, height * 0.5);
2323
rotate(frameCount / 50.0);
24-
polygon(0, 0, 80, 20);
24+
polygon(0, 0, 80, 20);
2525
pop();
26-
26+
2727
push();
28-
translate(width*0.8, height*0.5);
28+
translate(width * 0.8, height * 0.5);
2929
rotate(frameCount / -100.0);
30-
polygon(0, 0, 70, 7);
30+
polygon(0, 0, 70, 7);
3131
pop();
3232
}
3333

3434
function polygon(x, y, radius, npoints) {
35-
var angle = TWO_PI / npoints;
35+
let angle = TWO_PI / npoints;
3636
beginShape();
37-
for (var a = 0; a < TWO_PI; a += angle) {
38-
var sx = x + cos(a) * radius;
39-
var sy = y + sin(a) * radius;
37+
for (let a = 0; a < TWO_PI; a += angle) {
38+
let sx = x + cos(a) * radius;
39+
let sy = y + sin(a) * radius;
4040
vertex(sx, sy);
4141
}
4242
endShape(CLOSE);
43-
}
43+
}
Lines changed: 19 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
/*
22
* @name Star
3-
* @description The star() function created for this example is capable of
4-
* drawing a wide range of different forms. Try placing different numbers
3+
* @description The star() function created for this example is capable of
4+
* drawing a wide range of different forms. Try placing different numbers
55
* into the star() function calls within draw() to explore.
66
*/
77
function setup() {
@@ -10,37 +10,37 @@ function setup() {
1010

1111
function draw() {
1212
background(102);
13-
13+
1414
push();
15-
translate(width*0.2, height*0.5);
15+
translate(width * 0.2, height * 0.5);
1616
rotate(frameCount / 200.0);
17-
star(0, 0, 5, 70, 3);
17+
star(0, 0, 5, 70, 3);
1818
pop();
19-
19+
2020
push();
21-
translate(width*0.5, height*0.5);
21+
translate(width * 0.5, height * 0.5);
2222
rotate(frameCount / 50.0);
23-
star(0, 0, 80, 100, 40);
23+
star(0, 0, 80, 100, 40);
2424
pop();
25-
25+
2626
push();
27-
translate(width*0.8, height*0.5);
27+
translate(width * 0.8, height * 0.5);
2828
rotate(frameCount / -100.0);
29-
star(0, 0, 30, 70, 5);
29+
star(0, 0, 30, 70, 5);
3030
pop();
3131
}
3232

3333
function star(x, y, radius1, radius2, npoints) {
34-
var angle = TWO_PI / npoints;
35-
var halfAngle = angle/2.0;
34+
let angle = TWO_PI / npoints;
35+
let halfAngle = angle / 2.0;
3636
beginShape();
37-
for (var a = 0; a < TWO_PI; a += angle) {
38-
var sx = x + cos(a) * radius2;
39-
var sy = y + sin(a) * radius2;
37+
for (let a = 0; a < TWO_PI; a += angle) {
38+
let sx = x + cos(a) * radius2;
39+
let sy = y + sin(a) * radius2;
4040
vertex(sx, sy);
41-
sx = x + cos(a+halfAngle) * radius1;
42-
sy = y + sin(a+halfAngle) * radius1;
41+
sx = x + cos(a + halfAngle) * radius1;
42+
sy = y + sin(a + halfAngle) * radius1;
4343
vertex(sx, sy);
4444
}
4545
endShape(CLOSE);
46-
}
46+
}

src/data/examples/en/01_Form/05_Triangle_Strip.js

Lines changed: 18 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -1,37 +1,37 @@
11
/*
22
* @name Triangle Strip
3-
* @description Example by Ira Greenberg. Generate a closed ring using the
4-
* vertex() function and beginShape(TRIANGLE_STRIP) mode. The outsideRadius
3+
* @description Example by Ira Greenberg. Generate a closed ring using the
4+
* vertex() function and beginShape(TRIANGLE_STRIP) mode. The outsideRadius
55
* and insideRadius variables control ring's radii respectively.
66
*/
7-
var x;
8-
var y;
9-
var outsideRadius = 150;
10-
var insideRadius = 100;
7+
let x;
8+
let y;
9+
let outsideRadius = 150;
10+
let insideRadius = 100;
1111

1212
function setup() {
1313
createCanvas(720, 400);
1414
background(204);
15-
x = width/2;
16-
y = height/2;
15+
x = width / 2;
16+
y = height / 2;
1717
}
1818

1919
function draw() {
2020
background(204);
21-
22-
var numPoints = int(map(mouseX, 0, width, 6, 60));
23-
var angle = 0;
24-
var angleStep = 180.0/numPoints;
25-
26-
beginShape(TRIANGLE_STRIP);
27-
for (var i = 0; i <= numPoints; i++) {
28-
var px = x + cos(radians(angle)) * outsideRadius;
29-
var py = y + sin(radians(angle)) * outsideRadius;
21+
22+
let numPoints = int(map(mouseX, 0, width, 6, 60));
23+
let angle = 0;
24+
let angleStep = 180.0 / numPoints;
25+
26+
beginShape(TRIANGLE_STRIP);
27+
for (let i = 0; i <= numPoints; i++) {
28+
let px = x + cos(radians(angle)) * outsideRadius;
29+
let py = y + sin(radians(angle)) * outsideRadius;
3030
angle += angleStep;
3131
vertex(px, py);
3232
px = x + cos(radians(angle)) * insideRadius;
3333
py = y + sin(radians(angle)) * insideRadius;
34-
vertex(px, py);
34+
vertex(px, py);
3535
angle += angleStep;
3636
}
3737
endShape();
Lines changed: 14 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,8 @@
11
/*
22
* @name Bezier
3-
* @description The first two parameters for the bezier() function specify the
4-
* first point in the curve and the last two parameters specify the last point.
5-
* The middle parameters set the control points that define the shape of the
3+
* @description The first two parameters for the bezier() function specify the
4+
* first point in the curve and the last two parameters specify the last point.
5+
* The middle parameters set the control points that define the shape of the
66
* curve.
77
*/
88
function setup() {
@@ -13,7 +13,16 @@ function setup() {
1313

1414
function draw() {
1515
background(0);
16-
for (var i = 0; i < 200; i += 20) {
17-
bezier(mouseX-(i/2.0), 40+i, 410, 20, 440, 300, 240-(i/16.0), 300+(i/8.0));
16+
for (let i = 0; i < 200; i += 20) {
17+
bezier(
18+
mouseX - i / 2.0,
19+
40 + i,
20+
410,
21+
20,
22+
440,
23+
300,
24+
240 - i / 16.0,
25+
300 + i / 8.0
26+
);
1827
}
1928
}

src/data/examples/en/01_Form/07_3D_Primitives.js

Lines changed: 17 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -6,25 +6,25 @@
66
* size. These shapes are positioned using the translate() function.
77
*/
88
function setup() {
9-
createCanvas(710, 400, WEBGL);
9+
createCanvas(710, 400, WEBGL);
1010
}
1111

1212
function draw() {
13-
background(100);
14-
15-
noStroke();
16-
fill(50);
17-
push();
18-
translate(-275, 175);
19-
rotateY(1.25);
20-
rotateX(-0.9);
21-
box(100);
22-
pop();
13+
background(100);
2314

24-
noFill();
25-
stroke(255);
26-
push();
27-
translate(500, height*0.35, -200);
28-
sphere(300);
29-
pop();
15+
noStroke();
16+
fill(50);
17+
push();
18+
translate(-275, 175);
19+
rotateY(1.25);
20+
rotateX(-0.9);
21+
box(100);
22+
pop();
23+
24+
noFill();
25+
stroke(255);
26+
push();
27+
translate(500, height * 0.35, -200);
28+
sphere(300);
29+
pop();
3030
}

src/data/examples/es/01_Form/00_Points_and_Lines.js

Lines changed: 5 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -5,12 +5,11 @@
55
* variables definen las posiciones basadas en el valor de 'd'.
66
*/
77
function setup() {
8-
9-
var d = 70;
10-
var p1 = d;
11-
var p2 = p1+d;
12-
var p3 = p2+d;
13-
var p4 = p3+d;
8+
let d = 70;
9+
let p1 = d;
10+
let p2 = p1 + d;
11+
let p3 = p2 + d;
12+
let p4 = p3 + d;
1413

1514
// Define el lienzo de 720 pixeles de ancho y 400 de alto
1615
createCanvas(720, 400);

src/data/examples/es/01_Form/01_Shape_Primitives.js

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,6 @@
66
* un número de parámetros para determinar la posición y tamaño de la figura.
77
*/
88
function setup() {
9-
109
// Define un lienzo de 720 pixeles de ancho y 400 de alto
1110
createCanvas(720, 400);
1211
background(0);

0 commit comments

Comments
 (0)