-
Notifications
You must be signed in to change notification settings - Fork 1
/
sketch2.js
65 lines (52 loc) · 1.53 KB
/
sketch2.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
65
//채택되지 못한 sketch file 입니다.
//이미지를 시간순으로 모자이크 처리하는 애니메이션입니다.
var img;
var arraylist = [];
var resMax = 24;
function preload(){
img = loadImage("assets/img/amsal.jpeg");
}
function setup() {
frameRate(60);
var sc = 1;
canvas=createCanvas(windowWidth,windowHeight);
canvas.position(0,0);
pixelDensity(1);
scale(sc);
img.resize(windowWidth, windowHeight);
image(img,0,0);
var d = pixelDensity();
var w = d*img.width*sc;
var h = d*img.height*sc;
loadPixels();
background(0);
var count = 0;
var colorRange = 255;
colorRange = 256-colorRange;
for(var res = 1; res < resMax; res++){
var newPixels = [];
for (var i = 0; i<w; i++){
for(var n =0; n<h; n++){
newPixels[(n*w + i)*4] = round(pixels[floor((floor(n/res)*res*w + i)/res)*res*4]/colorRange)*colorRange;
newPixels[(n*w + i)*4+1] = round(pixels[floor((floor(n/res)*res*w + i)/res)*res*4+1]/colorRange)*colorRange;
newPixels[(n*w + i)*4+2] = round(pixels[floor((floor(n/res)*res*w + i)/res)*res*4+2]/colorRange)*colorRange;
newPixels[(n*w + i)*4+3] = 255;
}
}
append(arraylist,newPixels.slice(0));
// console.log(newPixels);
}
// console.log(arraylist.length);
}
function draw() {
var year = select('h1');
var yearText = year.elt.textContent;
// console.log(yearText%(resMax-1));
var flag = parseInt((yearText-1900)/5);
// console.log(pixels.length);
var arrlen= arraylist.length-1;
for(var i = 0; i<pixels.length; i++){
pixels[i] = arraylist[arrlen-flag][i];
}
updatePixels();
}