2016年9月12日 星期一

WEEK_02 海野土佐衛門畫肥嘟嘟左衛門

課堂作業
=======================================================================
(一)
試做類似小畫家的程式
void setup(){
    size(600,600);
}
void draw(){
   if(mousePressed) line(mouseX,mouseY,pmouseX,pmouseY);
}
mousePressed:滑鼠在按下去才執行
按鍵
keyPressed():按鍵在按下去才執行
if(key=='1') stroke(#FFDFA2);
在按鍵1上作顏色的更動
滾輪
int now=1;
void mouseWheel(MouseEvent event){
  float e = event.getCount();
  now += e;
  if(now<1) now=1;//這個是讓最小值不要低於0
  strokeWeight(now);
  println(now);
}
存檔與讀檔
if(key=='s') save("now.png");
if(key=='r'){
    PImage img=loadImage("now.png");
    if(img!=null) image(img, 0,0);
  }
重開
成功讀取然後繼續作畫...
伪調色盤
boolean bColorSelect=false;//記得boolean要宣告 
if(key=='c' && bColorSelect==false){
    bColorSelect=true;
    save("beforeColor.png");
    PImage img=loadImage("colorMap.png");
    image(img,0,0);
  }
else if(key=='c'&& bColorSelect==true){
    bColorSelect=false;
    PImage img=loadImage("beforeColor.png");
    if(img!=null) image(img,0,0);
  }
然後就有會調色盤了
if(bColorSelect){
    loadPixels();
    stroke(pixels[mouseX+mouseY*width]);
}
把滑鼠放在調色盤在關掉會選取調色盤的座標

=======================================================================
調色盤
void setup(){
    size(600,600);
    background(255);
}
void draw(){
  if(bColorSelect){
    loadPixels();
    stroke(pixels[mouseX+mouseY*width]);
  }
  else if(mousePressed) line(mouseX,mouseY,pmouseX,pmouseY);
}
boolean bColorSelect=false;
void keyPressed(){
  if(key=='1') stroke(#FFDFA2);
  if(key=='2') stroke(#BA00FF);
  if(key=='3') stroke(#21FF00);
  if(key=='s') save("now.png");
  if(key=='r'){
    PImage img=loadImage("now.png");
    if(img!=null) image(img, 0,0);
  }
  if(key=='c' && bColorSelect==false){
    bColorSelect=true;
    save("beforeColor.png");
    PImage img=loadImage("colorMap.png");
    image(img,0,0);
  }else if(key=='c'&& bColorSelect==true){
    bColorSelect=false;
    PImage img=loadImage("beforeColor.png");
    if(img!=null) image(img,0,0);
  }
}
int now=1;
void mouseWheel(MouseEvent event){
  float e = event.getCount();
  now += e;
  if(now<1) now=1;
  strokeWeight(now);
  println(now);

}

沒有留言:

張貼留言