-
Notifications
You must be signed in to change notification settings - Fork 115
Expand file tree
/
Copy pathliveSketch.js
More file actions
38 lines (33 loc) · 937 Bytes
/
liveSketch.js
File metadata and controls
38 lines (33 loc) · 937 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
33
34
35
36
37
38
/**
* Pointillism
* by Daniel Shiffman.
*
* Mouse horizontal location controls size of dots.
* Creates a simple pointillist effect using ellipses colored
* according to pixels in an image.
*/
// The next line is needed if running in JavaScript Mode with Processing.js
/* @pjs preload="moonwalk.jpg"; */
function runLiveSketch(s) {
var img;
var smallPoint, largePoint;
s.preload = () => {
img = s.loadImage('/livesketch/pointillism/moonwalk.jpg');
};
s.setup = () => {
s.createCanvas(640, 360);
smallPoint = 4;
largePoint = 40;
s.imageMode(s.CENTER);
s.noStroke();
s.background(255);
};
s.draw = () => {
var pointillize = s.map(s.mouseX, 0, s.width, smallPoint, largePoint);
var x = s.int(s.random(img.width));
var y = s.int(s.random(img.height));
var pix = img.get(x, y);
s.fill(pix[0], pix[1], pix[2], 128);
s.ellipse(x, y, pointillize, pointillize);
};
}