Thanks to visit codestin.com
Credit goes to github.com

Skip to content
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
14 changes: 14 additions & 0 deletions js/color.js
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,20 @@
return '#' + hex;
};

/**
* Returns a the color when lit with a certain color light
*/
Color.prototype.lightWith = function (lightColor) {
var newColor = new Color();

newColor.r = (lightColor.r / 255) * this.r;
newColor.g = (lightColor.g / 255) * this.g;
newColor.b = (lightColor.b / 255) * this.b;

newColor.loadHSL();
return newColor;
};


/**
* Returns a lightened color based on a given percentage
Expand Down
5 changes: 4 additions & 1 deletion js/isomer.js
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,7 @@ function Isomer(canvasId, options) {
* The maximum color difference from shading
*/
this.colorDifference = 0.20;
this.lightColor = options.lightColor || new Isomer.Color(255, 255, 255);
}

Isomer.prototype._translatePoint = function (point) {
Expand Down Expand Up @@ -95,6 +96,8 @@ Isomer.prototype._addPath = function (path, baseColor) {
*/
var brightness = Vector.dotProduct(normal, this.lightAngle);

var color = baseColor.lighten(brightness * this.colorDifference);
var color = baseColor.lightWith(this.lightColor);
color = color.lighten(brightness * this.colorDifference);

this.canvas.path(path.points.map(this._translatePoint.bind(this)), color);
};