Skip to content

Commit df06794

Browse files
committed
Regenerate example pages with updated p5.js sketches
1 parent dcf05c1 commit df06794

7 files changed

Lines changed: 44 additions & 52 deletions

examples/characters-strings.html

Lines changed: 18 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -96,23 +96,36 @@ <h1>Characters Strings</h1>
9696
9797
function draw() {
9898
background(0);
99-
10099
fill(255);
101-
102100
textSize(14);
103101
text("Click on the program, then type to add to the String", 50, 50);
104102
text("Current key: " + letter, 50, 70);
105103
text("The String is " + words.length + " characters long", 50, 90);
106-
107104
textSize(36);
108-
text(words, 50, 120, 540, 300);
105+
106+
// manual wrap
107+
let lineWidth = 540;
108+
let x = 50;
109+
let y = 140;
110+
let lineHeight = 44;
111+
let line = "";
112+
for (let i = 0; i < words.length; i++) {
113+
let testLine = line + words[i];
114+
if (textWidth(testLine) > lineWidth) {
115+
text(line, x, y);
116+
y += lineHeight;
117+
line = words[i];
118+
} else {
119+
line = testLine;
120+
}
121+
}
122+
text(line, x, y);
109123
}
110124
111125
function keyTyped() {
112126
if ((key >= 'A' && key <= 'z') || key === ' ') {
113127
letter = key;
114128
words += key;
115-
console.log(key);
116129
}
117130
}<\/script>
118131
</body></html>`);

examples/datatype-conversion.html

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -101,7 +101,8 @@ <h1>Datatype Conversion</h1>
101101
let b = int(f / 2);
102102
103103
text("The value of variable c is " + c, 50, 100);
104-
text("The value of variable f is " + f, 50, 150);
104+
text("The value of variable f is " + f + ".000000", 50, 150);
105+
//SHUSH
105106
text("The value of variable i is " + i, 50, 200);
106107
text("The value of variable b is " + b, 50, 250);
107108

examples/move-eye.html

Lines changed: 4 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -92,18 +92,13 @@ <h1>Move Eye</h1>
9292
}
9393
9494
function draw() {
95-
lights();
9695
background(0);
97-
98-
camera(
99-
30.0, mouseY - height / 2, 220.0,
100-
0.0, 0.0, 0.0,
101-
0.0, 1.0, 0.0
102-
);
103-
96+
lights();
97+
camera(30.0, mouseY - height / 2, 220.0,
98+
0.0, 0.0, 0.0,
99+
0.0, 1.0, 0.0);
104100
noStroke();
105101
box(90);
106-
107102
stroke(255);
108103
line(-100, 0, 0, 100, 0, 0);
109104
line(0, -100, 0, 0, 100, 0);

examples/perspective-vs-ortho.html

Lines changed: 4 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -91,25 +91,20 @@ <h1>Perspective vs Ortho</h1>
9191
function setup() {
9292
createCanvas(600, 360, WEBGL);
9393
noStroke();
94+
fill(255);
9495
}
9596
9697
function draw() {
9798
background(0);
9899
lights();
99-
100-
let far = map(mouseX, 0, width, 300, 1000);
101-
100+
let far = map(mouseX, 0, width, 120, 400);
102101
if (showPerspective) {
103-
perspective(PI / 3, width / height, 10, far);
102+
perspective(PI / 3.0, width / height, 10, far);
104103
} else {
105-
ortho(-width / 2, width / 2,
106-
-height / 2, height / 2,
107-
10, far);
104+
ortho(-width / 2.0, width / 2.0, -height / 2.0, height / 2.0, 10, far);
108105
}
109-
110106
rotateX(-PI / 6);
111107
rotateY(PI / 3);
112-
113108
box(180);
114109
}
115110

examples/perspective.html

Lines changed: 7 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -92,26 +92,20 @@ <h1>Perspective</h1>
9292
}
9393
9494
function draw() {
95-
lights();
9695
background(0);
97-
98-
let cameraY = height / 2;
99-
let fov = (mouseX / width) * PI / 2;
100-
let cameraZ = cameraY / tan(fov / 2);
96+
lights();
97+
let cameraY = height / 2.0;
98+
let fov = mouseX / width * PI / 2;
99+
let cameraZ = cameraY / tan(fov / 2.0);
101100
let aspect = width / height;
102-
103101
if (mouseIsPressed) {
104-
aspect /= 2;
102+
aspect = aspect / 2.0;
105103
}
106-
107-
perspective(fov, aspect, cameraZ / 10, cameraZ * 10);
108-
104+
perspective(fov, aspect, cameraZ / 10.0, cameraZ * 10.0);
109105
translate(30, 0, 0);
110106
rotateX(-PI / 6);
111-
rotateY(PI / 3 + (mouseY / height) * PI);
112-
107+
rotateY(PI / 3 + mouseY / height * PI);
113108
box(45);
114-
115109
translate(0, 0, -50);
116110
box(30);
117111
}<\/script>

examples/primitives-3d.html

Lines changed: 3 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -88,26 +88,23 @@ <h1>Primitives 3D</h1>
8888
</head><body>
8989
<script>function setup() {
9090
createCanvas(640, 360, WEBGL);
91+
noLoop();
9192
}
9293
9394
function draw() {
9495
background(0);
9596
lights();
96-
9797
noStroke();
98-
9998
push();
100-
translate(-width / 2 + 130, 0, 0);
99+
translate(-180, 0, 0);
101100
rotateY(1.25);
102101
rotateX(-0.4);
103102
box(100);
104103
pop();
105-
106104
noFill();
107105
stroke(255);
108-
109106
push();
110-
translate(-width / 2 + 500, height * 0.35 - height / 2, -200);
107+
translate(170, -height * 0.15, -200);
111108
sphere(280);
112109
pop();
113110
}<\/script>

examples/variable-scope.html

Lines changed: 6 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -97,21 +97,18 @@ <h1>Variable Scope</h1>
9797
9898
function draw() {
9999
line(a, 0, a, height);
100-
101-
for (let a = 120; a < 200; a += 2) {
102-
line(a, 0, a, height);
100+
for (let i = 120; i < 200; i += 2) {
101+
line(i, 0, i, height);
103102
}
104-
105-
let a = 300;
106-
line(a, 0, a, height);
107-
103+
let b = 300;
104+
line(b, 0, b, height);
108105
drawAnotherLine();
109106
drawYetAnotherLine();
110107
}
111108
112109
function drawAnotherLine() {
113-
let a = 320;
114-
line(a, 0, a, height);
110+
let c = 320;
111+
line(c, 0, c, height);
115112
}
116113
117114
function drawYetAnotherLine() {

0 commit comments

Comments
 (0)