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 › changing a color of a specific object
Page Index Toggle Pages: 1
changing a color of a specific object (Read 491 times)
changing a color of a specific object
Nov 14th, 2006, 9:07am
 
Hi
I'm totally new to processing and completly lost.

In my project, I have a timeline at the top of the page and a building in the middle.
The building is separated into 3 parts.
I want to change the colors of the 3 parts when I touch the timeline, but I can't find the way to do this.
This might be a really basic question, but can someone give me advice?
Thanks.

hapapa
Re: changing a color of a specific object
Reply #1 - Nov 23rd, 2006, 9:44am
 
With this sort of thing, it is probably best to save your states using an Object-Oriented approach. Using plain-ole Java constructs, you could have something like this:

Code:

Class BuildingSegment
color segment_color;
float px, py; //x and y position
// other relevant fields

public BuildingSegment(){...}

void setColor(color c){segment_color = c;}

void render()
{
fill(this.segment_color);
rect(...); //etc...
}
}


Within the body of your code, you would instantiate three BuildingSegment objects, and call render() for each of them within the draw loop. Every time the timeline is touched, or whatever happens, you can call the function setColor, or whatever you come up with to modify the rendering of the building.

If this approach seems kind of weird with the OO stuff, you can always set three global color variables and create functions that change them accordingly.

Anyway, I hope this helps to at least point you in the right direction. If you posted more of your code, I could be able to get a better handle on what you're trying to do, if you need more help.
Page Index Toggle Pages: 1