Moved scaling stuff into a module
This commit is contained in:
43
sources/scripts/modules/brush.js
Normal file
43
sources/scripts/modules/brush.js
Normal file
@@ -0,0 +1,43 @@
|
||||
function Brush()
|
||||
{
|
||||
Module.call(this,"brush");
|
||||
|
||||
this.settings = {size:10,color:"#f00"};
|
||||
|
||||
this.thickness = function(line)
|
||||
{
|
||||
var ratio = 1 - (distance_between(line.from,line.to)/15.0);
|
||||
return this.settings.size * ratio;
|
||||
}
|
||||
|
||||
this.stroke = function(line)
|
||||
{
|
||||
ronin.commander.blur();
|
||||
var ctx = ronin.render.context();
|
||||
|
||||
ctx.beginPath();
|
||||
ctx.globalCompositeOperation="source-over";
|
||||
ctx.moveTo(line.from.x * 2,line.from.y * 2);
|
||||
ctx.lineTo(line.to.x * 2,line.to.y * 2);
|
||||
ctx.lineCap="round";
|
||||
ctx.lineWidth = this.thickness(line);
|
||||
ctx.strokeStyle = this.settings.color;
|
||||
ctx.stroke();
|
||||
ctx.closePath();
|
||||
}
|
||||
|
||||
this.mod_size = function(mod)
|
||||
{
|
||||
this.settings.size = clamp(this.settings.size+mod,1,100);
|
||||
}
|
||||
|
||||
function clamp(v, min, max)
|
||||
{
|
||||
return v < min ? min : v > max ? max : v;
|
||||
}
|
||||
|
||||
function distance_between(a,b)
|
||||
{
|
||||
return Math.sqrt( (a.x-b.x)*(a.x-b.x) + (a.y-b.y)*(a.y-b.y) );
|
||||
}
|
||||
}
|
||||
23
sources/scripts/modules/eraser.js
Normal file
23
sources/scripts/modules/eraser.js
Normal file
@@ -0,0 +1,23 @@
|
||||
function Eraser()
|
||||
{
|
||||
Module.call(this,"eraser");
|
||||
|
||||
this.thickness = function(line)
|
||||
{
|
||||
return ronin.brush.thickness(line);
|
||||
}
|
||||
|
||||
this.stroke = function(line)
|
||||
{
|
||||
var ctx = ronin.render.context();
|
||||
|
||||
ctx.beginPath();
|
||||
ctx.globalCompositeOperation="destination-out";
|
||||
ctx.moveTo(line.from.x * 2,line.from.y * 2);
|
||||
ctx.lineTo(line.to.x * 2,line.to.y * 2);
|
||||
ctx.lineCap="round";
|
||||
ctx.lineWidth = this.thickness(line);
|
||||
ctx.stroke();
|
||||
ctx.closePath();
|
||||
}
|
||||
}
|
||||
4
sources/scripts/modules/frame.js
Normal file
4
sources/scripts/modules/frame.js
Normal file
@@ -0,0 +1,4 @@
|
||||
function Frame()
|
||||
{
|
||||
Module.call(this,"frame");
|
||||
}
|
||||
Reference in New Issue
Block a user