用processing製作一個小畫家,並畫圖
程式碼:
void setup(){ size(500,400); background(255,255,255); //顏色盤 fill(0,0,0); rect(0,350,25,25); fill(255,0,0); rect(25,350,25,25); fill(255,128,0); rect(50,350,25,25); fill(255,255,0); rect(75,350,25,25); fill(0,128,0); rect(100,350,25,25); fill(0,0,255); rect(125,350,25,25); fill(0,0,128); rect(150,350,25,25); fill(64,0,128); rect(175,350,25,25); fill(255,255,255); rect(0,375,25,25); fill(255,128,128); rect(25,375,25,25); fill(255,170,90); rect(50,375,25,25); fill(255,255,157); rect(75,375,25,25); fill(0,255,0); rect(100,375,25,25); fill(0,255,255); rect(125,375,25,25); fill(0,128,255); rect(150,375,25,25); fill(128,0,255); rect(175,375,25,25); //橡皮擦 fill(255,255,255); rect(200,350,75,25); fill(0,0,0); text("橡皮擦",220,366); //清除畫面 fill(255,255,255); rect(200,375,75,25); fill(0,0,0); text("清除畫面",213,392); //調粗細 fill(160,210,255); rect(275,350,50,25); ellipse(300,362.5,1,1); fill(160,210,255); rect(325,350,50,25); ellipse(350,362.5,5,5); fill(160,210,255); rect(375,350,50,25); ellipse(400,362.5,10,10); fill(90,180,255); rect(275,375,75,25); fill(0,0,0); text("越來越細",288,392); fill(90,180,255); rect(350,375,75,25); fill(0,0,0); text("越來越粗",363,392); //存檔 fill(255,140,255); rect(425,350,75,50); fill(0,0,0); text("存檔",452,380); } int w=5; void draw(){ //第一行顏色 if(mousePressed && mouseX<25 && mouseY&rt;350 && mouseY<375) stroke(0,0,0); else if(mousePressed && mouseX<50 && mouseY&rt;350 && mouseY<375) stroke(255,0,0); else if(mousePressed && mouseX<75 && mouseY&rt;350 && mouseY<375) stroke(255,128,0); else if(mousePressed && mouseX<100 && mouseY&rt;350 && mouseY<375) stroke(255,255,0); else if(mousePressed && mouseX<125 && mouseY&rt;350 && mouseY<375) stroke(0,128,0); else if(mousePressed && mouseX<150 && mouseY&rt;350 && mouseY<375) stroke(0,0,255); else if(mousePressed && mouseX<175 && mouseY&rt;350 && mouseY<375) stroke(0,0,128); else if(mousePressed && mouseX<200 && mouseY&rt;350 && mouseY<375) stroke(64,0,128); //第二行顏色 else if(mousePressed && mouseX<25 && mouseY&rt;375 && mouseY<400) stroke(255,255,255); else if(mousePressed && mouseX<50 && mouseY&rt;375 && mouseY<400) stroke(255,128,128); else if(mousePressed && mouseX<75 && mouseY&rt;375 && mouseY<400) stroke(255,170,90); else if(mousePressed && mouseX<100 && mouseY&rt;375 && mouseY<400) stroke(255,255,157); else if(mousePressed && mouseX<125 && mouseY&rt;375 && mouseY<400) stroke(0,255,0); else if(mousePressed && mouseX<150 && mouseY&rt;375 && mouseY<400) stroke(0,255,255); else if(mousePressed && mouseX<175 && mouseY&rt;375 && mouseY<400) stroke(0,128,255); else if(mousePressed && mouseX<200 && mouseY&rt;375 && mouseY<400) stroke(128,0,255); //橡皮擦 else if(mousePressed && mouseX<275 && mouseY&rt;350 && mouseY<375){ stroke(255,255,255); strokeWeight(5); } //清除畫面 else if(mousePressed && mouseX<275 && mouseY&rt;375){ fill(255,255,255); noStroke(); rect(0,0,500,350); } //調粗細 else if(mousePressed && mouseX<325 && mouseY&rt;350 && mouseY<375){ w=1; strokeWeight(w); } else if(mousePressed && mouseX<375 && mouseY&rt;350 && mouseY<375){ w=5; strokeWeight(w); } else if(mousePressed && mouseX<425 && mouseY&rt;350 && mouseY<375){ w=10; strokeWeight(w); } else if(mousePressed && mouseX&rt;355 && mouseX<425 && mouseY&rt;375){ strokeWeight(++w); } else if(mousePressed && mouseX&rt;275 && mouseX<350 && mouseY&rt;375){ strokeWeight(--w); if(w<2) w=2; } //存檔 else if(mousePressed && mouseX&rt;425 &&mouseY&rt;350){ save("C:/Users/wfim_801205/Desktop/apicture.jpg"); } else if(mousePressed) line(mouseX, mouseY, pmouseX, pmouseY); }
存檔解釋圖,還有清除鍵:
自己畫的圖:
&rt沒用
回覆刪除