Theme Color convertion

  • 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.

  • Try Construct 3

    Develop games in your browser. Powerful, performant & highly capable.

    Try Now Construct 3 users don't see these ads
  • 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.

  • 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 :)

  • 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) :

    <?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>[/code:li0srjn9]
  • jhice: since the original post the system expression rgb(r,g,b) has been added in Construct 2.

    [quote:7zcd3gzl]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.

  • 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 : scirra.com/forum/viewtopic.php

    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 ^^)

Jump to:
Active Users
There are 1 visitors browsing this topic (0 users and 1 guests)