2012年10月2日 星期二

Week04 HW04


4-1 畫線

















/*void setup(){
  size(500,400);
}
void draw(){
  line(mouseX, mouseY, pmouseX, pmouseY);  //直接畫線
}*/

void setup(){
  size(500,400);
  background(255);
}
void draw(){
  stroke(0,255,0);
  if(mousePressed)  line(mouseX, mouseY, pmouseX, pmouseY);  //滑鼠點下畫線
}

4-2 小畫家1

















void setup(){
  size(500,400);
  background(255,255,255);
  noStroke();
  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(0,0,0);
  rect(0,150,50,50);
  stroke(0,0,0);
  fill(255,255,255);
  ellipse(30,250,50,50);
  fill(255,255,255);
  ellipse(30,300,50,50);
}
void draw(){
  if(mousePressed && mouseX<50 && mouseY<50) stroke(255,0,0);    //stroke 線顏色
  else if(mousePressed && mouseX<50 && mouseY<100) stroke(0,255,0);  //滑鼠按下、X和Y位置
  else if(mousePressed && mouseX<50 && mouseY<150) stroke(0,0,255);
  else if(mousePressed && mouseX<50 && mouseY<200) stroke(0,0,0);
  else if(mousePressed && mouseX<50 && mouseY<300) save("image1.jpg");  //存檔,processing要先存檔
  else if(mousePressed && mouseX<50 && mouseY<330)  {
    PImage img;   //讀檔
    img = loadImage("image1.jpg");
    image(img,0,0,500,400);
  }
  else if(mousePressed)  line(mouseX, mouseY, pmouseX, pmouseY);  //滑鼠按下畫線
}


4-3 小畫家2

















void setup(){
  size(500,400);
  background(255,255,255);
  noStroke();
  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(0,0,0);
  rect(0,150,50,50);
  stroke(0,0,0);
  fill(255,255,255);
  ellipse(30,250,50,50);
  fill(255,255,255);
  ellipse(30,300,50,50);
  fill(255,255,255);
  rect(450,0,50,50);
  fill(255,255,255);
  ellipse(475,25,15,15);
  fill(255,255,255);
  rect(450,50,50,50);
  fill(255,255,255);
  ellipse(475,75,5,5);
}
  int w=5;  //線粗細預設在5
void draw(){
  if(mousePressed && mouseX<50 && mouseY<50) stroke(255,0,0);    //stroke 線顏色
  else if(mousePressed && mouseX<50 && mouseY<100) stroke(0,255,0);  //滑鼠按下、X和Y位置
  else if(mousePressed && mouseX<50 && mouseY<150) stroke(0,0,255);
  else if(mousePressed && mouseX<50 && mouseY<200) stroke(0,0,0);
  else if(mousePressed && mouseX<50 && mouseY<300) save("image1.jpg");  //存檔,processing要先存檔
  else if(mousePressed && mouseX<50 && mouseY<330){
    PImage file = loadImage("image1.jpg");  //讀檔
    image(file, 0,0,500,400);
  }else if(mousePressed && mouseX>450 && mouseY<50)  strokeWeight(++w);  //線條變粗
  else if(mousePressed && mouseX>450 && mouseY<100){ 
    strokeWeight(--w);  //線條變細
    if(w<2) w=2;  //變細最小到2
  }
  else if(mousePressed)  line(mouseX, mouseY, pmouseX, pmouseY);  //滑鼠按下畫線
}

4-4 心得
自己也可以設計小畫家的簡易功能很有趣。

1 則留言: