Animated pixel array manipulation
in
Programming Questions
•
7 months ago
I would like to transform one image into another by copying the pixels from pixel array to pixel array. This works just fine, but I would like to be able to see this happening. Right now I just see the end result after a while. So, how can I do some sort of an updatePixels() inside the draw() loop?
- PImage bikeImg;
- PImage carImg;
- boolean firstRun = true;
- void setup() {
- size(600, 409);
- background(255);
- bikeImg = loadImage("bike.jpg");
- carImg = loadImage("car.jpg");
- }
- void draw() {
- if ( firstRun == true ) {
- firstRun = false;
- // renders the initial image
- image(carImg, 0, 0);
- // loads the current screen into the pixel array
- loadPixels();
- // loads the pixels for the next image
- carImg.loadPixels();
- for (int i=0; i<bikeImg.pixels.length; i++) {
- // overwrite the original image with the new one
- pixels[i] = bikeImg.pixels[i];
- updatePixels();
- }
- }
- }
1