From 7ff25747dc547ed40ec2ffa18d4029144d30f7d7 Mon Sep 17 00:00:00 2001 From: Devine Lu Linvega Date: Wed, 22 Nov 2017 19:43:42 +1300 Subject: [PATCH] Added color tweening --- sources/scripts/core/cursor.js | 4 ++-- sources/scripts/core/module.js | 9 +-------- sources/scripts/modules/brush.js | 12 ++++++++---- sources/scripts/units/color.js | 13 +++++++++++++ 4 files changed, 24 insertions(+), 14 deletions(-) diff --git a/sources/scripts/core/cursor.js b/sources/scripts/core/cursor.js index 763db40..625adce 100644 --- a/sources/scripts/core/cursor.js +++ b/sources/scripts/core/cursor.js @@ -8,8 +8,8 @@ function Cursor(rune) this.query = null; this.mode = "vertex"; - this.color = "#f00" - this.color_alt = "#fff" + this.color = "#444444" + this.color_alt = "#ff0000" this.size = 4; this.under = false; diff --git a/sources/scripts/core/module.js b/sources/scripts/core/module.js index 7d4af52..4bd74a1 100644 --- a/sources/scripts/core/module.js +++ b/sources/scripts/core/module.js @@ -3,8 +3,6 @@ function Module(name,docs = "Missing documentation.") this.name = name; this.methods = {}; - this.routes = {}; - this.ports = {}; this.docs = docs; this.hint = function() @@ -15,12 +13,7 @@ function Module(name,docs = "Missing documentation.") var v = this.methods[id]; html += v.hint(); } - - for(route_id in this.routes){ - var route_val = this.routes[route_id]; - html += route_id+"->"+route_val+" "; - } - + return html.trim() != "" ? " "+html.trim() : ""; } } \ No newline at end of file diff --git a/sources/scripts/modules/brush.js b/sources/scripts/modules/brush.js index 8470625..864a0f8 100644 --- a/sources/scripts/modules/brush.js +++ b/sources/scripts/modules/brush.js @@ -2,6 +2,8 @@ function Brush() { Module.call(this,"brush"); + this.speed = 0; + this.pointers = [ new Pointer({offset:{x:0,y:0}}) ]; @@ -32,7 +34,8 @@ function Brush() this.thickness = function(line) { - var t = ronin.cursor.size * this.ports.speed; + var ratio = clamp(1 - (ronin.brush.speed/20),0,1) + var t = ronin.cursor.size * ratio; this.absolute_thickness = t > this.absolute_thickness ? this.absolute_thickness+0.25 : this.absolute_thickness-0.25; return this.absolute_thickness * 3; } @@ -41,8 +44,7 @@ function Brush() { ronin.commander.blur(); - this.ports.speed = 1-distance_between(line.from,line.to)/15.0; - this.ports.distance += this.ports.speed; + this.speed = distance_between(line.from,line.to); for(pointer_id in this.pointers){ this.pointers[pointer_id].stroke(line); @@ -101,13 +103,15 @@ function Pointer(options) line.to = line.from } + var ratio = clamp((ronin.brush.speed/20),0,1) + ctx.beginPath(); ctx.globalCompositeOperation = ronin.keyboard.is_down["Alt"] ? "destination-out" : "source-over"; ctx.moveTo((line.from.x * 2) + this.options.offset.x,(line.from.y * 2) + this.options.offset.y); ctx.lineTo((line.to.x * 2) + this.options.offset.x,(line.to.y * 2) + this.options.offset.y); ctx.lineCap="round"; ctx.lineWidth = this.thickness(line); - ctx.strokeStyle = ronin.cursor.color; + ctx.strokeStyle = this.options.tween ? new Color(ronin.cursor.color).tween(new Color(ronin.cursor.color_alt),ratio) : ronin.cursor.color; ctx.stroke(); ctx.closePath(); } diff --git a/sources/scripts/units/color.js b/sources/scripts/units/color.js index da16279..591cf11 100644 --- a/sources/scripts/units/color.js +++ b/sources/scripts/units/color.js @@ -43,4 +43,17 @@ function Color(hex = '#000000') { return this.brightness() > 150 ? "bright" : "dark"; } + + this.tween = function(target,value) + { + var c1 = this.floats(); + var c2 = target.floats(); + + var r = ((255 * c1.r) * value) + ((255 * c2.r) * (1-value)); + var g = ((255 * c1.g) * value) + ((255 * c2.g) * (1-value)); + var b = ((255 * c1.b) * value) + ((255 * c2.b) * (1-value)); + var rgb = [parseInt(r),parseInt(g),parseInt(b)]; + var hex = new Color().rgb_to_hex(rgb); + return hex; + } } \ No newline at end of file