自己做小畫家
(1)開啟視窗,有筆的效果
(2)加上if(mousePressed),按下滑鼠才會畫
(3)背景設成白色(一次),放在setup()裡面
(4)設定鍵盤按鍵可以更改畫筆顏色 ,使用keyPressed()
(5)使用滑鼠滾輪更改筆觸大小,記得增加if(now<1) now=1;
才不會出現筆觸是負數的問題
(6)存檔,首先要先存一個資料夾,按s儲存、r讀檔
**if(img!=null),一定要加這行,讀不到檔才不會當機
(7)開出調色盤,先存一張調色盤的圖片,放到資料夾裡面,
按 'c' 先儲存已畫出的圖,並顯示出調色盤;再按下 'c' 關閉調色盤,
並開起之前的圖。
程式碼:
if(key=='c' && bColorSelect==false){
bColorSelect=true;
save("bcolor.png");
PImage img=loadImage("colormap.png");
if(img!=null) image(img,0,0);
}else if(key=='c' && bColorSelect==true){
bColorSelect=false;
PImage img=loadImage("bcolor.png");
if(img!=null) image(img,0,0);
}
(8)吸顏色改畫筆顏色
if(bColorSelect){
loadPixels();
stroke(pixels[mouseX+mouseY*width]);
}












沒有留言:
張貼留言