markwendell
YaBB Newbies
Offline
Posts: 2
img content update
Aug 8th , 2005, 8:08pm
I'm trying to change the contents of an image in the draw loop, but I guess my understanding of the PImage format is lacking. For example, I want to do a variation of the noise3D example. Rather than alter the display pixels directly as in the example, I want to store the noise values in an image var and then display that image. Here's my version of that example: ------------- PImage img; float increment = 0.01; float zoff = 0; float zinc = 0.2; void setup() { img = loadImage("blah.jpg"); int xsize = img.width; int ysize = img.height; size(xsize, ysize); background(0); // black out img loadPixels(); for (int i=0; i<(width*height); i++) { img.pixels[i] = color(0,0,0); } updatePixels(); } void draw() { // load up img with new values loadPixels(); float xoff = 0.0f; for (int x = 0; x < width; x++) { xoff += increment; float yoff = 0.0f; for (int y = 0; y < height; y++) { yoff += increment; float bright = noise(xoff,yoff,zoff)*255; img.pixels[x+y*width] = color(bright,bright,bright); } } updatePixels(); // display img image(img,0,0); zoff += zinc; } -------------- My question is, why doesn't this update? I'm under the impression that I should be able to use the "img.pixels[index] = whatever" command to change the contents of img in the draw loop. Just to clarify, what I'd like to do is: a) initialize an image variable b) change the contents of that image (such as with noise) c) display that image d) loop back to b. Any help is appreciated! Mark