Ass­i­g­n­m­e­n­t 3 Ske­t­c­h­p­a­d

by Alexander Chapkin
  • Show Code
/** @peep sketch */
/* @pjs font=/uploads/16177/controllerfouroblique.otf; */
//General setup.
void setup () 
  {
    size(800, 600);
    background(255);
    stroke(0);
    //Font.
    PFont font = createFont("/uploads/16177/controllerfouroblique.otf", 15);
    textFont(font);
  } 
 
//Text and drawing tools.
void draw () {
  //All the text has to be first, otherwise, it'll get covered by drawings.
  fill(125);
  text("Initiate drawing by clicking.", 20, 20);
  //Most colours according to 'https://www.colorcodehex.com'.
  text("q-White w-Black e-Grey r-Green t-Blue y-Red u-Yellow i-Cyan o-Magenta", 20, 40);
  text("Change tool size with keys 1 - 9.", 20, 60);
  text("z-Spray x-Circles c-Brush v-Orbs b-Squares n-Fill White m-Fill Black", 20, 80);
 
  //Tool sizes.
  if (key == '1')
  {
    strokeWeight(1);
  }
  if (key == '2')
  {
    strokeWeight(2);
  }
  if (key == '3')
  {
    strokeWeight(3);
  }
  if (key == '4')
  {
    strokeWeight(4);
  }
  if (key == '5')
  {
    strokeWeight(5);
  }
  if (key == '6')
  {
    strokeWeight(6);
  }
  if (key == '7')
  {
    strokeWeight(7);
  }
  if (key == '8')
  {
    strokeWeight(8);
  }
  if (key == '9')
  {
    strokeWeight(9);
  }
 
  //Drawing tools.
  if (mousePressed == true) 
    {
      line(mouseX, mouseY, pmouseX, pmouseY);
    }
  if (key == 'q')
    {
      stroke(255);
    }
  if (key == 'w')
    {
      stroke(0);
    }
  if (key == 'e')
    {
      stroke(125, 125, 125);
    }    
  if (key == 'r')
    {
      stroke(0, 255, 0);
    }
  if (key == 't')
    {
      stroke(0, 0, 255);
    }
  if (key == 'y')
    {
      stroke(255, 0, 0);
    }
  if (key == 'u')
    {
      stroke(255, 255, 0);
    }
  if (key == 'i')
    {
      stroke(0, 255, 255);
    }
  if (key == 'o')
    {
      stroke(255, 0, 255);
    }    
 
  //Complex drawing tools.  
  if (key == 'z') 
    {
      if (mousePressed == true)
        {
          spray ();
        }
    }
  if (key == 'x')
    {
      fill(255);
      ellipse(mouseX, mouseY, 20, 20);
    }
  if (key == 'c') 
    {
      brush ();
    }
  if (key == 'v')
    {
      fill(0);
      ellipse(mouseX, mouseY, 20, 20);
    }
  if (key == 'b')
    {
      fill(255);
      rect(mouseX, mouseY, 20, 20);
    } 
  if (key == 'n')
    {
      fill(255);
      rect(0, 0, 800, 600);
    }  
  if (key == 'm')
    {
      fill(0);
      rect(0, 0, 800, 600);
    }      
  }
//And end of simple lines or key presses. 
 
//Start of coding for more complex drawing tools.
//Spray.
void spray () 
  {
    strokeWeight(0);
    //Speed of spray.
    int maxIterations = 25;
    //Spray's width.
    int width1 = 30;
    //Radii.
    float rad;
    //Angle.
    float angle1;
    //Positioning.
    float x;
    float y;
    //Spray qualities.
    for (int i = 0; i < maxIterations; i++) 
      {
        rad = random(width1);
        angle1 = random(360);
        x=(rad*cos(radians(angle1)))+mouseX;
        y=(rad*sin(radians(angle1)))+mouseY;
        point(x, y);
      }
  }
 
//Brush.
void brush () 
  {
    float d = dist(pmouseX, pmouseY, mouseX, mouseY);
    if (mousePressed == true) 
      {
        strokeWeight(constrain(20-d, 3, 20));
        line(mouseX, mouseY, pmouseX, pmouseY);
      }
  }

Comments

Nobody has said anything yet.