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 › Simple question- fill(), structure and objects
Page Index Toggle Pages: 1
Simple question- fill(), structure and objects? (Read 669 times)
Simple question- fill(), structure and objects?
Nov 30th, 2009, 2:32am
 
Heya. I've been having a blast learning processing but am having trouble understanding a relatively simple thing.

I don't quite understand how to fill separate shapes (rect, ellipse, etc) with separate fills.

For example: in the code below, there is a rect() that should be filled with white, and another rectangle that should be filled with semi transparent black each time the draw loop completes. In theory, this should create a motion trail effect, but instead it applies one of the fill()s to all rect()s being drawn.

I started out doing everything in the draw loop, then moved things out to separate custom functions, and am now trying to create the different shapes that get different fills with their own object classes.

Any help would be supremely appreciated! Thank you.

Code:
colorSquare sq1;
backGround bg1;

void setup(){
 size(800,600);
 noStroke();
 background(0);
 sq1 = new colorSquare();
 bg1 = new backGround();
}

void draw()
{
 sq1.display();
 bg1.bgDisplay();
}

class colorSquare
{
 void display(){
   rect(mouseX, mouseY, 50, 50);
   fill (255);
   stroke(255);
 }
}

class backGround {
void bgDisplay(){
 rect(0,0,width,height);
 fill(0,0,0,20);
}
}



Similarly, if I try to rotate() just one of the objects, everything is effected. Totally stumped!

Re: Simple question- fill(), structure and objects?
Reply #1 - Nov 30th, 2009, 2:42am
 
fill() sets the fill colour, it doesn't actually do the filling.

and as such it needs to go before the rect()

examples: http://processing.org/reference/fill_.html
Re: Simple question- fill(), structure and objects?
Reply #2 - Nov 30th, 2009, 2:45am
 
and if you want to rotate only one thing you need to pushMatrix() beforehand and popMatrix() afterwards or else, yes, it affects everything.

see manpages for details.
Re: Simple question- fill(), structure and objects?
Reply #3 - Nov 30th, 2009, 3:11am
 
koogy wrote on Nov 30th, 2009, 2:42am:
fill() sets the fill colour, it doesn't actually do the filling.

and as such it needs to go before the rect()l



Ahh, I see now-
it basically prepares the fill color for whatever is drawn next
Re: Simple question- fill(), structure and objects?
Reply #4 - Nov 30th, 2009, 3:37am
 
Yes, and the same applies for noFill(), stroke(), noStroke(), rectMode(), ellipseMode() etc...  Everything following one of these will have the setting applied until it is changed by an appropriate function.  In a large programme you have to look out for these as they can often cause things to display differently than you intended...
Page Index Toggle Pages: 1