2012年10月2日 星期二

Week04, HW04

4.1

void setup(){
  size(800,600);
  background(255,255,255);
  strokeWeight(2);
  fill(255,0,0);
  rect(0,0,50,50);
  fill(0,255,0);
  rect(0,50,50,50);
  fill(0,0,255);
  rect(0,100,50,50);
  fill(255,255,0);
  rect(0,150,50,50);
  fill(0,0,0);
  rect(0,200,50,50);
  fill(255,255,255);
  rect(750,0,50,50);
  fill(255,255,255);
  ellipse(775, 25, 2,2);
  fill(255);
  rect(750,50,50,50);
  ellipse(775, 75, 6, 6);
  rect(750,100,50,50);
  ellipse(775, 125, 10,10);
  rect(0,250,50,50);
  fill(255,255,255);
  rect(0,500,50,50);
  rect(0,550,50,50);
  rect(750,550,50,50);
  fill(0,0,0);
  text("Save",10,530);
  text("Load",10,580);
  text("Clear",760,580);
  stroke(0,0,0);
}

void draw(){
  if(mouseX&rt;750 && mouseX<800){
    if(mouseY&rt;0 && mouseY<50 && mousePressed){
      strokeWeight(2);
    } 
    else if(mouseY&rt;50 && mouseY<100 && mousePressed){
      strokeWeight(6);
    }
    else if(mouseY&rt;100 && mouseY<150 && mousePressed){
      strokeWeight(10);
    }
    else if(mouseY&rt;500 && mouseY<600 && mousePressed){
      setup();
    }
     else if(mousePressed) line(mouseX,mouseY,pmouseX,pmouseY);
  }
  else if(mouseX&rt;0 && mouseX<50){
    if(mouseY&rt;0 && mouseY<50 && mousePressed){
      stroke(255,0,0);
    } 
    else if(mouseY&rt;50 && mouseY<100 && mousePressed){
      stroke(0,255,0);
    }
    else if(mouseY&rt;100 && mouseY<150 && mousePressed){
      stroke(0,0,255);
    }
    else if(mouseY&rt;150 && mouseY<200 && mousePressed){
      stroke(255,255,0);
    }
    else if(mouseY&rt;200 && mouseY<250 && mousePressed){
      stroke(0,0,0);
    }
    else if(mouseY&rt;250 && mouseY<300 && mousePressed){
      stroke(255,255,255);
    }
    else if(mouseY&rt;500 && mouseY<550 && mousePressed){
      save("Temp.jpg");
    }
    else if(mouseY&rt;550 && mouseY<600 && mousePressed){
      PImage img=loadImage("Temp.jpg");
      image(img,0,0,800,600);
    }
    else if(mousePressed) line(mouseX,mouseY,pmouseX,pmouseY);
  }
  else if(mouseX&rt;50 && mouseX<750 && mousePressed) line(mouseX,mouseY,pmouseX,pmouseY);
}




1 則留言: