Added new units, adding stroke.

This commit is contained in:
Devine Lu Linvega
2016-11-15 21:17:55 -08:00
parent 7b6c629e1e
commit fddc967c61
8 changed files with 74 additions and 17 deletions

View File

@@ -38,6 +38,9 @@ function Commander(element,element_input)
case "|":
ronin.overlay.active(cmd);
break;
case "-":
ronin.stroke.active(cmd);
break;
case "^": // TODO
ronin.translate.active(cmd);
break;

View File

@@ -24,13 +24,14 @@ function Brush()
if(cmd.rect()){
pointer.mirror = cmd.rect();
}
if(cmd.noise()){
pointer.noise = cmd.noise();
if(cmd.variable("osc_scale") && cmd.variable("osc_rate")){
pointer.osc_rate = parseFloat(cmd.variable("osc_rate"));
pointer.osc_scale = parseFloat(cmd.variable("osc_scale"));
}
if(cmd.angle()){
pointer.angle = cmd.angle();
}
if(cmd.rect() || cmd.position() || cmd.noise() || cmd.angle()){
if(cmd.rect() || cmd.position() || cmd.variable("osc_rate") || cmd.angle()){
this.add_pointer(pointer);
}
if(cmd.color()){
@@ -62,9 +63,9 @@ function Brush()
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()+" " : "");
var hint_random = (cmd.random() ? "Random 0.."+cmd.random()+" " : "");
return "Brush: "+hint_value+hint_position+hint_color+hint_rect+hint_noise;
return "Brush: "+hint_value+hint_position+hint_color+hint_rect+hint_random;
}
this.add_pointer = function(pointer)

View File

@@ -2,11 +2,13 @@ function Pointer(offset = new Position(), color = new Color('000000'))
{
this.offset = offset;
this.mirror = null;
this.noise = null;
this.position_prev = null;
this.angle = null;
this.distance = 0;
this.osc_scale = null;
this.osc_rate = null;
this.draw = function()
{
if(!this.position_prev){this.position_prev = this.position(); }
@@ -16,9 +18,10 @@ function Pointer(offset = new Position(), color = new Color('000000'))
this.distance += position.distance_to(this.position_prev);
if(this.noise){
position.x += (Math.sin(this.distance/100) * this.noise) - (this.noise/2);
position.y += (Math.sin(this.distance/100) * this.noise) - (this.noise/2);
// Osc experiment
if(this.osc_rate && this.osc_scale){
// position.x += (Math.sin(this.distance/(25 * this.osc_rate)) * this.osc_scale) - (this.osc_scale/2);
position.y += (Math.sin(this.distance/(25 * this.osc_rate)) * this.osc_scale) - (this.osc_scale/2);
}
ronin.canvas.context().beginPath();

View File

@@ -6,4 +6,5 @@ function Ronin()
this.file = new File();
this.hint = new Hint();
this.filter = new Filter();
this.stroke = new Stroke();
}

36
scripts/ronin.stroke.js Normal file
View File

@@ -0,0 +1,36 @@
function Stroke(element)
{
Module.call(this);
// Module
this.passive = function(cmd)
{
}
this.active = function(cmd)
{
// TODO
var origin = new Position(cmd.content[0]);
var destination = new Position(cmd.content[1]);
var e = {};
e.clientX = origin.x;
e.clientY = origin.y;
ronin.brush.is_drawing = true;
ronin.brush.draw(e);
e.clientX = destination.x;
e.clientY = destination.y;
ronin.brush.draw(e);
ronin.brush.is_drawing = false;
}
this.hint = function(cmd)
{
}
}

View File

@@ -43,10 +43,10 @@ function Command(content)
return null;
}
this.noise = function()
this.random = function()
{
for (i = 0; i < this.content.length; i++) {
if(this.content[i].indexOf("?") >= 0){ return parseInt(this.content[i].replace('?','')); }
if(this.content[i].indexOf("..") >= 0){ (Math.random() * this.content[i].split("..")[1]) + this.content[i].split("..")[0]; }
}
return null;
}
@@ -66,4 +66,12 @@ function Command(content)
}
return null;
}
this.variable = function(name)
{
for (i = 0; i < this.content.length; i++) {
if(this.content[i].indexOf(name+":") >= 0){ return this.content[i].split(":")[1]; }
}
return null;
}
}