savestate

This commit is contained in:
Yannick 2025-04-14 09:34:42 +02:00
parent eff0138135
commit c54b95d716

View file

@ -28,14 +28,15 @@ const sortSketch = function (p) {
};
p.preload = function () {
img = p.loadImage("assets/image.png");
// img = p.loadImage("assets/image.png");
img = p.createImage(66, 66)
p.pixelDensity(1);
};
p.draw = function () {
img.loadPixels();
p.image(img, 0, 0, 400, 400);
let pixelArray = [[]];
let pixelArray = [];
for (let px = 0; px < img.pixels.length; px += 4) {
pixelArray.push([
img.pixels[px],
@ -45,14 +46,23 @@ const sortSketch = function (p) {
]);
}
pixelArray.sort((a, b) => parseInt(a[0]) - parseInt(b[0]));
img.pixels = [];
for (pixel of pixelArray) {
img.pixels.push(...pixel);
pixelArray.sort((a, b) => a[0] - b[0]);
for (let px = 0; px < img.pixels.length; px += 4) {
img.pixels[px] = pixelArray[px / 4][0];
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);
img.updatePixels();
for (let x = 0; x < img.width; x += 1) {
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) {