Omnimaga

General Discussion => Technology and Development => Computer Programming => Topic started by: Snake X on May 11, 2011, 05:32:24 pm

Title: [solved] java applet color help
Post by: Snake X on May 11, 2011, 05:32:24 pm
So lets say I want to make a rainbow effect in a java applet.

Code: [Select]
Color rainbow = new Color(red,green,blue);

Where did the vars red green, blue come from? Lets just say they're declared random integers. That's not the important part right now.

Ok so now that I have the color 'rainbow' outside of a while/for loop, how would I change this already made color? I've tried looking for this forever but I cant find it! All I can find is Color <name> = new Color(r,g,b); nothing about changing existing colors. I can't have a color for every single value out there from 1-255 * 3 that'd be at least over 9000 color declarations.
Title: Re: java applet color help
Post by: Snake X on May 12, 2011, 07:04:39 am
anyone..?

Sorry for double posting but I didn't see any other way and I thought this thread would never get noticed if I didn't do anything :s
Title: Re: java applet color help
Post by: Jim Bauwens on May 12, 2011, 07:39:59 am
I'm not a Java programmer, but I'll try to help you anyway.

If I understand correctly, you want to change the color of "Color rainbow"?
Well, I think you just can issue
Code: [Select]
Color rainbow = new Color(red,green,blue);again, just with other values for red,green and blue.

Edit: if Color is a type, I think you can leave it away, as the var is already declared.
Title: Re: java applet color help
Post by: ruler501 on May 12, 2011, 08:55:10 am
could you  just take out the color part for when you are changing it?
Title: Re: java applet color help
Post by: m1ac4 on May 12, 2011, 10:00:32 am
A quick google search on the subject turned up this (http://www.leepoint.net/notes-java/algorithms/random/random-api.html) webpage.
So the code displayed that site that would generate a random 24-bit color would look like
Code: [Select]
Random r = new Random();
Color  c = new Color(r.nextInt(256), r.nextInt(256), r.nextInt(256));
Title: Re: java applet color help
Post by: Snake X on May 12, 2011, 06:23:43 pm
edit: I got it. Thanks for all your help :D