-
Notifications
You must be signed in to change notification settings - Fork 115
Expand file tree
/
Copy pathliveSketch.js
More file actions
34 lines (32 loc) · 1013 Bytes
/
liveSketch.js
File metadata and controls
34 lines (32 loc) · 1013 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
function runLiveSketch(s) {
var distances;
var maxDistance;
var spacer;
s.setup = () => {
s.createCanvas(640, 360);
maxDistance = s.dist(s.width / 2, s.height / 2, s.width, s.height);
distances = [];
for (var x = 0; x < s.width; x++) {
distances[x] = [];
for (var y = 0; y < s.height; y++) {
var distance = s.dist(s.width / 2, s.height / 2, x, y);
distances[x][y] = (distance / maxDistance) * 255;
}
}
spacer = 10;
s.noLoop(); // Run once and stop
};
s.draw = () => {
s.background(0);
// This embedded loop skips over values in the arrays based on
// the spacer variable, so there are more values in the array
// than are drawn here. Change the value of the spacer variable
// to change the density of the points
for (var y = 0; y < s.height; y += spacer) {
for (var x = 0; x < s.width; x += spacer) {
s.stroke(distances[x][y]);
s.point(x + spacer / 2, y + spacer / 2);
}
}
};
}