void setup(){ size(500,400); background(223,255,255); fill(174,87,0); rect(0,0,50,50); fill(248,189,67); rect(0,50,50,50); fill(0); rect(0,100,50,50); fill(255,255,255); rect(0,250,50,50); fill(255); rect(0,150,50,50); //save rect(0,200,50,50); //erase fill(255,255,255); rect(450,0,50,50); ellipse(475, 25, 2,2); fill(255); rect(450,50,50,50); ellipse(475, 75, 6, 6); rect(450,100,50,50); ellipse(475, 125, 10,10); strokeWeight(1); } void draw(){ if(mousePressed && mouseX<50 && mouseY<50) stroke(174,87,0); else if(mousePressed && mouseX<50 && mouseY<100) stroke(248,189,67); else if(mousePressed && mouseX<50 && mouseY<150) stroke(0); else if(mousePressed && mouseX<50 && mouseY<200) stroke(255); else if(mousePressed && mouseX<50 && mouseY<250) save("aaa.png"); //save else if(mousePressed && mouseX<50 && mouseY<300) { PImage file = loadImage("aaa.png"); image(file,0,0,500,400); } //erase else if(mouseX&rt;450 && mouseX<500 && mouseY&rt;0 && mouseY<50 && mousePressed) { strokeWeight(3); } else if(mouseX&rt;450 && mouseX<500 && mouseY&rt;50 && mouseY<100 && mousePressed) { strokeWeight(6); } else if(mouseX&rt;450 && mouseX<500 && mouseY&rt;100 && mouseY<150 && mousePressed) { strokeWeight(10); } if (mousePressed) line(mouseX,mouseY,pmouseX,pmouseY); }
2.心得
今天教得很有趣,竟然用簡單的程式就可以做出小畫家 還可以自己選顏色畫自己喜歡的圖, 還可以存檔、復原,很好玩:D
沒有留言:
張貼留言