i basicly want to make what draw() does when you don't include background().. an image where you can draw shapes (with alpha and smooth)
I made this little sketch which is sortof supposed to append one image to another.. the biggest problem i'm having is making a PGraphics object to draw to.. just like g.
The only class i can make it work with is PGraphics3, which doesn't support smooth, and looks like has problems with fill as well (just try it out in my code)
Any leads on how i could work with PGraphics objects as I do with the g object?
G3.ellipse, with fill, stroke and smooth, basicly, preferably not PGraphics3 object
Code:
PImage G;
PGraphics3 G3;
void setup()
{
size(200,200);
framerate(10);
smooth();
G = new PImage(width,height);
G3 = new PGraphics3(width,height,null);
}
void draw()
{
G3.beginFrame();
G3.pixels = new int[width*height];
G3.stroke(255,10);
G3.ellipse(random(width),random(height),10,10);
G3.endFrame();
background(255,0,0);
G = append(G,G3);
image(G,0,0);
//if(mousePressed) image(G3,0,0);
}
PImage append(PImage src, PImage img)
{
if(src.pixels.length != img.pixels.length) return src;
for(int i = 0; i < src.width; i++){
for(int j = 0; j < src.height; j++){
color cSrc = src.pixels[i+j*src.width];
color cNew = img.pixels[i+j*src.width];
float rS = red(cSrc);
float rN = red(cNew);
float gS = green(cSrc);
float gN = green(cNew);
float bS = blue(cSrc);
float bN = blue(cNew);
float aS = alpha(cSrc);
float aN = alpha(cNew);
if(aN > 0) // comment out if sentence for cool effect
src.pixels[i+j*src.width] = cSrc+cNew; //blend(cSrc,cNew,ADD);
}
}
src.updatePixels();
return src;
}