This is kind of a weird question, please forgive the longwinded explanation:
There must be an easier way to do this. I’m trying to save each frame (as it appears on the screen) and make a movie, but the frame captures that processing saves don’t look like the window, and I think because I added transparency to each pixel!
This code is just a super basic, modified Open Simplex Noise example. Since a new noise layer is added on top of the previous one, each frame I save needs to contain all the previous frames as layers as well (I think). This is all because save() and saveFrame() don’t capture what the screen actually looks like!
I created an array of PImage objects to store the images, but I’m not sure how to save them on top of each other?
If that approach is not possible then I was thinking I might have to iterate over every pixel from every previous frame and layer them all on top of each other? I feel like I must be missing something though…
Any advice or input would be greatly appreciated!
// https://thecodingtrain.com/CodingChallenges/137-4d-opensimplex-noise-loop
int totalFrames = 360;
int counter = 0;
boolean record = true;
boolean fourD = false;
PImage[] layeredImages = new PImage[360];
PImage img;
//zoom
float increment = 0.03;
// Just for non-looping demo
float zoff = 0;
OpenSimplexNoise noise;
void setup() {
size(640, 360);
img = createImage(640, 360, ARGB);
noise = new OpenSimplexNoise();
}
void draw() {
float percent = 0;
if (record) {
percent = float(counter) / totalFrames;
} else {
percent = float(counter % totalFrames) / totalFrames;
}
render(percent, counter);
if (record) {
layeredImages[counter] = img;
layeredImages[counter].save("img/"+nf(counter, 3)+".png");
if (counter == totalFrames-1) {
exit();
}
}
counter++;
}
void render(float percent, int counter) {
float angle = map(percent, 0, 1, 0, TWO_PI);
float uoff = map(sin(angle), -1, 1, 0, 2);
float voff = map(sin(angle), -1, 1, 0, 2);
float xoff = 0;
img.loadPixels();
for (int x = 0; x < width; x++) {
float yoff = 0;
for (int y = 0; y < height; y++) {
float n;
if (fourD) {
// 4D Open Simplex Noise is very slow!
n = (float) noise.eval(xoff, yoff, uoff, voff)*255+100;
} else {
// If you aren't worried about looping run this instead for speed!
n = (float) noise.eval(xoff, yoff, zoff)*255+100;
}
//float bright = n > 0 ? 255 : 0;
img.pixels[x + y * width] = color(n, n, n, 3);
yoff += increment;
}
xoff += increment;
}
img.updatePixels();
image(img, 0, 0);
zoff += increment;
}