Doodle in Grey – cool paint app

This is a cool doodle app – and it will save your picture.


int oldX=0,oldY=0,drawcolor=0;

void setup() {
  size (400,300);
  background(255);
  smooth();
  frameRate(123);
}

void draw() {
  int n=0;
  int colors[]= {
    0,100,200,250
  };

  if(mousePressed) {
    strokeWeight(3);
    stroke(drawcolor);
    line(mouseX,mouseY,oldX,oldY);


    //check if the exit button is pressed
    if (inside (10,10,40,40)) {
      exit();
    }
    
    //check if save button is pressed
    if (inside(10,260,40,290)){
      
      save("mypicture.png");
      background(255);
    }    

    //color selector
    for(n=0;n<4;n++) {
      if (inside(360,10+n*40,390,40+n*40)) {
          
        if (mouseButton==LEFT){
          drawcolor = colors[n];
        }
        else{
        background(colors[n]);
        }  
      }
    }
  }

  oldX=mouseX;
  oldY=mouseY;

  //draw close button
  stroke(0);
  strokeWeight(1);
  rect(10,10,30,30);
  line(10,10,40,40);
  line(40,10,10,40);
  
  //save button
  rect(10,260,30,30);
  rect(15,265,20,20);

  //draw color buttons
  for(n=0;n<4;n++)
  {
    fill(colors[n]);
    rect(360,10+n*40,30,30);
  }
}
// returns true if mouse is inside this rectangle
boolean inside(int left, int top, int right, int bottom ) {
  
  if (mouseX>left && mouseX<right && mouseY>top && mouseY<bottom ) {

    return true;
  }

  else {
    return false;
  }
}
Advertisements

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s