<commit_before>/**
 * @<NAME>
 */

/*
 * Pieces hold and run managers.
 * You may only add managers to a Piece's
 * manager array.
 * They are a convenience object to help manage
 * different kinds of managers (and their agents)
 * from the top level.
 * You can also access the imgData directly
 * to apply it to multiple canvases.
 */

var Piece = function(){
  this.width= 150;
  this.height= 100;
  this.x = 0;
  this.y = 0;
  this.addingBrush = false;
}

Piece.prototype.init = function(canvas_,red,green,blue,alpha,actions,randoms,life,size){
  this.canvas = canvas_, this.red = red, this.green = green, this.blue = blue, this.alpha = alpha;
  this.actions = actions, this.randoms = randoms, this.life = life, this.size = size;
  this.width = width = canvas_.width;
  this.height = height = canvas_.height;
  this.ctx = canvas_.getContext('2d');
  this.imgData = this.ctx.getImageData(0,0,this.width,this.height);
  this.managers = [];
}

Piece.prototype.addManager = function(manager,width_,height_){
  if(!width_) var width_ = this.width;
  if(!height_) var height_ = this.height;

  this.managers.push(manager);
  this.managers[this.managers.length-1].frameOnCanvas(this.imgData.data,width_,height_);
}

Piece.prototype.uiAddBrush = function(action,what,x,y,vel,life,random){
  var type = undefined;
  var name = "";
  if(action == "smear"){
    switch (what){
      case "opaque":
        type = function(marks,self){self.smearOpaque(marks,self);};
        break;
      case "antiTransparent":
        type = function(marks,self){self.smearAntiTransparent(marks,self);};
        break;
      case "awayLight":
        type = function(marks,self){self.smearAwayLight(marks,self);};
        break;
      case "awayDark":
        type = function(marks,self){self.smearAwayDark(marks,self);};
        break;
      default:
        type = function(marks,self){self.smearAll(marks,self);};
        what = "all";
    }
    name = action + "_" + what;
  }else if(action == "blend"){
    switch (what){
      case "b/w":
        type = function(marks,self){self.blendBlackOrWhite(marks,self);};
        name = "blendBW";
        break;
      default:
        type = function(marks,self){self.blend(marks,self);};
        name = "blendDefault";
    }
  }

  var exists = undefined;
  var managers = this.managers;

  for(var index = 0; index < managers.length; index++){
    if(managers[index].name == name){
      exists = index;
      break;
    }
  }
  var manager;
  if(typeof exists == "number"){
    manager = managers[exists];
  }else{
    this.addManager(new BrushManager(type,name));
    manager = managers[this.managers.length-1];
  }
  var size = this.size.value;
  manager.addBrush(new Brush(x-10-size/2,y-10,x-10+size/2,y-10,vel,life));
  var newBrush = manager.brushes[manager.brushes.length-1];
  newBrush.setMaxSpeedAndForce(.5,.01);
  newBrush.rgbaValues = [Number(self.red.value),Number(self.green.value),Number(self.blue.value),Number(self.alpha.value)];
}

Piece.prototype.clickInterface = function(){
  var self = this;
  this.canvas.onclick = function(event){
    var rect = self.canvas.getBoundingClientRect(), root = document.documentElement;
    var x = event.clientX - rect.left - root.scrollLeft;
    var y = event.clientY - rect.top - root.scrollTop;
    if(!self.addingBrush){
      self.x = x;
      self.y = y;
      self.addingBrush = true;
    }else{
      self.addingBrush = false;
      var vel = new Vector(x-self.x,y-self.y);
      var method = ["smear","default"];
      var random = "no";
      var actions = self.actions;
      var randoms = self.randoms;
      for(var action=0; action < actions.length; action++){
        if(actions[action].checked){
          method = actions[action].value.split(" ");
          break;
        }
      }
      for(var rIndex=0; rIndex < randoms.length; rIndex++){
        if(randoms[rIndex].checked){
          random = randoms[rIndex].value;
          break;
        }
      }
      self.uiAddBrush(method[0],method[1],self.x,self.y,vel,self.life.value,random);  
    }
  }
}


Piece.prototype.run = function(){
  this.managers.forEach(function(manager){
    manager.run();
  });
  this.ctx.putImageData(this.imgData,0,0);
  this.clickInterface();
}

function getPixel(x_,y_){
  if (x_ < 0 || y_ < 0 || x_ > width || y_ > height){
    return undefined;
  }else{
    return (Math.floor(x_) * 4 + width * Math.floor(y_)*4);<commit_msg>Working on adding line from initial click (brush point of nascence) to mouse (indicating direction for velocity)<commit_after>/**
 * @<NAME>
 */

/*
 * Pieces hold and run managers.
 * You may only add managers to a Piece's
 * manager array.
 * They are a convenience object to help manage
 * different kinds of managers (and their agents)
 * from the top level.
 * You can also access the imgData directly
 * to apply it to multiple canvases.
 */

var Piece = function(){
  this.width= 150;
  this.height= 100;
  this.x = 0;
  this.y = 0;
  this.addingBrush = false;
}

Piece.prototype.init = function(canvas_,red,green,blue,alpha,actions,randoms,life,size){
  this.canvas = canvas_, this.red = red, this.green = green, this.blue = blue, this.alpha = alpha;
  this.actions = actions, this.randoms = randoms, this.life = life, this.size = size;
  this.width = width = canvas_.width;
  this.height = height = canvas_.height;
  this.ctx = canvas_.getContext('2d');
  this.uictx = canvas_.getContext('2d');
  this.imgData = this.ctx.getImageData(0,0,this.width,this.height);
  this.managers = [];
}

Piece.prototype.addManager = function(manager,width_,height_){
  if(!width_) var width_ = this.width;
  if(!height_) var height_ = this.height;

  this.managers.push(manager);
  this.managers[this.managers.length-1].frameOnCanvas(this.imgData.data,width_,height_);
}

Piece.prototype.uiAddBrush = function(action,what,x,y,vel,random){
  var type = undefined;
  var name = "";
  if(action == "smear"){
    switch (what){
      case "opaque":
        type = function(marks,self){self.smearOpaque(marks,self);};
        break;
      case "antiTransparent":
        type = function(marks,self){self.smearAntiTransparent(marks,self);};
        break;
      case "awayLight":
        type = function(marks,self){self.smearAwayLight(marks,self);};
        break;
      case "awayDark":
        type = function(marks,self){self.smearAwayDark(marks,self);};
        break;
      default:
        type = function(marks,self){self.smearAll(marks,self);};
        what = "all";
    }
    name = action + "_" + what;
  }else if(action == "blend"){
    switch (what){
      case "b/w":
        type = function(marks,self){self.blendBlackOrWhite(marks,self);};
        name = "blendBW";
        break;
      default:
        type = function(marks,self){self.blend(marks,self);};
        name = "blendDefault";
    }
  }

  var exists = undefined;
  var managers = this.managers;

  for(var index = 0; index < managers.length; index++){
    if(managers[index].name == name){
      exists = index;
      break;
    }
  }
  var manager;
  if(typeof exists == "number"){
    manager = managers[exists];
  }else{
    this.addManager(new BrushManager(type,name));
    manager = managers[this.managers.length-1];
  }
  var size = this.size.value;
  manager.addBrush(new Brush(x-10-size/2,y-10,x-10+size/2,y-10,vel,Number(this.life.value)));
  var newBrush = manager.brushes[manager.brushes.length-1];
  newBrush.setMaxSpeedAndForce(.5,.01);
  newBrush.rgbaValues = [Number(self.red.value),Number(self.green.value),Number(self.blue.value),Number(self.alpha.value)];
}

Piece.prototype.clickInterface = function(){
  var self = this;
  this.canvas.onclick = function(event){
    var rect = self.canvas.getBoundingClientRect(), root = document.documentElement;
    var x = event.clientX - rect.left - root.scrollLeft;
    var y = event.clientY - rect.top - root.scrollTop;
    if(!self.addingBrush){
      self.x = x;
      self.y = y;
      self.addingBrush = true;
    }else{
      self.addingBrush = false;
      var vel = new Vector(x-self.x,y-self.y);
      var method = ["smear","default"];
      var random = "no";
      var actions = self.actions;
      var randoms = self.randoms;
      for(var action=0; action < actions.length; action++){
        if(actions[action].checked){
          method = actions[action].value.split(" ");
          break;
        }
      }
      for(var rIndex=0; rIndex < randoms.length; rIndex++){
        if(randoms[rIndex].checked){
          random = randoms[rIndex].value;
          break;
        }
      }
      self.uiAddBrush(method[0],method[1],self.x,self.y,vel,random);  
    }
  }
  if(self.addingBrush){
    document.onmousemove = function(event){
      console.log(11);
      var rect = self.canvas.getBoundingClientRect(), root = document.documentElement;
      var x = event.clientX - rect.left - root.scrollLeft;
      var y = event.clientY - rect.top - root.scrollTop;
      var ctx = self.ctx;
      ctx.beginPath();
      ctx.strokeStyle = '#000000';
      ctx.moveTo(self.x,self.y);
      ctx.lineTo(x,y);
      ctx.stroke();

    }
  }else{

  }
}


Piece.prototype.run = function(){
  this.managers.forEach(function(manager){
    manager.run();
  });
  this.ctx.putImageData(this.imgData,0,0);
  this.clickInterface();
}

function getPixel(x_,y_){
  if (x_ < 0 || y_ < 0 || x_ > width || y_ > height){
    return undefined;
  }else{
    return (Math.floor(x_) * 4 + width * Math.floor(y_)*4);
{'fraction_non_alphanumeric': 0.15230524642289348, 'fraction_numerical': 0.009009009009009009, 'mean_word_length': 3.0707506471095773, 'pattern_counts': {'":': 10, '<': 15, '<?xml version=': 0, '>': 9, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '7503878', 'n_tokens_mistral': 3234, 'n_tokens_neox': 3144, 'n_words': 632}