Added color tweening
This commit is contained in:
parent
bef1257276
commit
7ff25747dc
@ -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;
|
||||
|
||||
|
@ -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() : "";
|
||||
}
|
||||
}
|
@ -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();
|
||||
}
|
||||
|
@ -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;
|
||||
}
|
||||
}
|
Loading…
x
Reference in New Issue
Block a user