Hello I am new to the processing software I found a code on github but I would have liked to add the function of saving the image for each image made by the algorithm can you help me please thank you because I do not can’t save my images the code is
import processing.pdf.*;
PImage img;
PImage displayImg;
// change this to get a bigger final image
int scale = 4;
float xScreen, yScreen;
float randomPixel;
color pixelColor;
int totalPoints = 0;
void setup() {
size(600, 800);
//size(2400, 3200, PDF, “womanDots.pdf”);
background(255);
//work in Hue Saturation Brightness instead of RGB, since the image is b/w
//with a max value of 100
colorMode(HSB, 100);
fill(255);
img = loadImage(“ALE.jpg”);
displayImg = createImage(img.width * scale, img.height * scale, RGB);
//make the display image white initially
for (int i=0; i<displayImg.pixels.length; i++) {
displayImg.pixels[i] = color(0, 0, 100);
}
//this only needs to be created once
//beginRecord(PDF, “womanDots.pdf”);
createDotImage();
}
void draw() {
// we want to move the image around on the screen and see it in full even if it’s a few times larger than the canvas
rect(0, 0, width, height);
xScreen = map(mouseX, 0, width, width - displayImg.width, 0);
yScreen = map(mouseY, 0, height, height - displayImg.height, 0);
image(displayImg, xScreen, yScreen);
}
void createDotImage() {
//loop through all the pixels of the original image and create dots in a square for each of them
// how many dots depends on how bright / dark the pixel is
for (int y=0; y<img.height; y++) {
for (int x=0; x<img.width; x++) {
pixelColor = img.get(x, y);
//now use the color information in a square that's scale*scale pixels large in the displayImg
for (int j=0; j<scale; j++) {
for (int i=0; i<scale; i++) {
randomPixel = random(100);
//pixels need to be black or white depending on whether they pass a certain threshold
if (brightness(pixelColor) < randomPixel) {
displayImg.set((x*scale)+i, (y*scale)+j, color(0, 0, 0));
totalPoints++;
}
}
}
}
}
println("Total number of points = " + totalPoints);
//image(displayImg, 0, 0);
//endRecord();
}