程式碼
void setup(){
size(500,400);
background(241,224,131);
fill(255,255,255); //save
rect(0,250,50,50);
fill(0,0,0);
text("Save",10,280);
fill(255,255,255); //load
rect(0,300,50,50);
fill(0,0,0);
text("Load",10,330);
fill(192,192,192); //粗
rect(450,0,50,50);
fill(255,0,0);
text("粗筆",463,30);
fill(192,192,192); //細
rect(450,50,50,50);
fill(255,0,0);
text("細筆",463,80);
noStroke();
fill(255,0,0); //red
rect(0,0,50,50);
fill(233,33,183); //pink
rect(0,50,50,50);
fill(255,255,0);//yellow
rect(0,100,50,50);
fill(0,255,0); //green
rect(0,150,50,50);
fill(0,0,255); //blue
rect(0,200,50,50);
}
int s=5;
void draw(){
if(mousePressed && mouseX<50 && mouseY<50) stroke(255,0,0);
else if(mousePressed && mouseX<50 && mouseY<100) stroke(233,33,183);
else if(mousePressed && mouseX<50 && mouseY<150) stroke(255,255,0);
else if(mousePressed && mouseX<50 && mouseY<200) stroke(0,255,0);
else if(mousePressed && mouseX<50 && mouseY<250) stroke(0,0,255);
else if(mousePressed && mouseX<50 && mouseY<300) save("pic.png");
else if(mousePressed && mouseX<50 && mouseY<350){
PImage file = loadImage("pic.png");
image(file, 0,0,500,400);
}else if(mousePressed && mouseX>450 && mouseY<50){
strokeWeight(++s);
}
else if(mousePressed && mouseX>450 && mouseY<1000){
strokeWeight(--s);
if(s<3)s=3;
}
else if(mousePressed) line(mouseX, mouseY, pmouseX, pmouseY);
}
圖片
課堂心得
自己做小畫家好酷,可以調整顏色筆的粗細,很特別。
90
回覆刪除