1 Replies - 6535 Views - Last Post: 22 May 2011 - 09:11 PM Rate Topic: -----

#1 elisemarie15  Icon User is offline

  • New D.I.C Head

Reputation: 0
  • View blog
  • Posts: 1
  • Joined: 22-May 11

Gridworld critter code; changing colors?

Posted 22 May 2011 - 09:07 PM

I don't have a specific code to put up, but i was wondering how i would go about doing this:

I have a critter that changes its neighbors to be any random color EXCEPT red. I have code to change to a random color, but I'm unsure of how to go about checking to see if the color is red and how to change it to another random color. Here is my code so far:

for (Actor a : actors)
{
int r= (int) (Math.random()*256);
int g= (int) (Math.random()*256);
int b= (int) (Math.random()*256);
a.setColor(new Color(r,g,B ));
}

This post has been edited by elisemarie15: 22 May 2011 - 09:08 PM


Is This A Good Question/Topic? 0
  • +

Replies To: Gridworld critter code; changing colors?

#2 macosxnerd101  Icon User is online

  • Self-Trained Economist
  • member icon




Reputation: 10397
  • View blog
  • Posts: 38,467
  • Joined: 27-December 08

Re: Gridworld critter code; changing colors?

Posted 22 May 2011 - 09:11 PM

Moved to GridWorld.

You can compare the new Color object to Color.RED using the Color equals() method. You could also look at the constants in the Color class and store those in a Color[], simply selecting a random element from the array.
Was This Post Helpful? 0
  • +
  • -

Page 1 of 1