savestate
This commit is contained in:
parent
eff0138135
commit
c54b95d716
1 changed files with 18 additions and 8 deletions
26
3/sketch.js
26
3/sketch.js
|
@ -28,14 +28,15 @@ const sortSketch = function (p) {
|
||||||
};
|
};
|
||||||
|
|
||||||
p.preload = function () {
|
p.preload = function () {
|
||||||
img = p.loadImage("assets/image.png");
|
// img = p.loadImage("assets/image.png");
|
||||||
|
img = p.createImage(66, 66)
|
||||||
p.pixelDensity(1);
|
p.pixelDensity(1);
|
||||||
};
|
};
|
||||||
|
|
||||||
p.draw = function () {
|
p.draw = function () {
|
||||||
img.loadPixels();
|
img.loadPixels();
|
||||||
p.image(img, 0, 0, 400, 400);
|
p.image(img, 0, 0, 400, 400);
|
||||||
let pixelArray = [[]];
|
let pixelArray = [];
|
||||||
for (let px = 0; px < img.pixels.length; px += 4) {
|
for (let px = 0; px < img.pixels.length; px += 4) {
|
||||||
pixelArray.push([
|
pixelArray.push([
|
||||||
img.pixels[px],
|
img.pixels[px],
|
||||||
|
@ -45,14 +46,23 @@ const sortSketch = function (p) {
|
||||||
]);
|
]);
|
||||||
}
|
}
|
||||||
|
|
||||||
pixelArray.sort((a, b) => parseInt(a[0]) - parseInt(b[0]));
|
pixelArray.sort((a, b) => a[0] - b[0]);
|
||||||
img.pixels = [];
|
for (let px = 0; px < img.pixels.length; px += 4) {
|
||||||
for (pixel of pixelArray) {
|
img.pixels[px] = pixelArray[px / 4][0];
|
||||||
img.pixels.push(...pixel);
|
img.pixels[px + 1] = pixelArray[px / 4][1];
|
||||||
|
img.pixels[px + 2] = pixelArray[px / 4][2];
|
||||||
|
img.pixels[px + 3] = pixelArray[px / 4][3];
|
||||||
}
|
}
|
||||||
console.log(img.pixels);
|
console.log(img.pixels);
|
||||||
|
for (let x = 0; x < img.width; x += 1) {
|
||||||
img.updatePixels();
|
for (let y = 0; y < img.height; y += 1) {
|
||||||
|
img.set(x, y, 0);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
console.log(img.pixels)
|
||||||
|
p.updatePixels();
|
||||||
|
p.image(img, 0, 0, 400, 400);
|
||||||
|
p.noLoop();
|
||||||
};
|
};
|
||||||
};
|
};
|
||||||
//let test = function (p) {
|
//let test = function (p) {
|
||||||
|
|
Loading…
Add table
Reference in a new issue