Hello. I'm new to processing. I'm trying to draw an image to the window pixel by pixel with a short delay between each pixel. My code is below. I feel like this should work based on other forum posts I've seen but I just get a gray square when I run it. Thanks for any help!
- PImage img0;
- int y;
- int z;
- String[] images = {
- "1.jpg",
- "2.jpg",
- "3.jpg",
- };
- void setup() {
- size(200,133);
- }
- void myDelay(int ms) {
- try {
- Thread.sleep(ms);
- }
- catch(Exception e){}
- }
- void draw() {
- loadPixels();
- y = random(0,3);
- // turn float into int (there must be a better way to do this)
- z = int(y * 1);
- img0 = loadImage(images[z]);
- img0.loadPixels();
- for (int y = 0; y < height; y++) {
- for (int x = 0; x < width; x++) {
- int loc = x + y*width;
- // The functions red(), green(), and blue() pull out the 3 color components from a pixel.
- float r = red(img0.pixels[loc]);
- float g = green(img0.pixels[loc]);
- float b = blue(img0.pixels[loc]);
- color c = color(r,g,b);
- set(x,y,c);
- myDelay(100);
- }
- }
- }
1