Skip to content

Commit 87bfc58

Browse files
authored
Merge pull request #1282 from aceslowman/exampleFixes
Misc WebGL Example Fixes
2 parents e1f7ee7 + fe98b09 commit 87bfc58

File tree

4 files changed

+39
-14
lines changed

4 files changed

+39
-14
lines changed

src/data/examples/assets/uniforms.frag

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -54,7 +54,7 @@ vec4 poly(float x, float y, float size, float sides, float rotation, vec3 col){
5454

5555
void main() {
5656

57-
vec2 center = resolution * 1.0; // draw the shape at the center of the screen
57+
vec2 center = resolution * 0.5; // draw the shape at the center of the screen
5858
float size = resolution.y * 0.5; // make the shape a quarter of the screen height
5959
float sides = mod(floor(mouse), 7.0) + 3.0; // slowly increase the sides, when it reaches 10 sides, go back down to 3
6060
float rotation = time; // rotation is in radians, but for time it doesnt really matter
Lines changed: 24 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -1,61 +1,74 @@
11
/*
22
* @name Geometries
3-
* @arialabel Six 3D shapes in neon gradient rotating on a white background. Shapes include cube, cylinder, ring, pyramid, sphere, and a plane.
4-
* @description There are six 3D primitives in p5 now.
3+
* @arialabel Seven 3D shapes in neon gradient rotating on a white background. Shapes include cube, cylinder, ring, pyramid, sphere, plane, and ellipsoid.
4+
* @description There are seven 3D primitives in p5 now.
55
*/
6+
67
function setup() {
78
createCanvas(710, 400, WEBGL);
9+
10+
describe(
11+
'a 3d example containing seven primitive objects, a plane, box, cylinder, cone, torus, sphere, and ellipsoid.'
12+
);
813
}
914

1015
function draw() {
1116
background(250);
1217

13-
translate(-240, -100, 0);
1418
normalMaterial();
1519
push();
20+
translate(-240, -100, 0);
1621
rotateZ(frameCount * 0.01);
1722
rotateX(frameCount * 0.01);
1823
rotateY(frameCount * 0.01);
1924
plane(70);
2025
pop();
2126

22-
translate(240, 0, 0);
2327
push();
28+
translate(0, -100, 0);
2429
rotateZ(frameCount * 0.01);
2530
rotateX(frameCount * 0.01);
2631
rotateY(frameCount * 0.01);
2732
box(70, 70, 70);
2833
pop();
2934

30-
translate(240, 0, 0);
3135
push();
36+
translate(240, -100, 0);
3237
rotateZ(frameCount * 0.01);
3338
rotateX(frameCount * 0.01);
3439
rotateY(frameCount * 0.01);
3540
cylinder(70, 70);
3641
pop();
3742

38-
translate(-240 * 2, 200, 0);
3943
push();
44+
translate(-250, 100, 0);
45+
rotateZ(frameCount * 0.01);
46+
rotateX(frameCount * 0.01);
47+
rotateY(frameCount * 0.01);
48+
cone(50, 70);
49+
pop();
50+
51+
push();
52+
translate(-75, 100, 0);
4053
rotateZ(frameCount * 0.01);
4154
rotateX(frameCount * 0.01);
4255
rotateY(frameCount * 0.01);
43-
cone(70, 70);
56+
torus(50, 20);
4457
pop();
4558

46-
translate(240, 0, 0);
4759
push();
60+
translate(100, 100, 0);
4861
rotateZ(frameCount * 0.01);
4962
rotateX(frameCount * 0.01);
5063
rotateY(frameCount * 0.01);
51-
torus(70, 20);
64+
sphere(50);
5265
pop();
5366

54-
translate(240, 0, 0);
5567
push();
68+
translate(275, 100, 0);
5669
rotateZ(frameCount * 0.01);
5770
rotateX(frameCount * 0.01);
5871
rotateY(frameCount * 0.01);
59-
sphere(70);
72+
ellipsoid(30, 40, 40);
6073
pop();
6174
}

src/data/examples/en/20_3D/02_multiple_lights.js

Lines changed: 10 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,10 @@
55
*/
66
function setup() {
77
createCanvas(710, 400, WEBGL);
8+
9+
describe(
10+
'a 3d example containing a spinning box and a sphere, each lit with a number of different lights, including ambient (gray), directional (red), spotlight (green), and point (blue).'
11+
);
812
}
913

1014
function draw() {
@@ -13,8 +17,13 @@ function draw() {
1317
let locX = mouseX - height / 2;
1418
let locY = mouseY - width / 2;
1519

20+
// ambient light is gray
1621
ambientLight(50);
22+
// directional light is red
1723
directionalLight(255, 0, 0, 0.25, 0.25, 0);
24+
// spotlight is green
25+
spotLight(0, 255, 0, 150, 0, 250, 0, 0, -1);
26+
// point light is blue
1827
pointLight(0, 0, 255, locX, locY, 250);
1928

2029
push();
@@ -27,5 +36,5 @@ function draw() {
2736

2837
translate(width / 4, 0, 0);
2938
ambientMaterial(250);
30-
sphere(120, 64);
39+
sphere(120, 24);
3140
}

src/data/examples/en/20_3D/10_passing_shader_uniforms.js

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -17,15 +17,18 @@
1717
// shaders require WEBGL mode to work
1818
createCanvas(710, 400, WEBGL);
1919
noStroke();
20+
21+
describe('a 2d example containing a sage green polygon, rotating in the middle of the sketch. As the mouse moves horizontally, the number of sides for the polygon change.')
2022
}
2123

2224
function draw() {
2325
// shader() sets the active shader with our shader
2426
shader(theShader);
2527

2628
// lets send the resolution, mouse, and time to our shader
29+
// the mouse x position will change the number of sides
2730
// before sending mouse + time we modify the data so it's more easily usable by the shader
28-
theShader.setUniform('resolution', [width, height]);
31+
theShader.setUniform('resolution', [width * displayDensity(), height * displayDensity()]);
2932
theShader.setUniform('mouse', map(mouseX, 0, width, 0, 7));
3033
theShader.setUniform('time', frameCount * 0.01);
3134

0 commit comments

Comments
 (0)