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 & HelpPrograms › Star Making Help
Page Index Toggle Pages: 1
Star Making Help (Read 2352 times)
Star Making Help
Aug 17th, 2005, 5:16pm
 
Hello,
this is my first processing script,
I would like to create images like this:
http://www.magueule.net/processing
(i made this in photoshop by layering outputs of the previous version of the script that was just saving a TIFF when you clicked)

the center of the star and the color are set by the mouse position,

Do you have any idea how i could make the whole image in Processing, clicking everytime I want to add a star (with a blending of the colors) to the background. and keep on going
I tried something but right now the program just gets stuck whenever I click

Thanks a lot

<code>

void setup() {

 size(200,200);
 rectMode(CENTER);


}

void draw()
{
 background(255);
 star(mouseX,mouseY);
}

void mousePressed()
{
// This part seems to be the problem
 color c = color(mouseX,mouseY,width-mouseX);
 loadPixels();
 for (int i=0; i<width; i++){
   for (int j=0; j<height; j++){
     color pixel = get(i,j);
     color newcolor = blend(pixel, c, BLEND);
     set(i,j,newcolor);
     updatePixels();
   }
 }
 
}



void star(int x, int y) {

 noStroke();
 fill(mouseX,mouseY,width-mouseX);
 beginShape(POLYGON);
 vertex(0,0);
 vertex(width/4,0);
 vertex(x,y);
 vertex(0,0);  
 endShape();

 beginShape(POLYGON);
 vertex(width/2,0);
 vertex(width*0.75,0);
 vertex(mouseX,mouseY);
 vertex(width/2,0);  
 endShape();

 
 // Top right corner

 beginShape(POLYGON);
 vertex(width,0);
 vertex(width,height/4);
 vertex(x,y);
 vertex(width,0);  
 endShape();
 
 beginShape(POLYGON);
 vertex(width,height/2);
 vertex(width,height*0.75);
 vertex(x,y);
 vertex(width,height/2);  
 endShape();
 
 // Bottom right corner

 beginShape(POLYGON);
 vertex(width*0.75,height);
 vertex(width,height);
 vertex(x,y);
 vertex(width*0.75,height);  
 endShape();

 beginShape(POLYGON);
 vertex(width/4,height);
 vertex(width/2,height);
 vertex(x,y);
 vertex(width/4,height);  
 endShape();

 
 // Bottom left corner

 beginShape(POLYGON);
 vertex(0,height/4);
 vertex(0,height/2);
 vertex(x,y);
 vertex(0,height/4);  
 endShape();

 beginShape(POLYGON);
 vertex(0,height*0.75);
 vertex(0,height);
 vertex(x,y);
 vertex(0,height*0.75);  
 endShape();
}
</code>
Re: Star Making Help
Reply #1 - Aug 18th, 2005, 1:55pm
 
The reason your code hangs is that you're calling updatePixels() for every single pixel on screen. move it to after the two for() loops.

However that won't fix the problem, because every frame you're clearing the screen with the background(255); call, that blank the sketch, so the blend will never be seen.

It shoudl be possible to achieve the result you want, but it might need the use of a PGraphics to draw the star to first, then blend that with the screen image.
Re: Star Making Help
Reply #2 - Aug 18th, 2005, 3:08pm
 
Thanks a lot for the advice,
I moved updatePixels()
I guess now the whole mousepressed part isnt really doing much as I see no blending, but at least it doesn't get stuck
and also tried moving the background to the setup() but then it draws every single star the mouse makes

I was thinking if it would make sense to save a tiff when mouse is pressed and reimport that into the background but it sounds like a complicated way to do it.

anyways.. I'll search for that Pgraphics stuff you mentioned, is that in an older version of processing ?
Re: Star Making Help
Reply #3 - Aug 18th, 2005, 3:13pm
 
PGraphics is current, just mostly undocumented. It can be used in the same way as saving the image, and re-loading it, just weithout having to save, and re-load things.
Re: Star Making Help
Reply #4 - Aug 18th, 2005, 4:26pm
 
PGraphics is current, just mostly undocumented

is there no documentation at all ?
If you have any clue where I could start searching please let me know

Thanks a lot
Re: Star Making Help
Reply #5 - Aug 18th, 2005, 8:45pm
 
Well PGraphics is the same thing as to what you normally draw to.. e.g when you do "BeginShape(QUADS); vertex(...)" etc, that's actually (effectively) going to a PGraphics object, just one you're inside of...

So you can do something like this:
Code:

PGraphics3 foo;

void setup()
{
size(200,200,P3D);
foo=new PGraphics3(200,200,null);
foo.defaults(); // <-- important!
}

void draw()
{
background(0);
foo.background(255);
foo.stroke(0);
foo.line(0,0,200,200);
foo.updatePixels(); // just in case
image(foo,100,0);
}


So you can prefix most drawing commands by the name of the PGraphics(2/3/GL) object, and they'll work on that, instead of the main screen, then just call image(thingy,x,y); and it'll copy the contents of the PGraphics object to screen.. so you could do blend(foo,0,0,width,height,BLEND); to blend the object and screen together.
Re: Star Making Help
Reply #6 - Aug 21st, 2005, 5:00pm
 
Thanks again for sharing this knowledge

I tried to put your advice into the script, its not there yet but I'm trying stuff around...

A couple questions have showed up though

- in your example you're using P3D. I don't really need 3D for what I'm trying to do so I tried a PGraphics2 . Then it seems the line

foo=new PGraphics2(200,200,null);

creates a problem. I'm wondering what the null part refers to...

- Why do you have to give the statement
PGraphics3 foo;
before everything else, even the setup() ?

- I t doesn't seem possible to do something like

foo.star(mouseX,mouseY);

when I defined all the polygons in the star() function...


I'll also try and find answers to these questions ( they must sound really dumb )
anyways, I really apreciate your help

thanks
Re: Star Making Help
Reply #7 - Aug 21st, 2005, 6:51pm
 
Some progress...

I did a little try with squares, if i get that to work, then i guess the stars or anything else will work..

so now its drawing a square on mousePressed, nice
but I've been trying the blending part and no way o get around it ...

<code>
PGraphics3 foo;
PGraphics3 IMG;


void setup() {

 size(300,300,P3D);
 foo = new PGraphics3 (300,300,null);
 foo.defaults();
 rectMode(CENTER);
 
 IMG = new PGraphics3 (300,300,null);
 IMG.defaults();
 IMG.background(255);

}


void draw()
{
 
 foo.noStroke();
 foo.background(IMG);
 foo.fill(mouseX,width-(mouseX+5),mouseY);
 foo.rect(mouseX,mouseY,100,100);
 image(foo,0,0);
 
}

void mousePressed()
{
 IMG.set(0,0,foo);
 IMG.blend(foo,0,0,0,0,BLEND);
 IMG.updatePixels();
 
}

<\code>

ps: how do i display code properly ?
Page Index Toggle Pages: 1