Added color tweening

This commit is contained in:
Devine Lu Linvega 2017-11-22 19:43:42 +13:00
parent bef1257276
commit 7ff25747dc
4 changed files with 24 additions and 14 deletions

View File

@ -8,8 +8,8 @@ function Cursor(rune)
this.query = null; this.query = null;
this.mode = "vertex"; this.mode = "vertex";
this.color = "#f00" this.color = "#444444"
this.color_alt = "#fff" this.color_alt = "#ff0000"
this.size = 4; this.size = 4;
this.under = false; this.under = false;

View File

@ -3,8 +3,6 @@ function Module(name,docs = "Missing documentation.")
this.name = name; this.name = name;
this.methods = {}; this.methods = {};
this.routes = {};
this.ports = {};
this.docs = docs; this.docs = docs;
this.hint = function() this.hint = function()
@ -16,11 +14,6 @@ function Module(name,docs = "Missing documentation.")
html += v.hint(); 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() : ""; return html.trim() != "" ? " "+html.trim() : "";
} }
} }

View File

@ -2,6 +2,8 @@ function Brush()
{ {
Module.call(this,"brush"); Module.call(this,"brush");
this.speed = 0;
this.pointers = [ this.pointers = [
new Pointer({offset:{x:0,y:0}}) new Pointer({offset:{x:0,y:0}})
]; ];
@ -32,7 +34,8 @@ function Brush()
this.thickness = function(line) 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; this.absolute_thickness = t > this.absolute_thickness ? this.absolute_thickness+0.25 : this.absolute_thickness-0.25;
return this.absolute_thickness * 3; return this.absolute_thickness * 3;
} }
@ -41,8 +44,7 @@ function Brush()
{ {
ronin.commander.blur(); ronin.commander.blur();
this.ports.speed = 1-distance_between(line.from,line.to)/15.0; this.speed = distance_between(line.from,line.to);
this.ports.distance += this.ports.speed;
for(pointer_id in this.pointers){ for(pointer_id in this.pointers){
this.pointers[pointer_id].stroke(line); this.pointers[pointer_id].stroke(line);
@ -101,13 +103,15 @@ function Pointer(options)
line.to = line.from line.to = line.from
} }
var ratio = clamp((ronin.brush.speed/20),0,1)
ctx.beginPath(); ctx.beginPath();
ctx.globalCompositeOperation = ronin.keyboard.is_down["Alt"] ? "destination-out" : "source-over"; 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.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.lineTo((line.to.x * 2) + this.options.offset.x,(line.to.y * 2) + this.options.offset.y);
ctx.lineCap="round"; ctx.lineCap="round";
ctx.lineWidth = this.thickness(line); 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.stroke();
ctx.closePath(); ctx.closePath();
} }

View File

@ -43,4 +43,17 @@ function Color(hex = '#000000')
{ {
return this.brightness() > 150 ? "bright" : "dark"; 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;
}
} }