-
Notifications
You must be signed in to change notification settings - Fork 0
/
sketch.js
65 lines (53 loc) · 1.17 KB
/
sketch.js
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
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
let file;
let img;
let tiles, tileSize;
var button;
var colour = false;
function handleFile(file) {
print(file);
if (file.type === 'image') {
img = loadImage(file.data, '');
console.log("img loaded!")
} else {
img = null;
}
}
function toggleColour() {
if (colour) {
colour = false;
} else if (!colour) {
colour = true;
}
}
function setup() {
createCanvas(550, 550);
input = createFileInput(handleFile);
slider = createSlider(1, 45, 10, 0.5);
button = createButton("Colour");
button.mousePressed(toggleColour);
colorMode(RGB, 255);
}
function draw() {
background(220);
noStroke();
if (img) {
// image(img, 0, 0, width, height);
img.resize(width,height)
tiles = slider.value();
tileSize = width/tiles;
translate(tileSize/2, tileSize/2);
for(x = 0; x < tiles; x++) {
for(y = 0; y < tiles; y++) {
c = img.get(x*tileSize, y*tileSize);
size = map(brightness(c), 0, 100, 25, 0);
if (colour) {
fill(c);
ellipse(x*tileSize, y*tileSize, size, size);
} else {
fill(0);
ellipse(x*tileSize, y*tileSize, size, size);
}
}
}
}
}