互動技術概論
Week03
1. 今日任務:畫出小畫家
滑鼠按下畫出線,不再是one stroke line
可以透過滑鼠事件偵測,讓筆畫可以構成圖。
實現按鈕如下圖
int x=0;
int y=0;
int w=50;
int h=50;
void setup(){
size(800,400);
rect(0,0,800,400);
fill(255,0,0);rect(x,y,w,h);
fill(255,255,0);rect(x,y+50,w,h);
fill(0,255,0); rect(x,y+100,w,h);
fill(0,255,255); rect(x,y+150,w,h);
fill(0,0,255); rect(x,y+200,w,h);
}
void draw(){
if(mousePressed){
if (mouseX < 50 && mouseY < y+h) {
stroke(255,0,0);
line(mouseX,mouseY,pmouseX,pmouseY);
}
else if (mouseX <50 && mouseY < y+h+50)
stroke(255,255,0);
else if (mouseX <50 && mouseY < y+h+100)
stroke(0,255,0);
else if (mouseX <50 && mouseY < y+h+150)
stroke(0,255,255);
else if (mouseX <50 && mouseY < y+h+200){
stroke(0,0,255);
}
//stroke(20);
line(mouseX,mouseY,pmouseX,pmouseY);
}
}
*做成小畫家,可以根據旁邊的按鈕選擇不同的顏色,以實現小畫家,另外加上比畫粗細,可以提供選擇。
int x=0;
int y=0;
int w=50;
int h=50;
void setup(){
size(800,400);
rect(0,0,800,400);
fill(255,0,0);rect(x,y,w,h);
fill(255,255,0);rect(x,y+50,w,h);
fill(0,255,0); rect(x,y+100,w,h);
fill(0,255,255); rect(x,y+150,w,h);
fill(0,0,255); rect(x,y+200,w,h);
}
void draw(){
if(mousePressed){
if (mouseX < 50 && mouseY < y+h) {
stroke(255,0,0);
line(mouseX,mouseY,pmouseX,pmouseY);
}
else if (mouseX <50 && mouseY < y+h+50)
stroke(255,255,0);
else if (mouseX <50 && mouseY < y+h+100)
stroke(0,255,0);
else if (mouseX <50 && mouseY < y+h+150)
stroke(0,255,255);
else if (mouseX <50 && mouseY < y+h+200){
stroke(0,0,255);
}else if (mouseX <50 && mouseY < y+h+450){
strokeWeight((y+h+450-mouseY)/10);
}
//stroke(20);
if(mouseX>50){
line(mouseX,mouseY,pmouseX,pmouseY);
}
}
}
***需要把函式放在正確的地方 主程式要乾淨俐落
int x=0; int y=0; int w=50; int h=50; void setup(){ size(800,400); rect(0,0,800,400); fill(255,0,0);rect(x,y,w,h); fill(255,255,0);rect(x,y+50,w,h); fill(0,255,0); rect(x,y+100,w,h); fill(0,255,255); rect(x,y+150,w,h); fill(0,0,255); rect(x,y+200,w,h); } void draw(){ } void mousePressed(){ if (mouseX < 50 && mouseY < y+h) { stroke(255,0,0); line(mouseX,mouseY,pmouseX,pmouseY); } else if (mouseX <50 && mouseY < y+h+50) stroke(255,255,0); else if (mouseX <50 && mouseY < y+h+100) stroke(0,255,0); else if (mouseX <50 && mouseY < y+h+150) stroke(0,255,255); else if (mouseX <50 && mouseY < y+h+200){ stroke(0,0,255); }else if (mouseX <50 && mouseY < y+h+450){ strokeWeight((mouseY-250)/10); } } void mouseDragged(){ if(mouseX>50){ line(mouseX,mouseY,pmouseX,pmouseY); } } void keyPressed(){ if(keyCode==UP){ } if(keyCode==DOWN){ } }
沒有留言:
張貼留言