• Post Reply Bookmark Topic Watch Topic
  • New Topic

generating colors  RSS feed

 
Yahya Elyasse
Ranch Hand
Posts: 510
Eclipse IDE Google Web Toolkit Java
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
hello all,

I'm trying to find a solution to the following problem :

suppose i have a variable Integer n from 1 to max .

I want to be able to generate an array of colors verifying this condition :

The colour should correspond to the 'number' attribute, with 'number'=1 being 100% green and 'number'=max being 100% red.
and for any given nmber between 1 and max we should find orresponding color (mixture of red and green).

can someone give me a hint (code will be very appreciated) ?

thanks
 
Stuart Gray
Ranch Hand
Posts: 410
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Colours are made of red, green, and blue (RGB) components, each of which (in 24-bit colour) can have values from 0 to 255 inclusive. The higher the value, the 'more' of that colour is available.

To generate your colours, start green at 255 (i.e. 100%), and red and blue at 0. Each iteration of your loop, reduce the green component and increase the red component. Leave the blue component alone.

The amount you increase or decrease by each iteration can be found with the formula: increment = 255/(no of colours - 1)

Hope this helps.
 
Don't get me started about those stupid light bulbs.
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!