Skip to content

Commit 5690103

Browse files
committed
added a simple feedback example
1 parent 60dce65 commit 5690103

File tree

1 file changed

+42
-0
lines changed

1 file changed

+42
-0
lines changed
Lines changed: 42 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,42 @@
1+
/*
2+
* @name Simple Feedback
3+
* @arialabel An example of a simple feedback effect using two buffers.
4+
* @description A simple feedback effect can be achieved through WEBGL mode and two graphics buffers.
5+
*/
6+
7+
let pg, swap;
8+
9+
function setup() {
10+
createCanvas(710, 400);
11+
12+
// this will hold our main graphic
13+
pg = createGraphics(710, 400, WEBGL);
14+
// this will hold the previous frame
15+
swap = createGraphics(710, 400, WEBGL);
16+
}
17+
18+
function draw() {
19+
// draw the previous frame
20+
pg.texture(swap);
21+
pg.noStroke();
22+
pg.plane(width, height);
23+
24+
// draw our circle graphic on top
25+
pg.fill(255);
26+
pg.ellipse(Math.sin(millis()/200)*5, Math.cos(millis()/200)*5, 150, 150);
27+
28+
// draw a slightly scaled up copy of the texture
29+
swap.push();
30+
swap.scale(1.1, 1.1);
31+
swap.texture(pg);
32+
swap.noStroke();
33+
swap.plane(width, height);
34+
swap.pop();
35+
36+
// an opaque rectangle is drawn over top to control the feedback decay
37+
swap.fill(0, 50);
38+
swap.rect(-width / 2, -height / 2, width, height);
39+
40+
// draw the output to the screen
41+
image(swap, 0, 0);
42+
}

0 commit comments

Comments
 (0)