We closed this forum 18 June 2010. It has served us well since 2005 as the ALPHA forum did before it from 2002 to 2005. New discussions are ongoing at the new URL http://forum.processing.org. You'll need to sign up and get a new user account. We're sorry about that inconvenience, but we think it's better in the long run. The content on this forum will remain online.
IndexProgramming Questions & HelpSyntax Questions › creating an image from two others
Page Index Toggle Pages: 1
creating an image from two others (Read 174 times)
creating an image from two others
Mar 20th, 2009, 7:22pm
 
how do you do this?
for example, in the code below i have created to squares as images: but i would like them to be created together (within) one single image...

s




Quote:
size(150,150);

PImage img1 = createImage(66, 66, RGB);
img1.loadPixels();
for (int i = 0; i < img1.pixels.length; i++) {
  img1.pixels[i] = color(0, 90, 102);
}
img1.updatePixels();

PImage img2 = createImage(66, 66, RGB);
img2.loadPixels();
for (int i = 0; i < img2.pixels.length; i++) {
  img2.pixels[i] = color(255, 90, 0);
}
img2.updatePixels();


image(img1, 17, 17);
image(img2, 50, 50);


Re: creating an image from two others
Reply #1 - Mar 20th, 2009, 9:51pm
 
I am unsure of what you want to do exactly.
But filling pixels like you do is extremely inefficient...
Perhaps you want to create a PGraphics instead, and draw there with rect() and such.
Re: creating an image from two others
Reply #2 - Mar 20th, 2009, 11:12pm
 
It's a question about being unable to understand how to limit the effect of his loops to a rectangular sub-region within the pixels[] array, while iterating over that array in a single 0..length-1 loop.

Which is more of a basic programming issue than anything truly Processing related.

You're right, though, he should really learn how to use Processing's drawing primitives on the regular screen canvas before messing around with pixel-pushing in PImage objects.

Sam, I would encourage you to go through all the examples on the Learning part of this site (http://processing.org/learning/), and read them until you understand them.  Somewhere along the way you'll get the knack of how your ideas translate into hands-on use of Processing's facilities.  Also helpful is to look at the great stuff on openprocessing.org; there's lots of fun and really pretty sketches there, with code you can look at to learn from.
Page Index Toggle Pages: 1