summaryrefslogtreecommitdiff
path: root/lib/randbg.pm
diff options
context:
space:
mode:
authorJules Laplace <carbon@melanarchy.org>2013-08-02 17:14:41 -0500
committerJules Laplace <carbon@melanarchy.org>2013-08-02 17:14:41 -0500
commite9192b3d42660a5781101df4357d276318151e8a (patch)
tree059eb6ace6147cf9559af74ed1ab5e221c80e280 /lib/randbg.pm
parent79670053c7247d3a49b607960efd284e93f057e5 (diff)
cgi-bin & lib
Diffstat (limited to 'lib/randbg.pm')
-rw-r--r--lib/randbg.pm26
1 files changed, 26 insertions, 0 deletions
diff --git a/lib/randbg.pm b/lib/randbg.pm
new file mode 100644
index 0000000..9f484f1
--- /dev/null
+++ b/lib/randbg.pm
@@ -0,0 +1,26 @@
+# randbg
+#
+# generates a background color within 0x0F of a given hex value.
+#
+# $bgcolor = randbg(0xfff);
+# returns [#f0f0f0, #ffffff]
+# $bgcolor = randbg(0x000);
+# returns [#000000, #0f0f0f]
+# $bgcolor = randbg(0x04d);
+# returns [#0040d0, #0f4fdf]
+
+sub randbg {
+ my $base = shift;
+ my $i = sprintf '%06x' ,
+ ((0xf00 & $base) * 0x100000 + (int rand 0x10) * 0x010000
+ + (0x0f0 & $base) * 0x001000 + (int rand 0x10) * 0x000100
+ + (0x00f & $base) * 0x000010 + (int rand 0x10) * 0x000001);
+ return $i;
+}
+
+# randbg (0xfff);
+# randbg (0x000);
+# randbg (0x04d);
+
+1;
+