Theme Color convertion

Get help using Construct 2

Post » Thu Jul 04, 2013 11:25 pm

hello,

i don't know if it the good section for this,

but i'll would like to know if someone know how to convert rgb to color format in the xml theme file.

example: color (245,245,245) => 16119285

How to reach 16119285 with (245,245,245) and (245,245,245) with 16119285 ?




Thks in advance, and sorry for my poor English.
B
38
S
13
G
4
Posts: 152
Reputation: 5,147

Post » Fri Jul 05, 2013 1:54 pm

I did some tests with the rgb function and I managed to get the formula:

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

In your case: 245 + (245 * 256) + (245*65536)=
              245 + 62720 + 16056320 =
              16119285

Hope it helps.
B
6
S
1
Posts: 17
Reputation: 459

Post » Fri Jul 05, 2013 3:37 pm

i don't realized that is an RGB to long.


Color = 16119285

RED = Color - (BLUE * 65536) - (GREEN * 256)
GREEN = (Color - (BLUE * 65536)) : 256
BLUE = Color : 65536


or

RED = Color % 256
GREEN = (Color : 256) % 256
BLUE = Color : 65536


and of course :

RED + (GREEN*256) + (BLUE*65536)

thks a lot Rising :)anata2013-07-05 15:42:12
B
38
S
13
G
4
Posts: 152
Reputation: 5,147

Post » Wed Feb 26, 2014 11:37 am

Up ^^

Thanks for the tip.

For lazy people, a simple PHP script to convert color (up to you to convert it in any other language :p) :

Code: Select all
<?php
if($_POST) {
   $r = $_POST['r'];
   $g = $_POST['g'];
   $b = $_POST['b'];
   $converted = $r + $g*256 + $b*65536;
   echo "rgb($r,$g,$b) => $converted";
}
?>

<form action="" method="post">
   <p>R <input type="text" name="r" /></p>
   <p>G <input type="text" name="g" /></p>
   <p>B <input type="text" name="b" /></p>
   <p><input type="submit" value="Convert" /></p>
</form>

<p>Source : <a href="https://www.scirra.com/forum/viewtopic.php?f=160&t=85796&p=687135">Scirra forum : Theme Color convertion</a>
B
11
S
2
Posts: 69
Reputation: 819

Post » Wed Feb 26, 2014 12:16 pm

@jhice: since the original post the system expression rgb(r,g,b) has been added in Construct 2.

rgb(r, g, b)
Generate a single number containing a color in RGB format. This is useful for conditions or actions taking a color parameter.
Moderator
B
295
S
118
G
96
Posts: 7,327
Reputation: 71,246

Post » Wed Feb 26, 2014 12:23 pm

@Kyatric : the fact is that I have colors coming from a server, and wanted to evaluate "rgb(0,64,255)" but it's not possible (see here : https://www.scirra.com/forum/viewtopic.php?t=96262)

So I searched how to convert rgb to C2 internal value, to send it directly from my server and use it as is in the code. And the formula is not wrriten in the manual.

(dont know if we're on the same page ^^)
B
11
S
2
Posts: 69
Reputation: 819


Return to How do I....?

Who is online

Users browsing this forum: max2612, Yahoo [Bot] and 7 guests