執行畫面
儲存畫面
void setup(){
size(500,400);
background(255,255,255);
fill(255,0,0);
rect(0,0,50,50);//Red
fill(0,255,0);
rect(0,50,50,50);//Green
fill(0,0,255);
rect(0,100,50,50);//Blue
fill(255,255,255);
rect(0,150,50,50);//eraser
fill(0,0,0);
text("eraser",6,180);
fill(255,255,255);
rect(0,200,50,50);//save
fill(0,0,0);
text("save",10,230);
fill(255,255,255);
rect(450,0,50,50);
ellipse(475, 25, 2,2);//samllpen
rect(450,50,50,50);
ellipse(475, 75, 6, 6);//midpen
rect(450,100,50,50);
ellipse(475, 125, 10,10);//largepen
}
void draw(){
if(mousePressed && mouseX<50 && mouseY <50) stroke(255,0,0);
else if(mousePressed && mouseX<50 && mouseY <100) stroke(0,255,0);
else if(mousePressed && mouseX<50 && mouseY <150) stroke(0,0,255);
else if(mousePressed && mouseX<50 && mouseY <200) stroke(255,255,255);
else if(mousePressed && mouseX<50 && mouseY <250) save("QQQ.png");
else if(mousePressed && mouseX>450 && mouseY <50) strokeWeight(2);
else if(mousePressed && mouseX>450 && mouseY <100) strokeWeight(6);
else if(mousePressed && mouseX>450 && mouseY <150) strokeWeight(10);
if(mousePressed) line(mouseX,mouseY,pmouseX,pmouseY);
}
3. 心得
小畫家的原理很好理解
區塊滑鼠點到就換色
不過如果顏色要設多一點,像電腦的小畫家一樣
這樣程式碼不就必須要寫很長@@??
現在光做簡易版就有點眼花了
不知道有沒有辦法簡化一點
95
回覆刪除