Skip to content

Commit b8a610e

Browse files
committed
Fix Rotate Push Pop camera distance, fix Loading Images scaling and loading state
1 parent f09741b commit b8a610e

4 files changed

Lines changed: 24 additions & 8 deletions

File tree

assets/examples_js/Basics/transform/Rotate_Push_Pop/Rotate_Push_Pop.js

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -14,13 +14,16 @@ function draw() {
1414
directionalLight(255, 255, 255, 0, 0, -1);
1515
directionalLight(100, 100, 100, 0, 0, 1);
1616

17+
// Move camera closer — default WEBGL camera is too far
18+
translate(0, 0, 150);
19+
1720
for (let i = 0; i < num; i++) {
1821
let gray = map(i, 0, num - 1, 0, 255);
1922
push();
2023
fill(gray);
2124
rotateY(a + offset * i);
2225
rotateX(a / 2 + offset * i);
23-
box(90);
26+
box(150);
2427
pop();
2528
}
2629
a += 0.01;

assets/examples_js/Basics/web/Loading_Images/Loading_Images.js

Lines changed: 8 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -6,14 +6,19 @@ function preload() {
66

77
function setup() {
88
createCanvas(640, 360);
9-
noLoop();
109
}
1110

1211
function draw() {
1312
background(0);
14-
if (img) {
13+
if (img && img.width > 0) {
14+
let h = img.height * (640 / img.width); // scale to fit width
1515
for (let i = 0; i < 5; i++) {
16-
image(img, 0, img.height * i);
16+
image(img, 0, h * i, 640, h);
1717
}
18+
} else {
19+
fill(255);
20+
textAlign(CENTER);
21+
textSize(14);
22+
text('Loading...', width/2, height/2);
1823
}
1924
}

examples/loading-images.html

Lines changed: 8 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -73,15 +73,20 @@ <h1>Loading Images</h1>
7373
7474
function setup() {
7575
createCanvas(640, 360);
76-
noLoop();
7776
}
7877
7978
function draw() {
8079
background(0);
81-
if (img) {
80+
if (img && img.width > 0) {
81+
let h = img.height * (640 / img.width); // scale to fit width
8282
for (let i = 0; i < 5; i++) {
83-
image(img, 0, img.height * i);
83+
image(img, 0, h * i, 640, h);
8484
}
85+
} else {
86+
fill(255);
87+
textAlign(CENTER);
88+
textSize(14);
89+
text('Loading...', width/2, height/2);
8590
}
8691
}<\/script></body></html>`);doc.close();})();</script>
8792
<div class="code-block">

examples/rotate-push-pop.html

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -81,13 +81,16 @@ <h1>Rotate Push Pop</h1>
8181
directionalLight(255, 255, 255, 0, 0, -1);
8282
directionalLight(100, 100, 100, 0, 0, 1);
8383
84+
// Move camera closer — default WEBGL camera is too far
85+
translate(0, 0, 150);
86+
8487
for (let i = 0; i < num; i++) {
8588
let gray = map(i, 0, num - 1, 0, 255);
8689
push();
8790
fill(gray);
8891
rotateY(a + offset * i);
8992
rotateX(a / 2 + offset * i);
90-
box(90);
93+
box(150);
9194
pop();
9295
}
9396
a += 0.01;

0 commit comments

Comments
 (0)