pmouse 前一個滑鼠座標

mousePressed 滑鼠壓下去才可以畫線

keyPressed 鍵盤按數字,可以改顏色

mouseWheel 滾輪 調整粗細
改變筆觸粗細 (利用滑鼠滾輪改變)
int now=1;
void mouseWheel(MouseEvent event) { //滾輪
float e = event.getCount();
now += e; //
if (now<1) now=1; //
strokeWeight(now); //筆觸根據滾輪改變大小
println (now); }

存檔 / 讀檔
void keyPressed(){
if (key=='1')stroke(#FF0004);
if (key=='2')stroke(#00FF2C);
if (key=='3')stroke(#008EFF);
if (key=='s')save("now.png"); //按's'存檔
if (key=='r'){ //按'r'讀檔
PImage img=loadImage("now.png"); //讀入名為now.png的檔案
if (img!=null) image(img, 0, 0);} //如果檔案不等於null(檔案存在), } 檔案放在(0,0)的位子

叫出調色盤 (利用存檔讀檔)
要先自己存一張調色盤的圖然後存檔到sketcf(ctrl+k)的資料夾中
void keyPressed(){
if (key=='1')stroke(#FF0004);
if (key=='2')stroke(#00FF2C);
if (key=='3')stroke(#008EFF);
if (key=='s')save("now.png");
if (key=='r'){
PImage img=loadImage("now.png");
if (img!=null) image(img, 0, 0);
}
if (key=='c'){ //當按下'c'時
save("beforeColor.png"); //將畫好的圖先存檔
PImage img=loadImage("colorMap.PNG"); //貼上調色盤圖片
image(img, 0, 0); //放在(0,0)的位置
}
if (key=='d'){ //當按下'd'時
PImage img=loadImage("beforeColor.png"); //叫出貼上調色盤前畫的圖
if (img!=null) image(img, 0, 0);
}
}
讓調色盤真的能選線條顏色
加入程式碼
void draw(){
if(bColorSelect){
loadPixels();
stroke(pixels[mouseX+mouseY*width]);
}
else if(mousePressed) line(mouseX, mouseY, pmouseX, pmouseY);
}


沒有留言:
張貼留言