Im making a simple drawing app and I want to add some features but don't know how.

I'd like to add a feature to increase the brush size with the up and down arrows (im using ellipse's), and also make a feature where I can click a triangle which ive made already to change the shape of the brush. Ive tried but cant figure it out. Any help would be appreciated.

Answers

  • edited August 2017

    It wouldn't be easier if you show your code or your attempt.

    1.

    Now for cursor use a function keyPressed () :

    void keyPressed () {
    
        // See reference for keyPressed 
    
        if(keyCode==UP) {
    
             diameter++;
    
        } 
    
        else if(keyCode==DOWN) {
    
             diameter--;
    
        }
    
    } // function 
    

    use the float variable diameter in your ellipse command (your brush size)

    2.

    Triangle

    When the three corners of the triangle are stored in a database or you know them as variables or numbers in your code you can calculate the middle of the triangle by adding the three X values and divide by 3 and repeat for y values.

    float middleTriangleX = ( x1 + x2 + x3 ) / 3.0; 
    

    Then use dist() to calculate if the mouse is inside the triangle:

    See reference for dist() :

    if(dist(mouseX, mouseY, middleTriangleX, middleTriangleY) < 50) {
          //inside 
    }
    

    I only show the principle here you have to write it yourself. Especially declaring variables.

    Chrisir ;-)

    [EDITED]

  • @djamboo --see keyCode in the references:

    How to change a variable with UP / DOWN:

    int x;
    
    void draw(){
      background(0);
      text(x,width/2,height/2);
    }
    
    void keyPressed(){
      if(keyCode==UP){
        x = x+1;
      }
      if(keyCode==DOWN){
        x = x-1;
      }
    }
    
Sign In or Register to comment.