Difference between revisions of "Template:ColorMath"

From Second Life Wiki
Jump to navigation Jump to search
m (The purpose of this template is to populate the hex and)
 
m (Pfft. Should have pressed Preview first. Sorry about that.)
 
(11 intermediate revisions by 3 users not shown)
Line 7: Line 7:
{{#vardefine:int|{{LSL Hex/Parse|{{#var:hex}}}}}}
{{#vardefine:int|{{LSL Hex/Parse|{{#var:hex}}}}}}


{{#vardefine:vector|<{{#expr:(({{#var:int}} / 256 / 256) mod 256) / 255 rounding {{{round|3}}})}}, {{#expr:(({{#var:int}} / 256 ) mod 256) / 255 rounding {{{round|3}}})}}, {{#expr:({{#var:int}} mod 256) / 255 rounding {{{round|3}}})}}>}}
{{#vardefine:x|{{#expr:(({{#var:int}} / 256 / 256) mod 256) / 255 round {{{round|3}}}}}}}
{{#vardefine:y|{{#expr:(({{#var:int}} / 256 ) mod 256) / 255 round {{{round|3}}}}}}}
{{#vardefine:z|{{#expr:({{#var:int}} mod 256) / 255 round {{{round|3}}}}}}}


|
|


{{#vardefine:hex|{{LSL Hex/Write|{{#expr:({{{1|0}}} mod 256) * 256 * 256}}|chars=2}}{{LSL Hex/Write|{{#expr:({{{2|0}}} mod 256) * 256}}|chars=2}}{{LSL Hex/Write|{{#expr:({{{3|0}}} mod 256)}}|chars=2}}}}
{{#vardefine:hex|{{LSL Hex/Write|{{#expr:{{{1|0}}} mod 256}}|chars=2}}{{LSL Hex/Write|{{#expr:{{{2|0}}} mod 256}}|chars=2}}{{LSL Hex/Write|{{#expr:({{{3|0}}} mod 256)}}|chars=2}}}}


{{#vardefine:vector|<{{#expr:({{{1|0}}} mod 256) / 255 rounding {{{round|3}}})}}, {{#expr:({{{2|0}}} mod 256) / 255 rounding {{{round|3}}})}}, {{#expr:({{{3|0}}} mod 256) / 255 rounding {{{round|3}}})}}>}}
{{#vardefine:x|{{#expr:({{{1|0}}} mod 256) / 255 round {{{round|3}}}}}}}
{{#vardefine:y|{{#expr:({{{2|0}}} mod 256) / 255 round {{{round|3}}}}}}}
{{#vardefine:z|{{#expr:({{{3|0}}} mod 256) / 255 round {{{round|3}}}}}}}


}}}}<noinclude>
}}


{{#vardefine:padding|{{#expr:{{{round|3}}}+2}}}}
{{#vardefine:vector|&lt;{{padright:{{#var:x}}{{#ifexpr:{{#len:{{#var:x}}}} = 1|.}}|{{#var:padding}}|0}}, {{padright:{{#var:y}}{{#ifexpr:{{#len:{{#var:y}}}} = 1|.}}|{{#var:padding}}|0}}, {{padright:{{#var:z}}{{#ifexpr:{{#len:{{#var:z}}}} = 1|.}}|{{#var:padding}}|0}}&gt;}}
}}<noinclude>
Parameters:
Parameters:
* 1 = r [0, 255]
* 1 = r [0, 255]
* 2 = g [0, 255]
* 2 = g [0, 255]
* 3 = b [0, 255]
* 3 = b [0, 255]
* hex = #rrggbb - "#" is optional
* hex=rrggbb ('''no''' "{{code|#}}" prefix is allowed on this template!)


Output:
Output:
* <nowiki>{{#var:hex}}</nowiki> - html style color integer, without "#"
* <nowiki>{{#var:hex}}</nowiki> - html style color integer, without "#"
* <nowiki>{{#var:vector}}</nowiki> - LSL style vector with values [0, 1]
* <nowiki>{{#var:vector}}</nowiki> - LSL style vector with values [0, 1]
{{ColorMath|hex=001f3f}} - {{#var:hex}} - {{#var:vector}}
{{ColorMath|0|31|63}} - {{#var:hex}} - {{#var:vector}}
</noinclude>
</noinclude>

Latest revision as of 09:28, 14 October 2023

Parameters:

  • 1 = r [0, 255]
  • 2 = g [0, 255]
  • 3 = b [0, 255]
  • hex=rrggbb (no "#" prefix is allowed on this template!)

Output:

  • {{#var:hex}} - html style color integer, without "#"
  • {{#var:vector}} - LSL style vector with values [0, 1]
- 001f3f - <0.000, 0.122, 0.247>
- 001F3F - <0.000, 0.122, 0.247>