在課堂上製作屬於自己的小畫家,我的小畫家具有變換顏色和變換粗細的功能,這樣大家上課就能玩圈圈叉叉囉!
執行圖:
程式碼:
void setup(){
size(600,600);
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,150,50,50);//黑按鈕
fill(255,255,255);
rect(550,0,50,50);//粗按鈕
rect(550,50,50,50);//細按鈕
fill(0,0,0);
ellipse(575,25,40,40);//粗圓
ellipse(575,75,10,10);//細圓
}
int lines=2;
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(0,0,0);
else if(mousePressed && mouseX>550 && mouseY<50){
strokeWeight(++lines);
}
else if(mousePressed && mouseX>550 && mouseY<100){
strokeWeight(--lines);
if(lines<2)lines=2;
}
else if(mousePressed) line(mouseX, mouseY, pmouseX, pmouseY);
}
沒有留言:
張貼留言