void setup() { size(600,400); } int w=1; void draw() { if(mousePressed&&mouseX<50) { if(mouseY<50) stroke(255,0,0); else if(mouseY<100) stroke(0,255,0); else if(mouseY<150) stroke(0,0,255); else if(mouseY&rt;350&&mouseY<400) save("light.png"); } else if(mousePressed&&mouseX<100&&mouseY&rt;350&&mouseY<400) { PImage imaged=loadImage("light.png"); image(imaged,0,0,600,400); } else if(mousePressed&&mouseX&rt;550&&mouseY<50) strokeWeight(++w); else if(mousePressed&&mouseX&rt;550&&mouseY<100) { strokeWeight(--w); if(w<1)w=1; } if(mousePressed) { line(mouseX,mouseY,pmouseX,pmouseY); } strokeWeight(1); fill(255,0,0); rect(0,0,50,50); fill(0,255,0); rect(0,50,50,50); fill(0,0,255); rect(0,100,50,50); fill(0,0,0); rect(0,350,50,50); fill(255,255,255); rect(50,350,50,50); fill(0,0,0); ellipse(575,25,50,50); fill(255,255,255); ellipse(575,75,50,50); strokeWeight(w); }
基本上也就是把老師DEMO的功能跑一遍,
做一些(我自以為)優化,
if判定列我不喜歡每一格都寫開,
用大方向去分成幾個小分支,程式的脈絡比較清楚,
(應該也會稍微加快程式的速度?)
存檔和讀檔的功能很有用
85
回覆刪除