-
Notifications
You must be signed in to change notification settings - Fork 115
Expand file tree
/
Copy pathliveSketch.js
More file actions
32 lines (27 loc) · 827 Bytes
/
liveSketch.js
File metadata and controls
32 lines (27 loc) · 827 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
/**
* Transparency.
*
* Move the pointer left and right across the image to change
* its position. This program overlays one image over another
* by modifying the alpha value of the image with the tint() function.
*/
// The next line is needed if running in JavaScript Mode with Processing.js
/* @pjs preload="moonwalk.jpg"; */
function runLiveSketch(s) {
var img;
var offset = 0;
var easing = 0.05;
s.preload = () => {
img = s.loadImage('/livesketch/transparency/moonwalk.jpg'); // Load an image into the program
};
s.setup = () => {
s.createCanvas(640, 360);
};
s.draw = () => {
s.image(img, 0, 0); // Display at full opacity
var dx = s.mouseX - img.width / 2 - offset;
offset += dx * easing;
s.tint(255, 127); // Display at half opacity
s.image(img, offset, 0);
};
}