Forums Archived

The forums are being archived. See this topic for more information.

Question about ColorRGB

Get help and support with Rubygame

Question about ColorRGB

Postby cgmjr » Mon Apr 05, 2010 1:48 am

I need to write a very subtle, but precise color onto a background. The decimal parms for ColorRGB are throwing me. The doc for ColorRGB#new advises that:
Code: Select all
All color components range from 0.0 to 1.0.


Now I need rgb [0,15,255]. How do I convert that to the decimals? I'm assuming just divide by 255. That means [0,15,255] becomes [0.0,0.058824,1.0]. Is that right?

Is there a constructor that will just take the traditional [0,15,255]?

Many thanks.
User avatar
cgmjr
 
Posts: 39
Joined: Mon Jan 11, 2010 6:41 am

Re: Question about ColorRGB

Postby jacius » Mon Apr 05, 2010 5:46 am

cgmjr wrote:Now I need rgb [0,15,255]. How do I convert that to the decimals? I'm assuming just divide by 255. That means [0,15,255] becomes [0.0,0.058824,1.0]. Is that right?

That is correct.

cgmjr wrote:Is there a constructor that will just take the traditional [0,15,255]?

Looks like I forgot to add documentation for it, but ColorRGB.new_from_sdl_rgba will do the trick:

Code: Select all
>> Rubygame::Color::ColorRGB.new_from_sdl_rgba( [0,15,255] )
=> #<Rubygame::Color::ColorRGB [0.0, 0.0588235294117647, 1.0, 1.0]>
User avatar
jacius
Site Admin
 
Posts: 131
Joined: Fri Feb 06, 2009 11:13 pm

Re: Question about ColorRGB

Postby cgmjr » Mon Apr 05, 2010 1:26 pm

Sweet! That's the ticket.

May I say, jacius, that Rubygame is great! I'm having a blast still, and I've found a means to accomplish everything I've needed so far. You've provided us a great framework, both predictable and understandable. I also appreciate how you continue to support it, and keep an eye on these forums.

I'm moving into some traditional UI needs for little project, and I'll post elsewhere with a couple of questions.
User avatar
cgmjr
 
Posts: 39
Joined: Mon Jan 11, 2010 6:41 am


Return to Help & Support

Who is online

Users browsing this forum: Bing [Bot] and 1 guest

cron