Skip to content

Commit 3b93989

Browse files
authored
Merge pull request #1238 from MissTipo/shader-translation-glsl-to-p5-strands-2.0
Add p5.strands translations for shader examples and rename original GLSL examples
2 parents 4ee9769 + 4b98cd5 commit 3b93989

File tree

14 files changed

+253
-14
lines changed

14 files changed

+253
-14
lines changed

src/content/examples/config.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -41,10 +41,10 @@ export const examplesCollection = defineCollection({
4141
)
4242
.optional(),
4343
// Collective attribution message either does not specify a year,
44-
// or specifies 2024. To add a new possible value, update:
44+
// or specifies a year from 2024 onwards. To add a new possible value, update:
4545
// 1) content/examples/config.ts to include new permitted values;
4646
// 2) and content/ui/*.yaml strings for attribution to include the text
47-
collectivelyAttributedSince: z.literal(2024).optional(),
47+
collectivelyAttributedSince: z.union([z.literal(2024), z.literal(2026)]).optional(),
4848
})
4949
)
5050
.optional()

src/content/examples/en/02_Animation_And_Variables/02_Mobile_Device_Movement/description.mdx

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,6 @@ featuredImage: "../../../images/featured/02_Animation_And_Variables-02_Mobile_De
33
featuredImageAlt: White circles on a black background, with varying degrees of transparency.
44
title: Mobile Device Movement
55
oneLineDescription: Animate based on device motion.
6-
featured: true
76

87
remix:
98
- description: Revised by
@@ -24,4 +23,4 @@ In this example, the
2423
<a href="https://p5js.org/reference/p5/accelerationY" target="_blank">accelerationY</a>,
2524
and <a href="https://p5js.org/reference/p5/accelerationZ" target="_blank">accelerationZ</a>
2625
values set the position and size of a circle.
27-
This only works for mobile devices.
26+
This only works for mobile devices.

src/content/examples/en/09_Angles_And_Motion/00_Sine_Cosine/description.mdx

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,6 @@ featuredImage: "../../../images/featured/09_Angles_And_Motion-00_Sine_Cosine-thu
33
featuredImageAlt: A point on the unit circle, together with the corresponding sine and cosine values on their graphs.
44
title: Sine and Cosine
55
oneLineDescription: Animate circular, back and forth, and wave motion.
6-
featured: true
76

87
remix:
98
- description: Revised by
@@ -28,4 +27,4 @@ The animation shows uniform circular motion around the unit circle
2827
(circle with radius 1). Any angle measured from the the x-axis
2928
determines a point on the circle. The cosine and sine of the angle
3029
are defined to be the x and y coordinates, respectively, of that
31-
point.
30+
point.

src/content/examples/en/11_3D/04_Filter_Shader/description.mdx

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
---
22
featuredImage: "../../../images/featured/11_3D-04_Filter_Shader-thumbnail.png"
33
featuredImageAlt: A screenshot of a video of a city crosswalk, with offset colors.
4-
title: Filter Shader
4+
title: Filter Shader (GLSL)
55
oneLineDescription: Manipulate imagery with a shader.
66

77
remix:
@@ -15,4 +15,4 @@ remix:
1515
---
1616

1717
Filter shaders are a way to apply an effect to anything that
18-
is on the canvas. In this example, the effect is applied to a video.
18+
is on the canvas. In this example, the effect is applied to a video.

src/content/examples/en/11_3D/05_Adjusting_Positions_With_A_Shader/description.mdx

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
---
22
featuredImage: "../../../images/featured/11_3D-05_Adjusting_Positions_With_A_Shader-thumbnail.png"
33
featuredImageAlt: A red-to-blue waving ribbon on a white background.
4-
title: Adjusting Positions with a Shader
4+
title: Adjusting Positions with a Shader (GLSL)
55
oneLineDescription: Use a shader to adjust shape vertices.
66

77
remix:
@@ -15,4 +15,4 @@ remix:
1515
---
1616

1717
Shaders can adjust the positions of the vertices of shapes.
18-
This lets you distort and animate 3D models.
18+
This lets you distort and animate 3D models.
Lines changed: 39 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,39 @@
1+
let video;
2+
let displaceColors;
3+
4+
function setup() {
5+
createCanvas(700, 400, WEBGL);
6+
video = createVideo(
7+
'https://upload.wikimedia.org/wikipedia/commons/d/d2/DiagonalCrosswalkYongeDundas.webm'
8+
);
9+
video.volume(0);
10+
video.hide();
11+
video.loop();
12+
displaceColors = buildFilterShader(displaceColorsCallback);
13+
describe(
14+
'A video of a city crosswalk, with colors getting more offset the further from the center they are'
15+
);
16+
}
17+
18+
function displaceColorsCallback() {
19+
function zoom(coord, amount) {
20+
return (coord - 0.5) / amount + 0.5;
21+
}
22+
filterColor.begin();
23+
const uv = filterColor.texCoord;
24+
const r = getTexture(filterColor.canvasContent, uv).r;
25+
const g = getTexture(filterColor.canvasContent, zoom(uv, 1.05)).g;
26+
const b = getTexture(filterColor.canvasContent, zoom(uv, 1.1)).b;
27+
const a = getTexture(filterColor.canvasContent, uv).a;
28+
filterColor.set([r, g, b, a]);
29+
filterColor.end();
30+
}
31+
32+
function draw() {
33+
background(255);
34+
push();
35+
imageMode(CENTER);
36+
image(video, 0, 0, width, height, 0, 0, video.width, video.height, COVER);
37+
pop();
38+
filter(displaceColors);
39+
}
Lines changed: 30 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,30 @@
1+
---
2+
featuredImage: "../../../images/featured/11_3D-04_Filter_Shader-thumbnail.png"
3+
featuredImageAlt: A screenshot of a video of a city crosswalk, with offset colors.
4+
title: Filter Shader (p5.strands)
5+
oneLineDescription: Manipulate imagery with a shader, written in p5.strands.
6+
featured: true
7+
8+
remix:
9+
- description: Created by
10+
attribution:
11+
- name: Dave Pagurek
12+
URL: https://www.davepagurek.com/
13+
code:
14+
- label: 2023 code
15+
URL: https://github.com/processing/p5.js-example/tree/main/examples/11_3D/04_Filter_Shader
16+
17+
- description: Remixed by
18+
attribution:
19+
- name: Dorine Tipo
20+
URL: https://dorinetipo.vercel.app/
21+
code:
22+
- label: 2026 p5.strands translation
23+
URL: https://github.com/processing/p5.js-website/tree/main/src/content/examples/en/11_3D/07_Filter_Shader_p5strands
24+
25+
- collectivelyAttributedSince: 2026
26+
---
27+
28+
This is a p5.strands version of the Filter Shader example. Filter shaders apply
29+
an effect to anything that is on the canvas. In this example, the effect is applied to
30+
a video.
Lines changed: 39 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,39 @@
1+
let wiggleShader;
2+
let ribbon;
3+
4+
function setup() {
5+
createCanvas(700, 400, WEBGL);
6+
wiggleShader = buildColorShader(wiggleCallback);
7+
8+
let startColor = color('#F55');
9+
let endColor = color('#55F');
10+
ribbon = buildGeometry(() => {
11+
noStroke();
12+
beginShape(QUAD_STRIP);
13+
let numPoints = 50;
14+
for (let currentPoint = 0; currentPoint < numPoints; currentPoint++) {
15+
let x = map(currentPoint, 0, numPoints - 1, -width / 3, width / 3);
16+
let y = map(currentPoint, 0, numPoints - 1, -height / 3, height / 3);
17+
fill(lerpColor(startColor, endColor, currentPoint / (numPoints - 1)));
18+
for (let z of [-50, 50]) {
19+
vertex(x, y, z);
20+
}
21+
}
22+
endShape();
23+
});
24+
describe('A red-to-blue ribbon that waves over time');
25+
}
26+
27+
function wiggleCallback() {
28+
objectInputs.begin();
29+
objectInputs.position.y += 20 * sin(millis() * 0.01 + objectInputs.position.y * 0.1);
30+
objectInputs.end();
31+
}
32+
33+
function draw() {
34+
background(255);
35+
noStroke();
36+
rotateX(PI * 0.1);
37+
shader(wiggleShader);
38+
model(ribbon);
39+
}
Lines changed: 30 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,30 @@
1+
---
2+
featuredImage: "../../../images/featured/11_3D-05_Adjusting_Positions_With_A_Shader-thumbnail.png"
3+
featuredImageAlt: A red-to-blue waving ribbon on a white background.
4+
title: Adjusting Positions with a Shader (p5.strands)
5+
oneLineDescription: Use a shader to adjust shape vertices, written in p5.strands.
6+
featured: true
7+
8+
remix:
9+
- description: Created by
10+
attribution:
11+
- name: Dave Pagurek
12+
URL: https://www.davepagurek.com/
13+
code:
14+
- label: 2023 code
15+
URL: https://github.com/processing/p5.js-example/tree/main/examples/11_3D/05_Adjusting_Positions_With_A_Shader
16+
17+
- description: Remixed by
18+
attribution:
19+
- name: Dorine Tipo
20+
URL: https://dorinetipo.vercel.app/
21+
code:
22+
- label: 2026 p5.strands translation
23+
URL: https://github.com/processing/p5.js-website/tree/main/src/content/examples/en/11_3D/08_Adjusting_Positions_With_A_Shader_p5strands
24+
25+
- collectivelyAttributedSince: 2026
26+
---
27+
28+
This is a p5.strands version of the Adjusting Positions with a Shader example.
29+
Shaders can adjust the positions of the vertices of shapes.
30+
This lets you distort and animate 3D models.

src/content/examples/en/12_Advanced_Canvas_Rendering/02_Shader_As_A_Texture/description.mdx

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
---
22
featuredImage: "../../../images/featured/12_Advanced_Canvas_Rendering-02_Shader_As_A_Texture-thumbnail.png"
33
featuredImageAlt: Two spheres broken up into a square grid with a gradient in each grid.
4-
title: Shader as a Texture
4+
title: Shader as a Texture (GLSL)
55
oneLineDescription: Generate a texture for a 3D shape using a shader.
66

77
remix:
@@ -19,4 +19,4 @@ remix:
1919
Shaders can be applied to 2D/3D shapes as textures.
2020

2121
To learn more about using shaders in p5.js:
22-
<a href="https://itp-xstory.github.io/p5js-shaders/">p5.js Shaders</a>
22+
<a href="https://itp-xstory.github.io/p5js-shaders/">p5.js Shaders</a>

0 commit comments

Comments
 (0)