Implemented variables properly.

This commit is contained in:
Devine Lu Linvega 2016-12-20 11:16:47 -07:00
parent 6c3ed550d3
commit 27117db46c
10 changed files with 90 additions and 53 deletions

View File

@ -24,3 +24,5 @@ canvas:hover { cursor: crosshair;}
#commander_hint .value { color:#ff0000;} #commander_hint .value { color:#ff0000;}
#commander_hint .value:after { content:", "; color:#999; } #commander_hint .value:after { content:", "; color:#999; }
#commander_hint .value:last-child:after { content:"";} #commander_hint .value:last-child:after { content:"";}
#commander_hint .variable_key { color:#ccc; font-weight:bold;}
#commander_hint .variable_value { color:#ccc;}

View File

@ -28,6 +28,23 @@ function Hint(element)
e += 1; e += 1;
} }
s += " ";
s += this.print_variables(module);
return s;
}
this.print_variables = function(module)
{
if(module.variables.length < 1){ return "";}
var s = "";
for (var key in module.variables){
s += "<span class='variable_key'>"+key+"</span>=<span class='variable_value'>"+module.variables[key]+"</span> ";
}
return s; return s;
} }

View File

@ -26,3 +26,7 @@ starting_canvas.height = window.innerHeight - 200;
commander.query("~ "+ronin.timestamp()); commander.query("~ "+ronin.timestamp());
commander.query("@ "+starting_canvas.render()); commander.query("@ "+starting_canvas.render());
commander.query("> 1 0,0 #000000");
commander.query("> banking=true");
commander.query("> natural=true");
commander.query("> -5,0");

View File

@ -3,7 +3,8 @@ function Brush(rune)
Module.call(this,rune); Module.call(this,rune);
this.parameters = [Position,Rect,Angle,Color,Value,Bang]; this.parameters = [Position,Rect,Angle,Color,Value,Bang];
this.pointers = [new Pointer(new Position())]; this.variables = {"natural" : false,"banking" : false};
this.pointers = [];
this.size = 1; this.size = 1;
this.opacity = 1; this.opacity = 1;
@ -15,31 +16,20 @@ function Brush(rune)
{ {
if(cmd.bang()){ this.pointers = []; } if(cmd.bang()){ this.pointers = []; }
var pointer = new Pointer(); // Pointer
if(cmd.rect() || cmd.position() || cmd.angle()){
this.add_pointer(cmd);
}
if(cmd.position()){ // Global
pointer.offset = cmd.position();
}
if(cmd.rect()){
pointer.mirror = cmd.rect();
}
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.variable("osc_rate") || cmd.angle()){
this.add_pointer(pointer);
}
if(cmd.color()){ if(cmd.color()){
this.color = cmd.color(); this.color = cmd.color();
} }
if(cmd.value()){ if(cmd.value()){
this.size = cmd.value().float; this.size = cmd.value().float;
} }
ronin.widget.update();
this.update_variables(cmd);
} }
this.passive = function(cmd) this.passive = function(cmd)
@ -55,19 +45,26 @@ function Brush(rune)
} }
} }
this.add_pointer = function(pointer) this.add_pointer = function(cmd)
{ {
this.pointers.push(pointer); var pointer = new Pointer();
if(cmd.position()){
pointer.offset = cmd.position();
}
if(cmd.rect()){
pointer.mirror = cmd.rect();
}
if(cmd.angle()){
pointer.angle = cmd.angle();
} }
this.widget = function() this.pointers.push(pointer);
{
return "> "+this.size+" <span>"+this.color.render()+"</span> ";
} }
this.widget_cursor = function() this.widget_cursor = function()
{ {
return "Brush "+this.size; return "Brush "+this.size+", "+this.pointers.length+" pointers";
} }
// Cursor // Cursor
@ -104,6 +101,6 @@ function Brush(rune)
ronin.brush.pointers[i].stop(); ronin.brush.pointers[i].stop();
} }
ronin.stroke.save_stroke(); ronin.stroke.save_stroke("brush");
} }
} }

View File

@ -6,10 +6,20 @@ function Pointer(offset = new Position(), color = new Color('000000'))
this.angle = null; this.angle = null;
this.distance = 0; this.distance = 0;
// Parameters
this.thickness = function()
{
var ratio = 10/this.position().distance_to(this.position_prev);
ratio = ratio > 1 ? 1 : ratio;
return ronin.brush.size * ratio;
}
//
this.draw = function() this.draw = function()
{ {
if(!this.position_prev){this.position_prev = this.position(); } if(!this.position_prev){this.position_prev = this.position(); }
if(ronin.brush.size < 0){ this.erase(); return; }
var position = this.position(); var position = this.position();
@ -29,22 +39,8 @@ function Pointer(offset = new Position(), color = new Color('000000'))
this.position_prev = position; this.position_prev = position;
} }
this.erase = function()
{
ronin.canvas.context().clearRect(this.position().x - (ronin.brush.size/2), this.position().y - (ronin.brush.size/2), ronin.brush.size, ronin.brush.size);
}
this.thickness = function()
{
var ratio = 10/this.position().distance_to(this.position_prev);
ratio = ratio > 1 ? 1 : ratio;
return ronin.brush.size * ratio;
}
this.position = function() this.position = function()
{ {
return ronin.cursor.position;
if(this.angle){ if(this.angle){
var angle_radian = this.angle.degrees * Math.PI / 180; var angle_radian = this.angle.degrees * Math.PI / 180;
var deltaX = ronin.brush.position.x - this.offset.x; var deltaX = ronin.brush.position.x - this.offset.x;
@ -62,10 +58,14 @@ function Pointer(offset = new Position(), color = new Color('000000'))
return new Position((ronin.brush.position.x + this.offset.x), (2 * this.mirror.height) - (ronin.brush.position.y + this.offset.y)); return new Position((ronin.brush.position.x + this.offset.x), (2 * this.mirror.height) - (ronin.brush.position.y + this.offset.y));
} }
console.log(ronin.brush.position); return this.position_default();
console.log(this.offset); }
return;
return new Position(ronin.brush.position.x + this.offset.x, ronin.brush.position.y + this.offset.y); // Effects
this.position_default = function()
{
return ronin.cursor.position.add(this.offset);
} }
this.start = function() this.start = function()

View File

@ -74,6 +74,6 @@ function Eraser(rune)
this.is_drawing = false; this.is_drawing = false;
this.position_prev = null; this.position_prev = null;
ronin.stroke.save_stroke(); ronin.stroke.save_stroke("eraser");
} }
} }

View File

@ -3,7 +3,7 @@ function Module(rune)
this.rune = rune; this.rune = rune;
this.element = null; this.element = null;
this.parameters = []; this.parameters = [];
this.variables = []; this.variables = {};
this.active = function(cmd) this.active = function(cmd)
{ {
@ -15,6 +15,15 @@ function Module(rune)
console.log("Nothing to do."); console.log("Nothing to do.");
} }
this.update_variables = function(cmd)
{
for (var key in this.variables){
if(!cmd.variable(key)){ continue; }
this.variables[key] = cmd.variable(key).value;
}
console.log(this.variables);
}
this.hint = function(cmd) this.hint = function(cmd)
{ {
return "unknown"; return "unknown";

View File

@ -18,9 +18,9 @@ function Stroke(rune)
this.positions.push(p); this.positions.push(p);
} }
this.save_stroke = function() this.save_stroke = function(mode)
{ {
s = "_ "; s = "_ mode:"+mode+" ";
for (i = 0; i < this.positions.length; i++) { for (i = 0; i < this.positions.length; i++) {
s += this.positions[i].render()+" "; s += this.positions[i].render()+" ";
} }

View File

@ -8,6 +8,11 @@ function Position(position_str = "0,0",y = null)
this.x = y ? position_str : parseFloat(this.position_str.split(",")[0]); this.x = y ? position_str : parseFloat(this.position_str.split(",")[0]);
this.y = y ? y : parseFloat(this.position_str.split(",")[1]); this.y = y ? y : parseFloat(this.position_str.split(",")[1]);
this.add = function(position)
{
return new Position(this.x + position.x, this.y + position.y);
}
this.is_equal = function(target) this.is_equal = function(target)
{ {
if(target.x == this.x && target.y == this.y){ return true; } if(target.x == this.x && target.y == this.y){ return true; }

View File

@ -4,7 +4,10 @@ function Variable(key,value)
this.candidates = []; this.candidates = [];
this.key = key; this.key = key;
this.value = value;
if(value == "true"){ this.value = true; }
else if(value == "false"){ this.value = false; }
else{ this.value = value; }
this.render = function() this.render = function()
{ {