~zodiacsohma/armagetronad/arma_colors_to_html_codes

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
<html>
        <head>
                <title>Armagetron Advanced - Colors to Html</title>
                <link rel="stylesheet" type="text/css" href="changing_colors.css">
        </head>
        <body style="color: #000000;">
<?php
###################################################################
######  Convert Armagetron color codes into     HTML format  ######
###################################################################
######  Script by: LOVER$BOY                                 ######
######  Version: 2.0                                         ######
######  Description: Please leave this header. Thanks!       ######
######  Contact: zodiacsohma1@gmail.com                      ######
###################################################################

$converted = false;
if (isset($_POST["convert"]))
{
    $text = $_POST["text"];

    //$text = htmlentities('0xff0000Alpha 0x00ffffProject 0x33ebff<0x78ff29<0xff3c1f<  0xff0000LOVER$BOYs 0xff301eH0xffbf1ee0xb1ff1el0x1eff21l0x14ffacs 0xff301eR0xffb41fa0xcfff1ec0x58ff29i0x28ff76n0x29fff0g  0x33ebff>0x78ff29>0xff3c1f>');

    //echo "Searching String: Alpha Project <<< LOVER\$BOYs Hells Racing!<br />\n";

?>
        <pre style="background: #000000 url(./message_background.png) repeat fixed center; padding: 10px; font-size:16px; color: #f9f9f9;">
<?php

    $pos = strpos($text, "0x");
    $prevpos = 0;

    $line = "";

    //  if one exists, store the beginning text BEFORE the process
    if ($pos !== false)
        $line .= substr($text, $prevpos, $pos - $prevpos);

    while ($pos !== false)
    {
        //  get color code from function
        $color = extractColorCode($text, $pos);

        //  store previous position and continue
        $prevpos = $pos;

        //  look up next occurance of color
        $pos = strpos($text, "0x", $pos);

        //  checking whether there is anymore to do
        if ($pos === false)
            //  if not, then store the rest of the string from previous color code
            $str = substr($text, $prevpos);
        else
            $str = substr($text, $prevpos, $pos - $prevpos);

        //  finally, output the string for each parsing
        $line .= '<span style="color: #'.$color.';">'.$str.'</span>';
    }

    echo $line;
    $converted = true;
?>
        </pre>
<?php
}
?>
                Enter your color coded arma string into the box and click "Convert"
                <form method="post">
                <table>
<?php
if ($converted)
{
?>
                    <tr><td><b>Display:</b><br /><textarea name="display" class="text_box" cols="90" rows="12"><?php echo $line; ?></textarea></td></tr>
                    <tr><td><b>Original:</b><br /><textarea name="text" class="text_box" cols="90" rows="12"><?php echo $_POST["text"]; ?></textarea></td></tr>
<?php
}
else
{
?>
                    <tr><td><textarea name="text" class="text_box" cols="90" rows="12">Your color coded text go here</textarea></td></tr>
<?php
}
?>
                    <tr><td><input type="submit" name="convert" value="Convert"></td></tr>
<?php

function CTR($x)
{
    return ($x / 255.0);
}

function extractColorCode($str, &$pos)
{
    //  list of valid chars
    $validChars = array('0','1','2','3','4','5','6','7','8','9','a','b','c','d','e','f');

    $colorcode = "";

    //  increment twice to avoid 0x
    $colorcode = substr($str, $pos + 2, 6);
    $pos += 8;
    
    if ($colorcode == "RESETT")
        $colorcode = "f9f9f9";

    $r = $g = $b = 0;

    $r_hex = hexdec($colorcode[0]) *16 + hexdec($colorcode[1]);
    $g_hex = hexdec($colorcode[2]) *16 + hexdec($colorcode[3]);
    $b_hex = hexdec($colorcode[4]) *16 + hexdec($colorcode[5]);

    $r = CTR($r_hex);
    $g = CTR($g_hex);
    $b = CTR($b_hex);

    if (isDark($r, $g, $b))
        $colorcode .= "; background: #f9f9f9";

    return $colorcode;
}

function isDark($r, $g, $b)
{
    $minR = $minB = $minG = 0.5;
    $minTotal = 0.7;

    return ( $r < $minR && $g < $minG && $b < $minB ) || $r+$g+$b < $minTotal;
}
?>
            </table>
        </form>
    </body>
</html>