tedpallas
YaBB Newbies
Offline
Posts: 4
Help with PImage
Apr 7th , 2008, 9:18pm
So - Thanks in advance to everyone who takes a look! I've written a program that draws some rectangles on the screen, using constrained randomness to make an attractive image. Here's the code: void setup() { size (screen.width, screen.height); smooth(); background(255, 255, 255); } float mult = 0; float multY = 0; float posX = -900; float posY = 0; float bgcount = 0; void draw() { frameRate (24); //background (155, 157, 255); if (mousePressed == true) { fill (155, 256, 155) ; } else { fill (240, 255, 155); } for (float i = 0; i < 10; i++) { noCursor(); float drawX = mouseX; float drawY = mouseY; float x = random (1, 900); float color1 = random (120, 200); float color2 = random (60, 120); float color3 = random (180, 200); float coltransp = (random (20, 90)); //stroke(color1, color2 ,255 ); stroke(255); float rectwidth = (sin (random (1, 360))) * 150; fill (color1, color2, 255, coltransp); rect (posX + x, posY + x, rectwidth, rectwidth*.7); //fill (100 + x + 30 * 1.02, 155, 255); //rect (i + x + 20, i, i+x, i); //stroke (100 + x, 120 + x, 255); //line (0, 0, mouseX, mouseY); mult = (mult + 15); multY = (multY + 1); bgcount = bgcount + 1; if (multY >= 400) { posX = posX + (random (1, 60)); posY = random (-100, 0); mult = 0; multY = 0; } if (posX >= 1280) { posX = 0; posY = random (-100, 0); bgcount = random (1, 40); } //if (bgcount >= 10) { //background (155, 157, 255); //bgcount = 0; //redraw (); //} } } if (keyPressed = true) { noLoop(); redraw (); } So now I want it to take color data from an array loaded with pixel data from the image. Here's what I've got so far: void setup() { size (screen.width, screen.height); smooth(); background(255, 255, 255); } PImage img = loadImage("OliviaInMadrid.jpg"); int dimension; for (int i=0; dimension; i+=2) { img.pixels[i] = color(0, 0, 0); } updatePixels(); image(img, 0, 0);` float mult = 0; float multY = 0; float posX = -900; float posY = 0; float bgcount = 0; void draw() { frameRate (24); //background (155, 157, 255); if (mousePressed == true) { fill (155, 256, 155) ; } else { fill (240, 255, 155); } for (float i = 0; i < 10; i++) { noCursor(); float drawX = mouseX; float drawY = mouseY; float x = random (1, 900); float color1 = random (120, 200); float color2 = random (60, 120); float color3 = random (180, 200); float coltransp = (random (20, 90)); //stroke(color1, color2 ,255 ); stroke(255); float rectwidth = (sin (random (1, 360))) * 150; fill (color1, color2, 255, coltransp); rect (posX + x, posY + x, rectwidth, rectwidth*.7); //fill (100 + x + 30 * 1.02, 155, 255); //rect (i + x + 20, i, i+x, i); //stroke (100 + x, 120 + x, 255); //line (0, 0, mouseX, mouseY); mult = (mult + 15); multY = (multY + 1); bgcount = bgcount + 1; if (multY >= 400) { posX = posX + (random (1, 60)); posY = random (-100, 0); mult = 0; multY = 0; } if (posX >= 1280) { posX = 0; posY = random (-100, 0); bgcount = random (1, 40); } //if (bgcount >= 10) { //background (155, 157, 255); //bgcount = 0; //redraw (); //} } } if (keyPressed = true) { noLoop(); redraw (); } It doesn't appear to do anything. Does anyone have some insight? This (that is, learning processing) is my first interaction with Java/programming since I was taught Pascal 8 years ago, in my freshman year of high school, and I'm having a hell of a time figuring out what's going on. The image code, by the way, is straight off the reference. Thanks again for all your help.