about summary refs log tree commit diff stats
path: root/lib/Octans/Hex2RGB.rakumod
diff options
context:
space:
mode:
authorAndinus <andinus@nand.sh>2022-01-12 12:42:38 +0530
committerAndinus <andinus@nand.sh>2022-01-12 12:42:38 +0530
commit25f65f212c210638d15d73c0c8dfe1fc08bd96a2 (patch)
tree48a98fcd1b0440465eca8e3d8684a306605c3b28 /lib/Octans/Hex2RGB.rakumod
parent59d0cd4fbb98cffa28120714b87008573777f429 (diff)
downloadoctans-25f65f212c210638d15d73c0c8dfe1fc08bd96a2.tar.gz
Add visualize feature using Cairo
This takes parts from Fornax: https://github.com/andinus/fornax

Each step is visualized and a video solution is generated.
Diffstat (limited to 'lib/Octans/Hex2RGB.rakumod')
-rw-r--r--lib/Octans/Hex2RGB.rakumod10
1 files changed, 10 insertions, 0 deletions
diff --git a/lib/Octans/Hex2RGB.rakumod b/lib/Octans/Hex2RGB.rakumod
new file mode 100644
index 0000000..72cb848
--- /dev/null
+++ b/lib/Octans/Hex2RGB.rakumod
@@ -0,0 +1,10 @@
+# This module has been adapted from Fornax::Hex2RGB.
+
+#| Takes hex value and returns RGB equivalent.
+sub hex2rgb(Str $hex --> List) is export {
+    # Skip the first character, group each by 2 and parse as base 16.
+    # Divide by 255 to return value between 0, 1.
+    $hex.comb.skip.rotor(2).map(
+        *.join.parse-base(16) / 255
+    )>>.Rat
+}