WEEK06
1.
size(500,500);
textSize(64);
text("Hello World",100,100);
fill(255,0,0);
text("Red",100,200);
//紅色字
//換行
2.
void setup(){
size(500,500);
textSize(64);
}
String line = "Input: ";
void draw(){
text(line,100,100);
}
void keyPressed(){
line += key;
}
3.
void setup(){
size(500,500);
textSize(64);
}
String line = "Input: ";
void draw(){
text(line,100,100);
}
void keyPressed(){
if(key>='A' && key<='Z') line += key;
if(key>='a' && key<='z') line += key;
}
4.
void setup(){
size(500,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);
}
}
5.加上音樂 要開副檔名才會記得加進去
import processing.sound.*;
//https://processing.org/reference/libraries/sound/index.html
SoundFile file;
void setup(){
size(300,300);
file = new SoundFile(this, "a.mp3");
file.play();
}
void draw(){
}
6.多個音檔連著播(檔案a,b,c)
7.
import processing.sound.*;
SoundFile a,b,c;
void setup(){
size(800,400);
textSize(64);
a = new SoundFile(this, "a.mp3");
b = new SoundFile(this, "b.mp3");
c = new SoundFile(this, "c.mp3");
}
String line = "";
void draw(){
background(0);
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();
}
}
8.射線
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=(500-y), d = sqrt(dx*dx+dy*dy)*3;
x += dx/d;
y += dy/d;
if(keyPressed){
stroke(255,0,0);
line(200,550,x,y);
}
}
9.射線上色 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=(500-y), d = sqrt(dx*dx+dy*dy)*3;
x += dx/d;
y += dy/d;
if(keyPressed){
stroke(255,0,0);
line(200,550,x,y);
}
}
void keyPressed(){
int i = A.length();
if(key==Q.charAt(i)){
A+=key;
}
}
10.按著上下左右鍵盤&按對應字母->會顯示在上面
void setup(){
size(400,600);
textSize(20);
randomQ();
}
void randomQ(){
int i = int(random(QQ.length));
Q = QQ[i];
}
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=(500-y), d = sqrt(dx*dx+dy*dy)*3;
x += dx/d;
y += dy/d;
if(keyPressed){
stroke(255,0,0);
line(200,550,x,y);
}
}
void keyPressed(){
int i = A.length();
if(key==Q.charAt(i)){
A+=key;
}
}
11.可連續玩
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=(500-y), d = sqrt(dx*dx+dy*dy)*3;
x += dx/d;
y += dy/d;
if(keyPressed){
stroke(255,0,0);
line(200,550,x,y);
}
}
void keyPressed(){
int i = A.length();
if(key==Q.charAt(i)){
A+=key;
if( Q.equals(A)){
randomQ();
A = "";
}
}
}
主題:還未決定~










沒有留言:
張貼留言