Active TopicsActive Topics  Display List of Forum MembersMemberlist  Search The ForumSearch  HelpHelp
  RegisterRegister  LoginLogin
PowerHome Programming
 PowerHome Messageboard : PowerHome Programming
Subject Topic: rgb PowerHome formula function Post ReplyPost New Topic
Author
Message << Prev Topic | Next Topic >>
dmoreno
Newbie
Newbie
Avatar

Joined: February 15 2002
Location: United States
Online Status: Offline
Posts: 31
Posted: December 02 2005 at 15:08 | IP Logged Quote dmoreno

Is there a way to covert 'rgb PowerHome formula function ' to HTML hex color? or even back to rgb(r,g,b)?
Back to Top View dmoreno's Profile Search for other posts by dmoreno
 
dhoward
Admin Group
Admin Group
Avatar

Joined: June 29 2001
Location: United States
Online Status: Offline
Posts: 4447
Posted: December 02 2005 at 22:38 | IP Logged Quote dhoward

Yep, sure is...use the ph_htmlcolor function. This function takes a PowerHome RGB color and converts it to a string in the form #XXXXXX.

A PowerHome RGB color is merely the following formula:

Red + (256 * Green) + (65536 * Blue)

where each of the colors is a value from 0 to 255. Once you have an RGB value, you can use math to extract it like so:

int(rgb / 65536)

gives you the blue component.

int((rgb - int(rgb / 65536) * 65536) / 256)

gives you the green component.

rgb - int( rgb / 65536) * 65536 - int((rgb - int(rgb / 65536) * 65536) / 256) * 256

gives you the red component.

That last one gets a little long and messy. The above formulas are based solely upon standard math. We can also get the values by using bitwise ANDing as demonstrated in the formulas below:

ph_and(rgb,16711680) / 65536

gives you the blue

ph_and(rgb,65280) / 256

gives you the green

ph_and(rgb,255)

gives you the red.

Hope this helps,

Dave.
Back to Top View dhoward's Profile Search for other posts by dhoward Visit dhoward's Homepage
 

If you wish to post a reply to this topic you must first login
If you are not already registered you must first register

  Post ReplyPost New Topic
Printable version Printable version

Forum Jump
You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot delete your posts in this forum
You cannot edit your posts in this forum
You cannot create polls in this forum
You cannot vote in polls in this forum