Added new Bang() cmd and began building filters.
This commit is contained in:
@@ -26,9 +26,6 @@ function Commander(element,element_input)
|
||||
case "@":
|
||||
ronin.canvas.active(cmd);
|
||||
break;
|
||||
case "~": // TODO
|
||||
ronin.memory.active(cmd);
|
||||
break;
|
||||
case "$":
|
||||
ronin.file.save(cmd);
|
||||
break;
|
||||
@@ -69,10 +66,6 @@ function Commander(element,element_input)
|
||||
ronin.canvas.passive(this.cmd);
|
||||
ronin.module = ronin.canvas;
|
||||
break;
|
||||
case "~":
|
||||
ronin.memory.passive(this.cmd);
|
||||
ronin.module = ronin.memory;
|
||||
break;
|
||||
case "/":
|
||||
ronin.file.passive(this.cmd);
|
||||
ronin.module = ronin.file;
|
||||
|
||||
@@ -2,6 +2,8 @@ function Brush()
|
||||
{
|
||||
Module.call(this);
|
||||
|
||||
this.pointers = [new Pointer(new Position())];
|
||||
|
||||
this.position = new Position();
|
||||
this.is_drawing = false;
|
||||
this.size = 1;
|
||||
@@ -12,6 +14,8 @@ function Brush()
|
||||
|
||||
this.active = function(cmd)
|
||||
{
|
||||
if(cmd.bang()){ this.pointers = []; }
|
||||
|
||||
var pointer = new Pointer();
|
||||
|
||||
if(cmd.position()){
|
||||
@@ -20,7 +24,10 @@ function Brush()
|
||||
if(cmd.rect()){
|
||||
pointer.mirror = cmd.rect();
|
||||
}
|
||||
if(cmd.rect() || cmd.position()){
|
||||
if(cmd.noise()){
|
||||
pointer.noise = cmd.noise();
|
||||
}
|
||||
if(cmd.rect() || cmd.position() || cmd.noise()){
|
||||
this.add_pointer(pointer);
|
||||
}
|
||||
if(cmd.color()){
|
||||
@@ -37,16 +44,17 @@ function Brush()
|
||||
|
||||
this.hint = function(cmd)
|
||||
{
|
||||
if(cmd.bang()){ return "Brush: Erase all pointers"; }
|
||||
|
||||
var hint_value = (cmd.value() ? "Size "+cmd.value()+" " : "");
|
||||
var hint_position = (cmd.position() ? "Position "+cmd.position().x+","+cmd.position().y+" " : "");
|
||||
var hint_color = (cmd.color() ? "Color "+cmd.color().hex+" " : "");
|
||||
var hint_rect = (cmd.rect() ? "Mirror "+cmd.rect().width+"/"+cmd.rect().height+" " : "");
|
||||
var hint_noise = (cmd.noise() ? "Noise 0.."+cmd.noise()+" " : "");
|
||||
|
||||
return "Brush: "+hint_value+hint_position+hint_color+hint_rect;
|
||||
return "Brush: "+hint_value+hint_position+hint_color+hint_rect+hint_noise;
|
||||
}
|
||||
|
||||
this.pointers = [new Pointer(new Position())];
|
||||
|
||||
this.add_pointer = function(pointer)
|
||||
{
|
||||
this.pointers.push(pointer);
|
||||
|
||||
@@ -2,6 +2,7 @@ function Pointer(offset = new Position(), color = new Color('000000'))
|
||||
{
|
||||
this.offset = offset;
|
||||
this.mirror = null;
|
||||
this.noise = null;
|
||||
this.position_prev = null;
|
||||
|
||||
this.draw = function()
|
||||
@@ -9,16 +10,23 @@ function Pointer(offset = new Position(), color = new Color('000000'))
|
||||
if(!this.position_prev){this.position_prev = this.position(); }
|
||||
if(ronin.brush.size < 0){ this.erase(); return; }
|
||||
|
||||
var position = this.position();
|
||||
|
||||
if(this.noise){
|
||||
position.x += (Math.random() * this.noise) - (this.noise/2);
|
||||
position.y += (Math.random() * this.noise) - (this.noise/2);
|
||||
}
|
||||
|
||||
context.beginPath();
|
||||
context.moveTo(this.position_prev.x,this.position_prev.y);
|
||||
context.lineTo(this.position().x,this.position().y);
|
||||
context.lineTo(position.x,position.y);
|
||||
context.lineCap="round";
|
||||
context.lineWidth = this.thickness();
|
||||
context.strokeStyle = ronin.brush.color.rgba();
|
||||
context.stroke();
|
||||
context.closePath();
|
||||
|
||||
this.position_prev = this.position();
|
||||
this.position_prev = position;
|
||||
}
|
||||
|
||||
this.erase = function()
|
||||
|
||||
@@ -6,16 +6,18 @@ function Canvas(element)
|
||||
|
||||
this.active = function(cmd)
|
||||
{
|
||||
if(cmd.bang()){ this.context().clearRect(0, 0, canvas.width, canvas.height); }
|
||||
|
||||
if(cmd.rect()){
|
||||
this.resize(cmd.rect());
|
||||
ronin.overlay.resize(cmd.rect());
|
||||
}
|
||||
|
||||
if(cmd.color()){
|
||||
this.element.getContext('2d').beginPath();
|
||||
this.element.getContext('2d').rect(0, 0, canvas.width, canvas.height);
|
||||
this.element.getContext('2d').fillStyle = cmd.color().hex;
|
||||
this.element.getContext('2d').fill();
|
||||
this.context().beginPath();
|
||||
this.context().rect(0, 0, canvas.width, canvas.height);
|
||||
this.context().fillStyle = cmd.color().hex;
|
||||
this.context().fill();
|
||||
}
|
||||
}
|
||||
|
||||
@@ -28,6 +30,8 @@ function Canvas(element)
|
||||
|
||||
this.hint = function(cmd)
|
||||
{
|
||||
if(cmd.bang()){ return "Canvas: Clear"; }
|
||||
|
||||
var hint_rect = (cmd.rect() ? "Resize to "+cmd.rect().width+"px by "+cmd.rect().height+"px " : "");
|
||||
var hint_color = (cmd.color() ? "Fill with color "+cmd.color().hex+" " : "");
|
||||
|
||||
@@ -41,4 +45,9 @@ function Canvas(element)
|
||||
this.element.setAttribute('width',rect.width+"px");
|
||||
this.element.setAttribute('height',rect.height+"px");
|
||||
}
|
||||
|
||||
this.context = function()
|
||||
{
|
||||
return this.element.getContext('2d');
|
||||
}
|
||||
}
|
||||
@@ -6,6 +6,8 @@ function File()
|
||||
|
||||
this.active = function(cmd)
|
||||
{
|
||||
if(cmd.bang()){ this.storage = []; }
|
||||
|
||||
ronin.overlay.clear();
|
||||
|
||||
if(!cmd.position()){ return; }
|
||||
|
||||
19
scripts/ronin.filter.js
Normal file
19
scripts/ronin.filter.js
Normal file
@@ -0,0 +1,19 @@
|
||||
function Filter(element)
|
||||
{
|
||||
Module.call(this);
|
||||
|
||||
this.active = function(cmd)
|
||||
{
|
||||
console.log("Nothing to do.");
|
||||
}
|
||||
|
||||
this.passive = function(cmd)
|
||||
{
|
||||
console.log("Nothing to do.");
|
||||
}
|
||||
|
||||
this.hint = function(cmd)
|
||||
{
|
||||
return "Filter: ";
|
||||
}
|
||||
}
|
||||
@@ -6,19 +6,5 @@ function Ronin()
|
||||
this.brush = new Brush();
|
||||
this.file = new File();
|
||||
this.hint = new Hint();
|
||||
|
||||
this.fill = function(p)
|
||||
{
|
||||
cvSave = canvas.toDataURL("image/png");
|
||||
|
||||
context.beginPath();
|
||||
context.rect(0, 0, canvas.width, canvas.height);
|
||||
context.fillStyle = "#"+p[0];
|
||||
context.fill();
|
||||
|
||||
var imgObj = new Image();
|
||||
imgObj.src = cvSave;
|
||||
|
||||
context.drawImage(imgObj,0,0);
|
||||
}
|
||||
this.filter = new Filter();
|
||||
}
|
||||
@@ -13,11 +13,13 @@ function Overlay(element)
|
||||
|
||||
this.active = function(cmd)
|
||||
{
|
||||
|
||||
if(cmd.bang()){ this.guides = []; }
|
||||
}
|
||||
|
||||
this.hint = function(cmd)
|
||||
{
|
||||
if(cmd.bang()){ return "Overlay: Erase all guides"; }
|
||||
|
||||
var hint_position = (cmd.position() ? "Position "+cmd.position().x+","+cmd.position().y+" " : "");
|
||||
var hint_rect = (cmd.rect() ? "Size "+cmd.rect().width+"px by "+cmd.rect().height+"px " : "");
|
||||
|
||||
|
||||
@@ -42,4 +42,20 @@ function Command(cmd_array)
|
||||
}
|
||||
return null;
|
||||
}
|
||||
|
||||
this.noise = function()
|
||||
{
|
||||
for (i = 0; i < this.cmd_array.length; i++) {
|
||||
if(this.cmd_array[i].indexOf("?") >= 0){ return parseInt(this.cmd_array[i][1]); }
|
||||
}
|
||||
return null;
|
||||
}
|
||||
|
||||
this.bang = function()
|
||||
{
|
||||
for (i = 0; i < this.cmd_array.length; i++) {
|
||||
if(this.cmd_array[i].indexOf("!") >= 0){ return true; }
|
||||
}
|
||||
return null;
|
||||
}
|
||||
}
|
||||
@@ -5,12 +5,6 @@ function Position(position_str = "0,0",y = null)
|
||||
this.x = y ? position_str : parseFloat(this.position_str.split(",")[0]);
|
||||
this.y = y ? y : parseFloat(this.position_str.split(",")[1]);
|
||||
|
||||
this.update = function(x,y)
|
||||
{
|
||||
this.x = x;
|
||||
this.y = y;
|
||||
}
|
||||
|
||||
this.is_equal = function(target)
|
||||
{
|
||||
if(target.x == this.x && target.y == this.y){ return true; }
|
||||
|
||||
Reference in New Issue
Block a user