From 7d64d557150aa68b68456b5851d5bcaeaaa9743c Mon Sep 17 00:00:00 2001 From: Marcus Bointon Date: Fri, 23 Mar 2012 16:39:28 +0100 Subject: [PATCH 1/3] Add random colour function --- lib/less/functions.js | 3 +++ 1 file changed, 3 insertions(+) diff --git a/lib/less/functions.js b/lib/less/functions.js index 6eb34bac8..66642fb22 100644 --- a/lib/less/functions.js +++ b/lib/less/functions.js @@ -121,6 +121,9 @@ tree.functions = { return new(tree.Color)(rgb, alpha); }, + randomcolor: function() { + return this.rgba(Math.random() * 255, Math.random() * 255, Math.random() * 255, 1.0); + }, greyscale: function (color) { return this.desaturate(color, new(tree.Dimension)(100)); }, From af1df5dca8a8659f939434af3b5b029c1b8952de Mon Sep 17 00:00:00 2001 From: Synchro Date: Fri, 23 Mar 2012 16:58:49 +0100 Subject: [PATCH 2/3] Add option to pick randomly from a provided array of colours --- lib/less/functions.js | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-) diff --git a/lib/less/functions.js b/lib/less/functions.js index 66642fb22..6dd8e02c0 100644 --- a/lib/less/functions.js +++ b/lib/less/functions.js @@ -122,7 +122,11 @@ tree.functions = { return new(tree.Color)(rgb, alpha); }, randomcolor: function() { - return this.rgba(Math.random() * 255, Math.random() * 255, Math.random() * 255, 1.0); + if (arguments.length > 0) { + return arguments[Math.floor(Math.random() * arguments.length)]; + } else { + return this.rgba(Math.random() * 255, Math.random() * 255, Math.random() * 255, 1.0); + } }, greyscale: function (color) { return this.desaturate(color, new(tree.Dimension)(100)); From 70dfa6f5786b510e1d46732c2b9a73cde73b6aa4 Mon Sep 17 00:00:00 2001 From: Synchro Date: Fri, 23 Mar 2012 17:18:21 +0100 Subject: [PATCH 3/3] Split pickrandom into a separate function --- lib/less/functions.js | 9 ++++----- 1 file changed, 4 insertions(+), 5 deletions(-) diff --git a/lib/less/functions.js b/lib/less/functions.js index 6dd8e02c0..e62963611 100644 --- a/lib/less/functions.js +++ b/lib/less/functions.js @@ -122,11 +122,10 @@ tree.functions = { return new(tree.Color)(rgb, alpha); }, randomcolor: function() { - if (arguments.length > 0) { - return arguments[Math.floor(Math.random() * arguments.length)]; - } else { - return this.rgba(Math.random() * 255, Math.random() * 255, Math.random() * 255, 1.0); - } + return this.rgba(Math.random() * 255, Math.random() * 255, Math.random() * 255, 1.0); + }, + pickrandom: function() { + return arguments[Math.floor(Math.random() * arguments.length)]; }, greyscale: function (color) { return this.desaturate(color, new(tree.Dimension)(100));