這是我們的Demo影片
這是我們的程式碼:
import processing.serial.*;
Serial myPort;
int val;
import ddf.minim.*;
Minim minim;
AudioPlayer c4;
AudioPlayer d4;
AudioPlayer e4;
AudioPlayer f4;
AudioPlayer g4;
AudioPlayer a4;
AudioPlayer b4;
AudioPlayer c5;
AudioPlayer d5;
AudioPlayer e5;
AudioPlayer f5;
AudioPlayer g5;
AudioPlayer a5;
AudioPlayer b5;
PImage success;
int i=0;
Boolean first=true;
PFont f;
char []input ={'1', '2', '3', '4', '5', '6', '7', 'c', 'd', 'e', 'f', 'g', 'a', 'b'};
char []input1={'1', '2', '3', '4', '5', '6', '7', 'C', 'D', 'E', 'F', 'G', 'A', 'B'};
void setup() {
size(800, 600, P3D);
if (first==true) {
myPort = new Serial(this, "COM3", 9600);
first=false;
}
minim=new Minim(this);
c4=minim.loadFile("c4.mp3");
d4=minim.loadFile("d4.mp3");
e4=minim.loadFile("e4.mp3");
f4=minim.loadFile("f4.mp3");
g4=minim.loadFile("g4.mp3");
a4=minim.loadFile("a4.mp3");
b4=minim.loadFile("b4.mp3");
c5=minim.loadFile("c5.mp3");
d5=minim.loadFile("d5.mp3");
e5=minim.loadFile("e5.mp3");
f5=minim.loadFile("f5.mp3");
g5=minim.loadFile("g5.mp3");
a5=minim.loadFile("a5.mp3");
b5=minim.loadFile("b5.mp3");
success=loadImage("success.png");
f = createFont("Georgia", 36);
//ACaslonPro-Italic
//Georgia
textFont(f);
textAlign(CENTER, CENTER);
smooth();
background(50);
}
String num= "115566544332215544332554433211556654433221";
String []message={
"| 1 1 5 5 | 6 6 5 – | ",
"Twinkle, twinkle, little Star ",
"| 4 4 3 3 | 2 2 1 – | ",
"How I wonder what you are",
"| 5 5 4 4 | 3 3 2 – | ",
"Up above the world so high",
"| 5 5 4 4 | 3 3 2 – | ",
"Like a diamond in the sky",
"| 1 1 5 5 | 6 6 5 – | ",
"Twinkle, twinkle, little Star ",
"| 4 4 3 3 | 2 2 1 – || ",
"How I wonder what you are"
};
void sheet() {
color c = color(#FFF3CE);
noStroke();
fill(c);
rect(150, 70, 500, 285, 2);
fill(0);
if (count%2==0)
star();
else if (count%2==1)
demo();
}
void star() {
textSize(36);
text("little star", 400, 80);
if (x<21)
for (i=0; i<3; i++) {
textSize(32);
text(message[2*i], 400, 120+80*i);
textSize(22);
text(message[1+2*i], 400, 160+80*i);
} else if (x>=21)
for (i=3; i<6; i++) {
textSize(32);
text(message[2*i], 400, 120+80*(i-3));
textSize(22);
text(message[1+2*i], 400, 160+80*(i-3));
}
fill(10);
rect(100, 350, 600, 10);
}
void demo() {
textSize(36);
text("Free design", 400, 80);
}
int n=15;
void draw() {
while ( myPort.available() > 0) { // If data is available,
val = myPort.read(); // read it and store it in val
if (val==48) {
c4.rewind();
c4.play();
n=0;
}
if (val==49) {
d4.rewind();
d4.play();
n=1;
} else if (val==50) {
e4.rewind();
e4.play();
n=2;
} else if (val==51) {
f4.rewind();
f4.play();
n=3;
} else if (val==52) {
g4.rewind();
g4.play();
n=4;
} else if (val==53) {
a4.rewind();
a4.play();
n=5;
} else if (val==54) {
b4.rewind();
b4.play();
n=6;
} else if (val==55) {
c5.rewind();
c5.play();
n=7;
}
}
fill(255);
stroke(0);
for (i=0; i<14; i++) {
pushMatrix();
translate(70, 500, 0);
rotateX(PI/2.5);
translate(50*i, 0, 0);
if (i==n)
fill(#CDE4F2);
else
fill(255);
if (keyPressed) {
n=15;
if (key == input[i] || key==input1[i])
fill(#CDE4F2);
else
fill(255);
}
box(50, 170, 60);
popMatrix();
}
for (int i=0; i<10; i++) {
pushMatrix();
translate(70, 500, 0);
rotateX(PI/2.5);
if (i>=2 &&i<5)
translate(25+50*(i+1), -25, 10);
else if (i>=5 && i<7)
translate(25+50*(i+2), -25, 10);
else if (i>=7 && i<10)
translate(25+50*(i+3), -25, 10);
else
translate(25+50*i, -25, 10);
fill(0);
box(23, 120, 60);
popMatrix();
}
sheet();
if (count%2==0)
if (x==42) {
image(success, width/4-20, 0, 450, 450);
turnoff=false;
if (mousePressed) {
x=0;
turnoff=true;
setup();
redraw();
}
}
}
boolean turnoff=true;
char record;
int x=0, count=0, y=0;
void keyPressed() {
if (key=='1') {
c4.rewind();
c4.play();
}
if (key=='2') {
d4.rewind();
d4.play();
}
if (key=='3') {
e4.rewind();
e4.play();
}
if (key=='4') {
f4.rewind();
f4.play();
}
if (key=='5') {
g4.rewind();
g4.play();
}
if (key=='6') {
a4.rewind();
a4.play();
}
if (key=='7') {
b4.rewind();
b4.play();
}
if (key=='c' || key=='C') {
c5.rewind();
c5.play();
}
if (key=='d' || key=='D') {
d5.rewind();
d5.play();
}
if (key=='e' || key=='E') {
e5.rewind();
e5.play();
}
if (key=='f' || key=='F') {
f5.rewind();
f5.play();
}
if (key=='g' || key=='G') {
g5.rewind();
g5.play();
}
if (key=='a' || key=='A') {
a5.rewind();
a5.play();
}
if (key=='b' || key=='B') {
b5.rewind();
b5.play();
}
if (key==' ')
count++;
for (i=0; i<14; i++)
if (key== input[i] || key ==input1[i])
record=key;
i=x;
if (turnoff==true)
if (count%2==0)
if (num.charAt(i)==key ||val==48)
x++;
}
沒有留言:
張貼留言