1-1
size(500,500); textSize(64); text("Hello World",100,100); fill(255,0,0); text("RED",100,200);
1-2
用字串來輸入文字,利用line、keyPressed
void setup(){ size(500,500); textSize(64); } String line="Imput: "; void draw(){ text(line,100,100); } void keyPressed(){ line +=key; }
1-3
原本一些特殊字元沒辦法出現,所以先試著切換字母的大小寫
void setup(){ size(800,500); textSize(64); } String line="Imput: "; void draw(){ text(line,100,100); } void keyPressed(){ if(key>='A' && key<='Z')line +=key; if(key>='a' && key<='z')line +=key; }
1-4
新增backspace,可以刪除打的字
void setup(){ size(800,500); textSize(64); } String line=""; void draw(){ background(0); text("Input: "+line,50,100); } void keyPressed(){ if(key>='A' && key<='Z')line +=key; if(key>='a' && key<='z')line +=key; if(key==BACKSPACE && line.length()>0){ line= line.substring(0,line.length()-1); } }
2-1
新增音樂
import processing.sound.*; SoundFile file; void setup(){ size(300,300); file=new SoundFile(this,"a.mp3"); file.play(); } void draw(){ }
2-2
新增音效,使用鍵盤輸入播放音樂
import processing.sound.*; SoundFile dadada,good,over; void setup(){ size(300,300); dadada=new SoundFile(this,"dadadadada.mp3"); good = new SoundFile(this,"good.mp3"); over = new SoundFile(this,"over.mp3"); } void draw(){ text("press 1,2,3",100,100); } void keyPressed(){ if(key=='1')dadada.play(); if(key=='2')good.play(); if(key=='3')over.play(); }
2-3
每次打字都會出現音效
import processing.sound.*; SoundFile da,dingdong,ouch; void setup(){ size(800,300); textSize(64); da=new SoundFile(this,"da.mp3"); dingdong = new SoundFile(this,"dingdong.mp3"); ouch = new SoundFile(this,"ouch.mp3"); } String line=""; void draw(){ text("Input: "+line,50,100); } void keyPressed(){ if(key>='A' && key<='Z'){line +=key;da.play();} if(key>='a' && key<='z'){line +=key;da.play();} if(key==BACKSPACE && line.length()>0){ line= line.substring(0,line.length()-1); ouch.play(); } if(key==ENTER){ dingdong.play(); } }
3-1
嘗試打字遊戲,字會慢慢靠近原點
void setup(){ size(400,600); textSize(20); } String Q="hello",A=""; float x=100,y=100; void draw(){ background(0); text(Q,x,y); ellipse(200,550,20,20); float dx=(200-x),dy=(550-y),d=sqrt(dx*dx+dy*dy); x+=dx/d; y+=dy/d; }
3-2
void setup(){ size(400,600); textSize(20); } String Q="hello",A=""; float x=100,y=100; void draw(){ background(0); text(Q,x,y); ellipse(200,550,20,20); float dx=(200-x),dy=(550-y),d=sqrt(dx*dx+dy*dy); x+=dx/d; y+=dy/d; if(keyPressed){ stroke(255,0,0); line(200,500,x,y); } }
3-3
新增顏色(Q跟A設不同的顏色)
void setup(){ size(400,600); textSize(20); } String Q="hello",A=""; float x=100,y=100; void draw(){ background(0); fill(#FFFFFF); text(Q,x,y); fill(#FF0000); text(A,x,y); ellipse(200,550,20,20); float dx=(200-x),dy=(550-y),d=sqrt(dx*dx+dy*dy); x+=dx/d; y+=dy/d; if(keyPressed){ stroke(255,0,0); line(200,500,x,y); } } void keyPressed(){ int i=A.length(); if(key==Q.charAt(i)){ A+=key; } }
3-4
出現字串然後輸入成功後可以換新的字
void setup(){ size(400,600); textSize(20); randomQ(); } void randomQ(){ int i=int(random(QQ.length)); Q=QQ[i]; x=random(0,300); y=random(0,100); } String []QQ={"void","setup","float","string","background","fill"}; String Q="hello",A=""; float x=100,y=100; void draw(){ background(0); fill(#FFFFFF); text(Q,x,y); fill(#FF0000); text(A,x,y); ellipse(200,550,20,20); float dx=(200-x),dy=(550-y),d=sqrt(dx*dx+dy*dy); x+=dx/d; y+=dy/d; if(keyPressed){ stroke(255,0,0); line(200,500,x,y); } } void keyPressed(){ int i=A.length(); if(key==Q.charAt(i)){ A+=key; if(Q.equals(A)){ randomQ(); A=""; } } }
3-5
題目還在考慮中,組員找到:賴奕辰
沒有留言:
張貼留言