import processing.core.*; 
import processing.data.*; 
import processing.event.*; 
import processing.opengl.*; 

import java.util.HashMap; 
import java.util.ArrayList; 
import java.io.File; 
import java.io.BufferedReader; 
import java.io.PrintWriter; 
import java.io.InputStream; 
import java.io.OutputStream; 
import java.io.IOException; 

public class Success_BrushTest extends PApplet {

PImage stamp;
float angle = 0;
float speed = 0;

public void setup(){ // Happens once when program starts.
  size(550, 989); // 'width' and 'height' is now available.
  background(255);
  stamp  = loadImage("stamp.png");
  imageMode(CENTER);
}

public void draw (){ // Hapens every frame (60 fps).
   if(mousePressed){
   brush();
  }
}

public void mouseDragged(){
  PVector mousePos  = new PVector(mouseX, mouseY);
  PVector pmousePos = new PVector(pmouseX, pmouseY);
  speed = mousePos.dist(pmousePos);

  if(speed > 5){
    mousePos.sub(pmousePos);
    angle = mousePos.heading();
  } else {
    angle = 0;
  }
  
}

public void brush(){
  translate(mouseX, mouseY);
  scale(speed/20);
  rotate(angle);
  tint(255, 255, 255, 255-speed);
  image(stamp, 0, 0);
  //translate(-mouseX, -mouseY);
  
  //println(speed);
  //if(speed > 30){
    //image(stamp, 0, 0);
}

/* Responding to the mouse being pressed and released.
void mousePressed(){ // Runs once when you press down mouse
  strokeWeight(random(10, 50));
}

void mouseReleased(){ // Runs when mouse is released.
  background(255);
}

void brush(){ 
    line(pmouseX, pmouseY, mouseX, mouseY);
}
*/

/* // Getting the speed of the mouse
void draw_line(){
  
  // Two Vectors
  PVector mousePos  = new PVector(mouseX, mouseY);
  PVector pmousePos = new PVector(pmouseX, pmouseY);
  float speed = (mousePos.dist(pmousePos));
  
  strokeWeight(speed);
  line(pmouseX, pmouseY, mouseX, mouseY);
  
}
*/

/* // Getting tthe normalized mouse position
void draw_line(){
  // Hapens when the mouse moves
  // and the mouse button is held down. 
  
  // Normalizing
  float horizontal_position = mouseX / float(width);
  float vertical_position   = mouseY / float(height);
  
  strokeWeight(horizontal_position * random(30, 50));
  stroke(vertical_position * random(255));
  
  line(pmouseX, pmouseY, mouseX, mouseY);
}
*/
  static public void main(String[] passedArgs) {
    String[] appletArgs = new String[] { "Success_BrushTest" };
    if (passedArgs != null) {
      PApplet.main(concat(appletArgs, passedArgs));
    } else {
      PApplet.main(appletArgs);
    }
  }
}
