Implemented variables properly.
This commit is contained in:
parent
6c3ed550d3
commit
27117db46c
@ -23,4 +23,6 @@ canvas:hover { cursor: crosshair;}
|
||||
#commander_hint .param:last-child:after { content:"";}
|
||||
#commander_hint .value { color:#ff0000;}
|
||||
#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;}
|
@ -28,6 +28,23 @@ function Hint(element)
|
||||
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;
|
||||
}
|
||||
|
||||
|
@ -25,4 +25,8 @@ starting_canvas.width = window.innerWidth - 200;
|
||||
starting_canvas.height = window.innerHeight - 200;
|
||||
|
||||
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");
|
@ -3,7 +3,8 @@ function Brush(rune)
|
||||
Module.call(this,rune);
|
||||
|
||||
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.opacity = 1;
|
||||
@ -15,31 +16,20 @@ function Brush(rune)
|
||||
{
|
||||
if(cmd.bang()){ this.pointers = []; }
|
||||
|
||||
var pointer = new Pointer();
|
||||
// Pointer
|
||||
if(cmd.rect() || cmd.position() || cmd.angle()){
|
||||
this.add_pointer(cmd);
|
||||
}
|
||||
|
||||
if(cmd.position()){
|
||||
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);
|
||||
}
|
||||
// Global
|
||||
if(cmd.color()){
|
||||
this.color = cmd.color();
|
||||
}
|
||||
if(cmd.value()){
|
||||
this.size = cmd.value().float;
|
||||
}
|
||||
ronin.widget.update();
|
||||
|
||||
this.update_variables(cmd);
|
||||
}
|
||||
|
||||
this.passive = function(cmd)
|
||||
@ -55,19 +45,26 @@ function Brush(rune)
|
||||
}
|
||||
}
|
||||
|
||||
this.add_pointer = function(pointer)
|
||||
this.add_pointer = function(cmd)
|
||||
{
|
||||
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.pointers.push(pointer);
|
||||
}
|
||||
|
||||
this.widget = function()
|
||||
{
|
||||
return "> "+this.size+" <span>"+this.color.render()+"</span> ";
|
||||
}
|
||||
|
||||
this.widget_cursor = function()
|
||||
{
|
||||
return "Brush "+this.size;
|
||||
return "Brush "+this.size+", "+this.pointers.length+" pointers";
|
||||
}
|
||||
|
||||
// Cursor
|
||||
@ -104,6 +101,6 @@ function Brush(rune)
|
||||
ronin.brush.pointers[i].stop();
|
||||
}
|
||||
|
||||
ronin.stroke.save_stroke();
|
||||
ronin.stroke.save_stroke("brush");
|
||||
}
|
||||
}
|
@ -5,11 +5,21 @@ function Pointer(offset = new Position(), color = new Color('000000'))
|
||||
this.position_prev = null;
|
||||
this.angle = null;
|
||||
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()
|
||||
{
|
||||
if(!this.position_prev){this.position_prev = this.position(); }
|
||||
if(ronin.brush.size < 0){ this.erase(); return; }
|
||||
|
||||
var position = this.position();
|
||||
|
||||
@ -29,22 +39,8 @@ function Pointer(offset = new Position(), color = new Color('000000'))
|
||||
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()
|
||||
{
|
||||
return ronin.cursor.position;
|
||||
|
||||
if(this.angle){
|
||||
var angle_radian = this.angle.degrees * Math.PI / 180;
|
||||
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));
|
||||
}
|
||||
|
||||
console.log(ronin.brush.position);
|
||||
console.log(this.offset);
|
||||
return;
|
||||
return new Position(ronin.brush.position.x + this.offset.x, ronin.brush.position.y + this.offset.y);
|
||||
return this.position_default();
|
||||
}
|
||||
|
||||
// Effects
|
||||
|
||||
this.position_default = function()
|
||||
{
|
||||
return ronin.cursor.position.add(this.offset);
|
||||
}
|
||||
|
||||
this.start = function()
|
||||
|
@ -74,6 +74,6 @@ function Eraser(rune)
|
||||
this.is_drawing = false;
|
||||
this.position_prev = null;
|
||||
|
||||
ronin.stroke.save_stroke();
|
||||
ronin.stroke.save_stroke("eraser");
|
||||
}
|
||||
}
|
@ -3,7 +3,7 @@ function Module(rune)
|
||||
this.rune = rune;
|
||||
this.element = null;
|
||||
this.parameters = [];
|
||||
this.variables = [];
|
||||
this.variables = {};
|
||||
|
||||
this.active = function(cmd)
|
||||
{
|
||||
@ -15,6 +15,15 @@ function Module(rune)
|
||||
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)
|
||||
{
|
||||
return "unknown";
|
||||
|
@ -18,9 +18,9 @@ function Stroke(rune)
|
||||
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++) {
|
||||
s += this.positions[i].render()+" ";
|
||||
}
|
||||
|
@ -8,6 +8,11 @@ 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.add = function(position)
|
||||
{
|
||||
return new Position(this.x + position.x, this.y + position.y);
|
||||
}
|
||||
|
||||
this.is_equal = function(target)
|
||||
{
|
||||
if(target.x == this.x && target.y == this.y){ return true; }
|
||||
|
@ -4,7 +4,10 @@ function Variable(key,value)
|
||||
|
||||
this.candidates = [];
|
||||
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()
|
||||
{
|
||||
|
Loading…
x
Reference in New Issue
Block a user