From 91b7555da60df745ce967a2e874341fe873e4cbd Mon Sep 17 00:00:00 2001 From: Devine Lu Linvega Date: Thu, 28 Dec 2017 16:59:18 +1300 Subject: [PATCH] Using the latest color version --- sources/scripts/core/cursor.js | 2 +- sources/scripts/units/color.js | 30 +++++++++++++++++------------- 2 files changed, 18 insertions(+), 14 deletions(-) diff --git a/sources/scripts/core/cursor.js b/sources/scripts/core/cursor.js index 7e8e150..dde15a1 100644 --- a/sources/scripts/core/cursor.js +++ b/sources/scripts/core/cursor.js @@ -9,7 +9,7 @@ function Cursor(rune) this.mode = "vertex"; this.color = "#000000" - this.color_alt = "#ff0000" + this.color_alt = "#ffffff" this.size = 4; this.pos = {x:0,y:0}; diff --git a/sources/scripts/units/color.js b/sources/scripts/units/color.js index 591cf11..9a097b4 100644 --- a/sources/scripts/units/color.js +++ b/sources/scripts/units/color.js @@ -1,17 +1,21 @@ -function Color(hex = '#000000') +function Color(hex = '#000000', rgb) { - this.example = "#ff0000"; - this.hex = hex; - - this.rgb = function() - { - var result = /^#?([a-f\d]{2})([a-f\d]{2})([a-f\d]{2})$/i.exec(this.hex); - return result ? { - r: parseInt(result[1], 16), - g: parseInt(result[2], 16), - b: parseInt(result[3], 16) - } : null; + if(rgb){ + this.rgb = rgb; + this.hex = "#"+("0" + parseInt(rgb.r,10).toString(16)).slice(-2)+("0" + parseInt(rgb.g,10).toString(16)).slice(-2)+("0" + parseInt(rgb.b,10).toString(16)).slice(-2); } + else{ + this.hex = hex; + var result = /^#?([a-f\d]{2})([a-f\d]{2})([a-f\d]{2})$/i.exec(this.hex); + this.rgb = {r: parseInt(result[1], 16),g: parseInt(result[2], 16),b: parseInt(result[3], 16)} + } + + this.r = this.rgb.r; + this.g = this.rgb.g; + this.b = this.rgb.b; + + this.average = parseInt((this.r + this.g + this.b)/3) + this.invert = {r:255-this.rgb.r, g:255-this.rgb.g, b:255-this.rgb.b}; this.rgba = function() { @@ -20,7 +24,7 @@ function Color(hex = '#000000') this.floats = function() { - var rgb = this.rgb(); + var rgb = this.rgb; return { r:rgb.r/255, g:rgb.g/255, b:rgb.b/255 } }