/**
 * Created by jams on 2016/5/13.
 */

var { min, max, sin, cos, round, sqrt, random, PI } = Math;
function rotate_rgb(RGBA, theta) {
	var [r, g, b, a] = RGBA;
	var u = sqrt(3) / 3;
	var pu = 1 / 3;
	cosa = cos(theta);
	sina = sin(theta);
	vera = 1 - cosa;
	red = round((cosa + pu * vera) * r + (pu * vera - u * sina) * g + (pu * vera + u * sina) * b);
	green = round((pu * vera + u * sina) * r + (cosa + pu * vera) * g + (pu * vera - u * sina) * b);
	blue = round((pu * vera - u * sina) * r + (pu * vera + u * sina) * g + (cosa + pu * vera) * b);
	return [red, green, blue, a];
}
var trim16 = a => max(min(a | 0, 15), 0);
var trim256 = a => max(min(a | 0, 255), 0);
function color() {
}
function doWith(manager, color, args) {
	if (rgbReg.test(color)) {
		return color.replace(rgbReg, function (match, r, g, b, a) {
			var [R, G, B, a] = manager([r, g, b, a], args);
			if (a) {
				return `rgba(${R},${G},${B},${a})`;
			} else {
				return `rgb(${R},${G},${B})`;
			}
		});
	} else if (rgbHex.test(color)) {
		return color.replace(rgbHex, function (match, r, g, b) {
			var [R, G, B] = manager([r, g, b].map(a => parseInt(a, 16)), args).map(trim16);
			return "#" + R.toString(16) + G.toString(16) + B.toString(16);
		});
	} else if (rgbHex2.test(color)) {
		return color.replace(rgbHex2, function (match, r, g, b) {
			var [R, G, B] = manager([r, g, b].map(a => parseInt(a, 16)), args).map(trim256);
			return "#" + R.toString(16) + G.toString(16) + B.toString(16);
		});
	}
}
var rgbReg = /rgba?\(\s*(\d+)\s*,\s*(\d+)\s*,\s*(\d+)(.*?)\)/i;
var rgbHex = /^#([\da-f])([\da-f])([\da-f])$/i;
var rgbHex2 = /^#([\da-f]{2})([\da-f]{2})([\da-f]{2})$/i;
var rotated_base_color = "#d16969";
extend(color, {
	rotate(color, theta) {
		return doWith(rotate_rgb, color, theta);
	},
	random(base = rotated_base_color) {
		return rotated_base_color = doWith(rotate_rgb, base, (random() * .4 + .4) * PI)
	}
});
@@ -663,16 +663,218 @@
 5), 0);%0A
+var hex256 = function (num) %7B%0A%09num = trim256(num);%0A%09if (num %3C 16) return %220%22 + num.toString(16);%0A%09return num.toString(16);%0A%7D%0Avar hex16 = function (num) %7B%0A%09num = trim16(num);%0A%09return num.toString(16);%0A%7D%0A
 function
@@ -1342,20 +1342,19 @@
 gs).map(
-trim
+hex
 16);%0A%09%09%09
@@ -1371,55 +1371,16 @@
  + R
-.toString(16) + G.toString(16) + B.toString(16)
+ + G + B
 ;%0A%09%09
@@ -1552,20 +1552,19 @@
 gs).map(
-trim
+hex
 256);%0A%09%09
@@ -1582,55 +1582,16 @@
  + R
-.toString(16) + G.toString(16) + B.toString(16)
+ + G + B
 ;%0A%09%09

转换颜色时对小于16的数字做补0处理