size(500,500);
textSize(64);
text("Hello World",100,100);
fill(255,0,0);
text("Red",100,200);
void setup(){
size(500,500);
textSize(64);
}
String line = "Input: ";
void draw(){
text(line,100,100);
}
void keyPressed(){
line += key;
}
放入音樂
import processing.sound.*;
SoundFile file;
void setup(){
size(300,300);
file = new SoundFile(this,"a.mp3");
file.play();
}
void draw(){
}
放3個音樂
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();
}
字打對會變紅色
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);//Q白色
fill(#FF0000);text(A,x,y);//A紅色
ellipse(200,550,20,20);
float dx=(200-x) ,dy=(550-y), d = sqrt(dx*dx+dy*dy)*2;//d=距離//*3可以調速度,可以用來分關卡
x += dx/d;
y += dx/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;//打對了變成A紅色
}
}
void setup(){
size (400,600);
textSize(12);
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)*3;
x += dx / d;
y += dy / d;
if(keyPressed){
stroke(255,0,0);
line(200,550,x+textWidth(A),y);
}
}
void keyPressed(){
int i = A.length();
if( key == Q.charAt(i)){ //相同 非常好
A += key;
if(Q.equals(A)){
randomQ();
A = "";
}
}
}










沒有留言:
張貼留言