[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
[elpa] master e58833f 120/271: Refactor and document.
From: |
Jackson Ray Hamilton |
Subject: |
[elpa] master e58833f 120/271: Refactor and document. |
Date: |
Thu, 05 Feb 2015 18:30:26 +0000 |
branch: master
commit e58833f9ceec874e657ebbc559487d4a13d982e2
Author: Jackson Ray Hamilton <address@hidden>
Commit: Jackson Ray Hamilton <address@hidden>
Refactor and document.
---
tools/color-schemer/color-schemer.js | 68 +++++++++++++++++++--------------
1 files changed, 39 insertions(+), 29 deletions(-)
diff --git a/tools/color-schemer/color-schemer.js
b/tools/color-schemer/color-schemer.js
index c5cb510..0dcc038 100644
--- a/tools/color-schemer/color-schemer.js
+++ b/tools/color-schemer/color-schemer.js
@@ -4,6 +4,7 @@
'use strict';
+ // Executes `fn' `n' times.
function times(n, fn) {
var i;
for (i = 0; i < n; i += 1) {
@@ -11,10 +12,12 @@
}
}
+ // Bounds `hue' within the [0, 360) range.
function boundHue(hue) {
return (360 + (hue % 360)) % 360;
}
+ // Converts parts of a hue to rgb parts.
function hue2rgb(p, q, t) {
if (t < 0) {
t += 1;
@@ -34,6 +37,7 @@
return p;
}
+ // Converts hue/saturation/lightness to red/green/blue.
function hslToRgb(h, s, l) {
var r, g, b, q, p;
@@ -52,52 +56,54 @@
return [Math.round(r * 255), Math.round(g * 255), Math.round(b * 255)];
}
+ // Converts `c' of width [1, 2] to a padded hexidecimal value.
function componentToHex(c) {
var hex = c.toString(16);
return hex.length === 1 ? '0' + hex : hex;
}
+ // Converts red/green/blue to a CSS hex code.
function rgbToHexCss(r, g, b) {
- return "#" + componentToHex(r) + componentToHex(g) + componentToHex(b);
+ return '#' + componentToHex(r) + componentToHex(g) + componentToHex(b);
}
+ // Spreads the properties of an `hsl' object into an array.
function spreadHsl(hsl) {
return [hsl.hue, hsl.saturation, hsl.lightness];
}
+ // App for designing "rainbow" color schemes centered around a point on the
+ // color wheel.
angular.module('color-schemer', [])
- .directive('csCell', [
-
- function () {
- return {
- scope: {
- hsl: '='
- },
- template: [
- '<div class="cs-cell">',
- ' <div class="cs-cell-color"></div>',
- ' <pre
class="cs-cell-code">{{distance}}°</pre>',
- ' <pre class="cs-cell-code">{{hexCss}}</pre>',
- ' <pre class="cs-cell-code cs-cell-code-light"',
- ' data-ng-style="{color: hexCss}">var a =
0;</pre>',
- ' <pre class="cs-cell-code cs-cell-code-dark"',
- ' data-ng-style="{color: hexCss}">var a =
0;</pre>',
- '</div>'
- ].join('\n'),
- link: function (scope, element, attributes) {
- /*jslint unparam: true */
- var color =
angular.element(element[0].querySelector('.cs-cell-color'));
- scope.distance = scope.hsl.hue;
- scope.hexCss = rgbToHexCss.apply(null,
hslToRgb.apply(null, spreadHsl(scope.hsl)));
- color.css('backgroundColor', scope.hexCss);
- }
- };
- }
- ])
+ .directive('csCell', [function () {
+ // A cell of color with useful data inside.
+ return {
+ scope: {
+ hsl: '='
+ },
+ template: [
+ '<div class="cs-cell">',
+ ' <div class="cs-cell-color"',
+ ' data-ng-style="{\'background-color\':
hexCss}"></div>',
+ ' <pre class="cs-cell-code">{{distance}}°</pre>',
+ ' <pre class="cs-cell-code">{{hexCss}}</pre>',
+ ' <pre class="cs-cell-code cs-cell-code-light"',
+ ' data-ng-style="{color: hexCss}">var a =
0;</pre>',
+ ' <pre class="cs-cell-code cs-cell-code-dark"',
+ ' data-ng-style="{color: hexCss}">var a =
0;</pre>',
+ '</div>'
+ ].join('\n'),
+ link: function (scope) {
+ scope.distance = scope.hsl.hue;
+ scope.hexCss = rgbToHexCss.apply(null,
hslToRgb.apply(null, spreadHsl(scope.hsl)));
+ }
+ };
+ }])
.controller('CellsController', ['$scope', function ($scope) {
+ // Updates the current set of colors according to $scope values.
$scope.reload = function () {
var colors = [];
times($scope.numberOfColors, function (index) {
@@ -124,18 +130,22 @@
lightness: $scope.lightness
});
});
+ // We may have been pivoting but it is much easier to grasp the
+ // set of colors if they are sorted.
colors.sort(function (a, b) {
return a.hue - b.hue;
});
$scope.colors = colors;
};
+ // Default values.
$scope.numberOfColors = 6;
$scope.distanceBetweenColors = 30;
$scope.center = 0;
$scope.saturation = 1;
$scope.lightness = 0.5;
+ // Display initially.
$scope.reload();
}]);
- [elpa] master 3cd5c31 101/271: Typos., (continued)
- [elpa] master 3cd5c31 101/271: Typos., Jackson Ray Hamilton, 2015/02/05
- [elpa] master 46f0986 105/271: Update readme., Jackson Ray Hamilton, 2015/02/05
- [elpa] master ab083f4 102/271: Simplify package.json., Jackson Ray Hamilton, 2015/02/05
- [elpa] master 1c47db9 107/271: Fix link., Jackson Ray Hamilton, 2015/02/05
- [elpa] master 0960e18 106/271: Spelling., Jackson Ray Hamilton, 2015/02/05
- [elpa] master 79513b2 109/271: Remove styling from faces., Jackson Ray Hamilton, 2015/02/05
- [elpa] master c6ea2eb 116/271: Add degree sign., Jackson Ray Hamilton, 2015/02/05
- [elpa] master d430804 108/271: Add tty faces., Jackson Ray Hamilton, 2015/02/05
- [elpa] master d339677 113/271: Strip BOM., Jackson Ray Hamilton, 2015/02/05
- [elpa] master 9693c56 125/271: Move fixture into its own file., Jackson Ray Hamilton, 2015/02/05
- [elpa] master e58833f 120/271: Refactor and document.,
Jackson Ray Hamilton <=
- [elpa] master 3031e54 119/271: Extend range; fix modulo bug., Jackson Ray Hamilton, 2015/02/05
- [elpa] master d78046d 098/271: Include external libraries., Jackson Ray Hamilton, 2015/02/05
- [elpa] master f7f4fe8 126/271: Improve elisp tests., Jackson Ray Hamilton, 2015/02/05
- [elpa] master fe2bd04 128/271: Multiple vars., Jackson Ray Hamilton, 2015/02/05
- [elpa] master b51c36d 118/271: New experimental color scheme., Jackson Ray Hamilton, 2015/02/05
- [elpa] master c595539 111/271: Shift and darken colors for light color scheme., Jackson Ray Hamilton, 2015/02/05
- [elpa] master 146c096 114/271: Merge branch 'develop' into feature/color-schemer, Jackson Ray Hamilton, 2015/02/05
- [elpa] master aa5cca3 129/271: Multiple vars. Rename., Jackson Ray Hamilton, 2015/02/05
- [elpa] master fae85f9 117/271: Add code samples., Jackson Ray Hamilton, 2015/02/05
- [elpa] master b190309 133/271: Update documentation to be language-agnostic., Jackson Ray Hamilton, 2015/02/05