-
Notifications
You must be signed in to change notification settings - Fork 0
/
sketch.js
80 lines (69 loc) · 1.6 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
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
var img;
var cantPixels = 32;
//var numeros = [];
var cont;
var tam = 6;
var myArray = [];
/*------------------*/
function preload() {
img = loadImage('32.png');
pixelDensity(1);
}
/*------------------*/
function setup() {
img.loadPixels();
createCanvas(cantPixels * tam, cantPixels * tam);
fill (255);
frameRate(1);
}
/*------------------*/
function draw() {
background(0);
image(img, 0, 0);
img.loadPixels();
loadPixels();
for (var y = 0; y < cantPixels; y++) {
for (var x = 0; x < cantPixels; x++) {
var index = (x + (y * cantPixels)) * 4;
var r = img.pixels[index + 0];
var g = img.pixels[index + 1];
var b = img.pixels[index + 2];
pixels[index + 0] = r;
pixels[index + 1] = g;
pixels[index + 2] = b;
pixels[index + 3] = 255
}
}
var nuevos_pixeles = [];
for (var i = 0; i < cantPixels * cantPixels * 4; i += 4) {
var pixel = [
pixels[i + 0], pixels[i + 1], pixels[i + 2], pixels[i + 3]
]
nuevos_pixeles.push(pixel)
}
shuffles(nuevos_pixeles);
for (var y = 0; y < cantPixels; y++) {
for (var x = 0; x < cantPixels; x++) {
var i = y * cantPixels + x;
//console.log(i);
var r = pixels[(i * 4) + 0] = nuevos_pixeles[i][0];
var g = pixels[(i * 4) + 1] = nuevos_pixeles[i][1];
var b = pixels[(i * 4) + 2] = nuevos_pixeles[i][2];
var a = pixels[(i * 4) + 3] = nuevos_pixeles[i][3];
fill(r, g, b);
noStroke();
rect(x * tam, y * tam, tam, tam);
}
}
}
/*------------------*/
function shuffles(a) {
var j, x, i;
for (i = a.length - 1; i > 0; i--) {
j = Math.floor(Math.random() * (i + 1));
x = a[i];
a[i] = a[j];
a[j] = x;
}
return a;
}