製作了8種顏色方塊可選則顏色
右方有 "+" 與 "-" 可以調整畫筆粗細
下方
ave按鈕可以存取影像
load按鈕可以載入所存取的影像
void setup()
{
size(600,500);
background(172,255,255);
//background(0,125,63);
//選顏色方塊
fill(255,255,255);
rect(10,10,30,30,3);
fill(192,192,192);
rect(10,50,30,30,3);
fill(128,64,0);
rect(10,90,30,30,3);
fill(255,128,0);
rect(10,130,30,30,3);
fill(255,255,0);
rect(10,170,30,30,3);
fill(108,180,68);
rect(10,210,30,30,3);
fill(252,211,193);
rect(10,250,30,30,3);
fill(0,0,255);
rect(10,290,30,30,3);
fill(0,157,220);
rect(10,330,30,30,3);
//選筆粗
fill(255,255,255);
rect(560,10,30,30,3);
String w = "+";
fill(0);
text(w,572,30);
fill(255,255,255);
rect(560,50,30,30,3);
String d = "-";
fill(0);
text(d,572,70);
//button_save
fill(0,120,0);
rect(450,450,50,30,3);
String s = "save";
fill(255);
text(s,462,470);
//button_load
fill(128,64,64);
rect(507,450,50,30,3);
String l = "load";
fill(255);
text(l,520,470);
stroke(0,0,0);
strokeWeight(1);
}
int ha=5;
void draw()
{
//筆觸大小
if(mousePressed && mouseX>450 && mouseY<50){
strokeWeight(++ha);
if(ha>20)ha=20;
}
else if(mousePressed && mouseX>560 && mouseX<590 && mouseY>50 && mouseY<80){
strokeWeight(--ha);
if(ha<2)ha=2;
}
//button事件
if(mousePressed && mouseX>450 && mouseX<500 && mouseY>450 && mouseY<480){
save("pic_1.jpg");
}
else if(mousePressed && mouseX>507 && mouseX<557 && mouseY>450 && mouseY<480){
PImage file = loadImage("pic_1.jpg");
image(file, 0,0,600,500);
}
//顏色
else if(mousePressed && mouseX<40 && mouseY>10 && mouseY<40)stroke(255,255,255);
else if(mousePressed && mouseX<40 && mouseY>50 && mouseY<80)stroke(192,192,192);
else if(mousePressed && mouseX<40 && mouseY>90 && mouseY<120)stroke(128,64,0);
else if(mousePressed && mouseX<40 && mouseY>130 && mouseY<160)stroke(255,128,0);
else if(mousePressed && mouseX<40 && mouseY>170 && mouseY<200)stroke(255,255,0);
else if(mousePressed && mouseX<40 && mouseY>210 && mouseY<240)stroke(0,128,0);
else if(mousePressed && mouseX<40 && mouseY>250 && mouseY<280)stroke(252,211,193);
else if(mousePressed && mouseX<40 && mouseY>290 && mouseY<320)stroke(0,0,255);
else if(mousePressed && mouseX<40 && mouseY>330 && mouseY<360)stroke(0,157,220);
else if(mousePressed)line(mouseX,mouseY,pmouseX,pmouseY);
}
心得
小畫家的介面製作好好玩
但是其實我還希望可以做出橡皮擦的功能(因為常常會不小心畫錯)
老師有提供一個方法,是多一個筆刷並設成背景顏色。
但是我想要的是四還原功能的筆刷~~
還有點選 + - 部分加大縮小筆刷大小
但是顏色都會殘留在上面
100
回覆刪除