real time write/read loop for jpg
in
Programming Questions
•
2 years ago
Good evening all
I am getting to grips with processing through solving the various problems involved in writing a real-time jpg glitch script. Its quite bodged and really just synthesises a few different scripts from others more learned than me (and to whom I'm bloody grateful). What I'd like is for this to be truly real time though, so that I move away from the loop of images which I initiate with the script below. I guess so that instead of writing out and randomly editing the data from a series of 21 images which are then looped in draw(), I'd like to have a brand new image each time, never repeating. This would surely be simpler in that it needs only to follow the import/randomly-modify process with one image, which is then displayed and replaced by another. I guess it means moving parts of the function into draw? But if anybody could shed some light on how I do this I'd be most grateful. I guess its obvious that (if you want to get it working) you'll need to replace the image with your own if you don't already have a jpeg entitled "sgtpeppers.jpg" just lying around your hard drive. Here is what I have:
int numFrames = 21;
int frame = 00;
PImage[] images = new PImage[numFrames];
String img = "sgtpeppers"; //name
String ext = ".jpg"; //extension
void setup() {
jpgimport();
delay (5000);
size(360, 360);
frameRate(24);
for (int i = 0; i < 21; i++) {
images[i] = loadImage("sgtpeppers" + i + ".jpg");
}}
void draw() {
frame = (frame+1)%numFrames;
image(images[frame], 0, 0);
}
void jpgimport() {
for(int num = 0; num <= 21; num++) { // 10 iterations
byte[] data=loadBytes(img+ext); // load data
for(int i=0;i<200;i++) // 200 changes loop
{
int loc=(int)random(128,data.length); // integer btwn 128 and the file length
data[loc]=(byte)random(53); //
}
saveBytes(img+num+ext,data); //won’t overwrite
}
}
I look forward to help on this as I'm really enjoying learning processing.
take care
james
1