遊戲名稱:節奏音感
遊戲玩法:在放音樂的過程中,會有音階隨機掉下來,操作的方法就是將Processing與Arduino的程式碼互相連接,再利用Arduino硬體組成的5個按鍵來操作,當音階到達指定的位置時按下,程式碼就會依照所設定的預設值範圍來判斷有無按到,在按到的過程中會出現閃光的特效,每按成功一次就加分數100分,直到音樂放完為止,遊戲結束後,在最後的畫面會出現總分。
Processing程式碼:
PImage bg,blue,orange,green,blue1,orange1;
PImage imgPub;
PImage imgMusic;
PImage imgPop;
import processing.serial.*;
Serial myPort;
int N=6;
int count = 9700;
float []thingX=new float[6], thingY=new float[6],thingType = new float[6];
int grade=0;
int val;
import ddf.minim.*;
Minim m;
AudioPlayer player;
void setup(){
myPort = new Serial(this, "COM4", 9600);
imgPub=loadImage("Pub.jpg");
imgMusic=loadImage("Music.jpg");
imgPop=loadImage("Pop.jpg");
image(imgPop,400,600);
image(imgMusic,400,600);
image(imgPub,400,600);
bg = loadImage("background.jpg");
blue = loadImage("blue.jpg");
orange = loadImage("orange.gif");
green = loadImage("green.jpg");
blue1 = loadImage("blue1.gif");
orange1 = loadImage("orange1.jpg");
m = new Minim(this);
player = m.loadFile("DNA.mp3");
size(400,600);
for(int i=0;i<N;i++){
newThing(i);
}
}
int countDown=10*30;
void draw(){
player.play();
val = myPort.read();
image(imgPop,0,0,400,600);
if(keyPressed)
textSize(40);
text("Start!!", 250, 300);
if(key=='s')
image(imgMusic,0,0,400,600);
if(countDown>0){
//background(255,0,255);
countDown--;
text("Time: "+countDown/50,170,300);
return;
}
image(bg,0,0, 400,600);
image(blue,0,575,80,40);
image(orange,80,575,80,40);
image(green,160,575,80,40);
image(blue1,240,575,80,40);
image(orange1,320,575,80,40);
for(int i=0;i<N;i++){
if(thingType[i]==1)
{
drawblue(i);
//if (keyPressed)
//if(key=='d'|| key=='D')
println(val);
if(525<thingY[i] && thingY[i]<700 && val==50)
{
thingY[i] = 650; grade+=100; //println(grade);
fill(#0046FF,90);
rect(0,575,80,-600);
}
}
else if(thingType[i]==2)
{
draworange(i);
//if (keyPressed)
{
//if(key=='f'|| key=='F')
//println(val);
if(525<thingY[i] && thingY[i]<600 && val==51)
{
thingY[i] = 650; grade+=100; println(grade);
fill(#FF7D00,90);
rect(80,575,80,-600);
}
}
}
else if(thingType[i]==3)
{
drawgreen(i);
//if (keyPressed)
{
//if(key=='b'|| key=='B')
//println(val);
if(525<thingY[i] && thingY[i]<600 && val==52)
{
thingY[i] = 650; grade+=100; println(grade);
fill(#10FF00,90);
rect(160,575,80,-600);
}
}
}
else if(thingType[i]==4)
{
drawblue1(i);
//if (keyPressed)
{
//if(key=='k'|| key=='K')
//println(val);
if(525<thingY[i] && thingY[i]<600 && val==49)
{
thingY[i] = 650; grade+=100; println(grade);
fill(#0046FF,90);
rect(240,575,80,-600);
}
}
}
else if(thingType[i]==5)
{
draworange1(i);
//if (keyPressed)
{
//if(key=='j'|| key=='J')
println(val);
if (525<thingY[i] && thingY[i]<600 && val==53)
{
thingY[i] = 650; grade+=100; println(grade);
fill(#FF7D00,90);
rect(320,575,80,-600);
}
}
}
thingY[i]+=3;
if(thingY[i]>600) newThing(i);
}
if(count>0){
count--;
text("Time: "+count/50,170,300);
}
if(count==0){
//background(#FF0015);
//background(imgMusic,400,600);
image(imgMusic,0,0,400,600);
fill(255,0,0);
text("Score: "+grade,122,300);
}
}
void newThing(int i){
thingY[i] = -random(200);
thingX[i] = random(400);
thingType[i] = int(random(5))+1;
}
void drawblue(int i){
thingX[i]=int(random(0,0));
image(blue,thingX[i],thingY[i],80,22);
}
void draworange(int i){
thingX[i]=int(random(80,80));
image(orange,thingX[i],thingY[i],80,22);
}
void drawgreen(int i){
thingX[i]=int(random(160,160));
image(green,thingX[i],thingY[i],80,22);
}
void drawblue1(int i){
thingX[i]=int(random(240,240));
image(blue1,thingX[i],thingY[i],80,22);
}
void draworange1(int i){
thingX[i]=int(random(320,320));
image(orange1,thingX[i],thingY[i],80,22);
}
Arduino硬體程式碼:
int buttonPin5 = 5;
int buttonPin2 = 2;
int buttonPin3 = 3;
int buttonPin4 = 4;
int buttonPin6 = 6;
int buttonState5 = 0;
int buttonState2 = 0;
int buttonState3 = 0;
int buttonState4 = 0;
int buttonState6 = 0;
void setup() {
pinMode(buttonPin5, INPUT);
pinMode(buttonPin2, INPUT);
pinMode(buttonPin3, INPUT);
pinMode(buttonPin4, INPUT);
pinMode(buttonPin6, INPUT);
Serial.begin(9600);
}
void loop() {
buttonState5 = digitalRead(buttonPin5);
buttonState2 = digitalRead(buttonPin2);
buttonState3 = digitalRead(buttonPin3);
buttonState4 = digitalRead(buttonPin4);
buttonState6 = digitalRead(buttonPin6);
if (buttonState5 == HIGH) {
Serial.write('1');
}
if (buttonState2== HIGH) {
Serial.print('2');
}
if (buttonState3 == HIGH) {
Serial.print('3');
}
if (buttonState4 == HIGH) {
Serial.print('4');
}
if (buttonState6 == HIGH) {
Serial.print('5');
}
else if(buttonState2 == LOW&&buttonState3 == LOW&&buttonState4 == LOW&&buttonState5 == LOW&&buttonState6 == LOW){
Serial.write('0');
}
delay(100);
}
Arduino硬體電路連接:
圖片結果截圖:
影片DEMO:
遊戲執行結果:
電腦側錄結果:
2014年1月12日 星期日
99163116鄭祥斌期中作品進度(1)
Processing程式碼:
PImage bg,blue,orange,green,blue1,orange1;
PImage imgPub;
PImage imgMusic;
PImage imgPop;
import processing.serial.*;
Serial myPort;
int N=6;
int count = 9700;
float []thingX=new float[6], thingY=new float[6],thingType = new float[6];
int grade=0;
int val;
import ddf.minim.*;
Minim m;
AudioPlayer player;
void setup(){
myPort = new Serial(this, "COM4", 9600);
imgPub=loadImage("Pub.jpg");
imgMusic=loadImage("Music.jpg");
imgPop=loadImage("Pop.jpg");
image(imgPop,400,600);
image(imgMusic,400,600);
image(imgPub,400,600);
bg = loadImage("background.jpg");
blue = loadImage("blue.jpg");
orange = loadImage("orange.gif");
green = loadImage("green.jpg");
blue1 = loadImage("blue1.gif");
orange1 = loadImage("orange1.jpg");
m = new Minim(this);
player = m.loadFile("DNA.mp3");
size(400,600);
for(int i=0;i<N;i++){
newThing(i);
}
}
int countDown=10*30;
void draw(){
player.play();
val = myPort.read();
image(imgPop,0,0,400,600);
if(keyPressed)
textSize(40);
text("Start!!", 250, 300);
if(key=='s')
image(imgMusic,0,0,400,600);
if(countDown>0){
//background(255,0,255);
countDown--;
text("Time: "+countDown/50,170,300);
return;
}
image(bg,0,0, 400,600);
image(blue,0,575,80,40);
image(orange,80,575,80,40);
image(green,160,575,80,40);
image(blue1,240,575,80,40);
image(orange1,320,575,80,40);
for(int i=0;i<N;i++){
if(thingType[i]==1)
{
drawblue(i);
//if (keyPressed)
//if(key=='d'|| key=='D')
println(val);
if(525<thingY[i] && thingY[i]<700 && val==50)
{
thingY[i] = 650; grade+=100; //println(grade);
fill(#0046FF,90);
rect(0,575,80,-600);
}
}
else if(thingType[i]==2)
{
draworange(i);
//if (keyPressed)
{
//if(key=='f'|| key=='F')
//println(val);
if(525<thingY[i] && thingY[i]<600 && val==51)
{
thingY[i] = 650; grade+=100; println(grade);
fill(#FF7D00,90);
rect(80,575,80,-600);
}
}
}
else if(thingType[i]==3)
{
drawgreen(i);
//if (keyPressed)
{
//if(key=='b'|| key=='B')
//println(val);
if(525<thingY[i] && thingY[i]<600 && val==52)
{
thingY[i] = 650; grade+=100; println(grade);
fill(#10FF00,90);
rect(160,575,80,-600);
}
}
}
else if(thingType[i]==4)
{
drawblue1(i);
//if (keyPressed)
{
//if(key=='k'|| key=='K')
//println(val);
if(525<thingY[i] && thingY[i]<600 && val==49)
{
thingY[i] = 650; grade+=100; println(grade);
fill(#0046FF,90);
rect(240,575,80,-600);
}
}
}
else if(thingType[i]==5)
{
draworange1(i);
//if (keyPressed)
{
//if(key=='j'|| key=='J')
println(val);
if (525<thingY[i] && thingY[i]<600 && val==53)
{
thingY[i] = 650; grade+=100; println(grade);
fill(#FF7D00,90);
rect(320,575,80,-600);
}
}
}
thingY[i]+=3;
if(thingY[i]>600) newThing(i);
}
if(count>0){
count--;
text("Time: "+count/50,170,300);
}
if(count==0){
//background(#FF0015);
//background(imgMusic,400,600);
image(imgMusic,0,0,400,600);
fill(255,0,0);
text("Score: "+grade,122,300);
}
}
void newThing(int i){
thingY[i] = -random(200);
thingX[i] = random(400);
thingType[i] = int(random(5))+1;
}
void drawblue(int i){
thingX[i]=int(random(0,0));
image(blue,thingX[i],thingY[i],80,22);
}
void draworange(int i){
thingX[i]=int(random(80,80));
image(orange,thingX[i],thingY[i],80,22);
}
void drawgreen(int i){
thingX[i]=int(random(160,160));
image(green,thingX[i],thingY[i],80,22);
}
void drawblue1(int i){
thingX[i]=int(random(240,240));
image(blue1,thingX[i],thingY[i],80,22);
}
void draworange1(int i){
thingX[i]=int(random(320,320));
image(orange1,thingX[i],thingY[i],80,22);
}
PImage bg,blue,orange,green,blue1,orange1;
PImage imgPub;
PImage imgMusic;
PImage imgPop;
import processing.serial.*;
Serial myPort;
int N=6;
int count = 9700;
float []thingX=new float[6], thingY=new float[6],thingType = new float[6];
int grade=0;
int val;
import ddf.minim.*;
Minim m;
AudioPlayer player;
void setup(){
myPort = new Serial(this, "COM4", 9600);
imgPub=loadImage("Pub.jpg");
imgMusic=loadImage("Music.jpg");
imgPop=loadImage("Pop.jpg");
image(imgPop,400,600);
image(imgMusic,400,600);
image(imgPub,400,600);
bg = loadImage("background.jpg");
blue = loadImage("blue.jpg");
orange = loadImage("orange.gif");
green = loadImage("green.jpg");
blue1 = loadImage("blue1.gif");
orange1 = loadImage("orange1.jpg");
m = new Minim(this);
player = m.loadFile("DNA.mp3");
size(400,600);
for(int i=0;i<N;i++){
newThing(i);
}
}
int countDown=10*30;
void draw(){
player.play();
val = myPort.read();
image(imgPop,0,0,400,600);
if(keyPressed)
textSize(40);
text("Start!!", 250, 300);
if(key=='s')
image(imgMusic,0,0,400,600);
if(countDown>0){
//background(255,0,255);
countDown--;
text("Time: "+countDown/50,170,300);
return;
}
image(bg,0,0, 400,600);
image(blue,0,575,80,40);
image(orange,80,575,80,40);
image(green,160,575,80,40);
image(blue1,240,575,80,40);
image(orange1,320,575,80,40);
for(int i=0;i<N;i++){
if(thingType[i]==1)
{
drawblue(i);
//if (keyPressed)
//if(key=='d'|| key=='D')
println(val);
if(525<thingY[i] && thingY[i]<700 && val==50)
{
thingY[i] = 650; grade+=100; //println(grade);
fill(#0046FF,90);
rect(0,575,80,-600);
}
}
else if(thingType[i]==2)
{
draworange(i);
//if (keyPressed)
{
//if(key=='f'|| key=='F')
//println(val);
if(525<thingY[i] && thingY[i]<600 && val==51)
{
thingY[i] = 650; grade+=100; println(grade);
fill(#FF7D00,90);
rect(80,575,80,-600);
}
}
}
else if(thingType[i]==3)
{
drawgreen(i);
//if (keyPressed)
{
//if(key=='b'|| key=='B')
//println(val);
if(525<thingY[i] && thingY[i]<600 && val==52)
{
thingY[i] = 650; grade+=100; println(grade);
fill(#10FF00,90);
rect(160,575,80,-600);
}
}
}
else if(thingType[i]==4)
{
drawblue1(i);
//if (keyPressed)
{
//if(key=='k'|| key=='K')
//println(val);
if(525<thingY[i] && thingY[i]<600 && val==49)
{
thingY[i] = 650; grade+=100; println(grade);
fill(#0046FF,90);
rect(240,575,80,-600);
}
}
}
else if(thingType[i]==5)
{
draworange1(i);
//if (keyPressed)
{
//if(key=='j'|| key=='J')
println(val);
if (525<thingY[i] && thingY[i]<600 && val==53)
{
thingY[i] = 650; grade+=100; println(grade);
fill(#FF7D00,90);
rect(320,575,80,-600);
}
}
}
thingY[i]+=3;
if(thingY[i]>600) newThing(i);
}
if(count>0){
count--;
text("Time: "+count/50,170,300);
}
if(count==0){
//background(#FF0015);
//background(imgMusic,400,600);
image(imgMusic,0,0,400,600);
fill(255,0,0);
text("Score: "+grade,122,300);
}
}
void newThing(int i){
thingY[i] = -random(200);
thingX[i] = random(400);
thingType[i] = int(random(5))+1;
}
void drawblue(int i){
thingX[i]=int(random(0,0));
image(blue,thingX[i],thingY[i],80,22);
}
void draworange(int i){
thingX[i]=int(random(80,80));
image(orange,thingX[i],thingY[i],80,22);
}
void drawgreen(int i){
thingX[i]=int(random(160,160));
image(green,thingX[i],thingY[i],80,22);
}
void drawblue1(int i){
thingX[i]=int(random(240,240));
image(blue1,thingX[i],thingY[i],80,22);
}
void draworange1(int i){
thingX[i]=int(random(320,320));
image(orange1,thingX[i],thingY[i],80,22);
}
99163116鄭祥斌期中作品進度
Arduino硬體程式碼更新版:
int buttonPin5 = 5;
int buttonPin2 = 2;
int buttonPin3 = 3;
int buttonPin4 = 4;
int buttonPin6 = 6;
int buttonState5 = 0;
int buttonState2 = 0;
int buttonState3 = 0;
int buttonState4 = 0;
int buttonState6 = 0;
void setup() {
pinMode(buttonPin5, INPUT);
pinMode(buttonPin2, INPUT);
pinMode(buttonPin3, INPUT);
pinMode(buttonPin4, INPUT);
pinMode(buttonPin6, INPUT);
Serial.begin(9600);
}
void loop() {
buttonState5 = digitalRead(buttonPin5);
buttonState2 = digitalRead(buttonPin2);
buttonState3 = digitalRead(buttonPin3);
buttonState4 = digitalRead(buttonPin4);
buttonState6 = digitalRead(buttonPin6);
if (buttonState5 == HIGH) {
Serial.write('1');
}
if (buttonState2== HIGH) {
Serial.print('2');
}
if (buttonState3 == HIGH) {
Serial.print('3');
}
if (buttonState4 == HIGH) {
Serial.print('4');
}
if (buttonState6 == HIGH) {
Serial.print('5');
}
else if(buttonState2 == LOW&&buttonState3 == LOW&&buttonState4 == LOW&&buttonState5 == LOW&&buttonState6 == LOW){
Serial.write('0');
}
delay(100);
}
int buttonPin5 = 5;
int buttonPin2 = 2;
int buttonPin3 = 3;
int buttonPin4 = 4;
int buttonPin6 = 6;
int buttonState5 = 0;
int buttonState2 = 0;
int buttonState3 = 0;
int buttonState4 = 0;
int buttonState6 = 0;
void setup() {
pinMode(buttonPin5, INPUT);
pinMode(buttonPin2, INPUT);
pinMode(buttonPin3, INPUT);
pinMode(buttonPin4, INPUT);
pinMode(buttonPin6, INPUT);
Serial.begin(9600);
}
void loop() {
buttonState5 = digitalRead(buttonPin5);
buttonState2 = digitalRead(buttonPin2);
buttonState3 = digitalRead(buttonPin3);
buttonState4 = digitalRead(buttonPin4);
buttonState6 = digitalRead(buttonPin6);
if (buttonState5 == HIGH) {
Serial.write('1');
}
if (buttonState2== HIGH) {
Serial.print('2');
}
if (buttonState3 == HIGH) {
Serial.print('3');
}
if (buttonState4 == HIGH) {
Serial.print('4');
}
if (buttonState6 == HIGH) {
Serial.print('5');
}
else if(buttonState2 == LOW&&buttonState3 == LOW&&buttonState4 == LOW&&buttonState5 == LOW&&buttonState6 == LOW){
Serial.write('0');
}
delay(100);
}
2014年1月11日 星期六
99163116鄭祥斌硬體程式碼
期末作品硬體程式碼:
int switchPin1 = 2;
int switchPin2 = 3;
int switchPin3 = 4;
int switchPin4 = 5;
int switchPin5 = 6;
boolean oldStage1 = false;
boolean oldStage2 = false;
boolean oldStage3 = false;
boolean oldStage4 = false;
boolean oldStage5 = false;
void setup()
{
pinMode(switchPin1, INPUT);
pinMode(switchPin2, INPUT);
pinMode(switchPin3, INPUT);
pinMode(switchPin4, INPUT);
pinMode(switchPin5, INPUT);
Serial.begin(9600);
}
void loop()
{
if (digitalRead(switchPin1) == LOW)
{
if(oldStage1)
{
Serial.print(0,DEC);
}
oldStage1 = false;
}
else
{
if(!oldStage1)
{
Serial.print(1,DEC);
}
oldStage1 = true;
}
if (digitalRead(switchPin2) == LOW)
{
if(oldStage2)
{
Serial.print(2,DEC);
}
oldStage2 = false;
}
else
{
if(!oldStage2)
{
Serial.print(3,DEC);
}
oldStage2 = true;
}
if (digitalRead(switchPin3) == LOW)
{
if(oldStage3)
{
Serial.print(4,DEC);
}
oldStage3 = false;
}
else
{
if(!oldStage3)
{
Serial.print(5,DEC);
}
oldStage3 = true;
}
if (digitalRead(switchPin4) == LOW)
{
if(oldStage4)
{
Serial.print(6,DEC);
}
oldStage4 = false;
}
else
{
if(!oldStage4)
{
Serial.print(7,DEC);
}
oldStage4 = true;
}
if (digitalRead(switchPin5) == LOW)
{
if(oldStage5)
{
Serial.print(8,DEC);
}
oldStage5 = false;
}
else
{
if(!oldStage5)
{
Serial.print(9,DEC);
}
oldStage5 = true;
}
}
2013年12月8日 星期日
99163116鄭祥斌, HW14, HW14 期中作品企劃
有關於這次期末作品的計畫,我們想做有關Pop'n Music的作品,因為在逛街時常看到有關於Pop'n Music的音樂機台,想說以此為這次期末作品的目標,以下是我們參考的影片。
有關控制的部分,我們會裡用Arduino的控制電路版以及麵包版透過線路的連接分別連到5個不同的按鈕,以利我們控制。
有關控制的部分,我們會裡用Arduino的控制電路版以及麵包版透過線路的連接分別連到5個不同的按鈕,以利我們控制。
2013年12月1日 星期日
Week 13
Lesson 5 Mode Cue
利用手去轉馬達,使得風扇轉動
#include <servo .h="">
Servo myServo;
int const potPin =A0;
int potVal;
int angle;
void setup(){
myServo.attach(9);
Serial.begin(9600);
}
void loop(){
potVal = analogRead(potPin);
Serial.print("potVal: ");
Serial.print(potVal);
//這裡的 map function 可以把 0~1023 轉換到 0~179度
//很方便的函示
angle=map(potVal, 0, 1023, 0, 179);
Serial.print(", angle: ");
Serial.print(angle);
Serial.print("\r\n");
myServo.write(angle);
delay(15);
}
Lesson 6 Light Theremin
利用光線的強弱來發出聲音
int sensorValue;
int sensorLow = 1023;
int sensorHigh = 0;
const int ledPin = 13;
void setup() {
pinMode(ledPin, OUTPUT);
digitalWrite(ledPin, HIGH);
//遮住/打開光敏電阻,讓程式修正最大和最小值
while (millis() < 5000) {
sensorValue = analogRead(A0);
if (sensorValue > sensorHigh) {
sensorHigh = sensorValue;
}
if (sensorValue < sensorLow) {
sensorLow = sensorValue;
}
}
//開始進入
digitalWrite(ledPin, LOW);
}
void loop() {
sensorValue = analogRead(A0);
//對應最高和最低的數值,對應為 50~4000 hz
int pitch = map(sensorValue, sensorLow, sensorHigh, 50, 4000);
tone(8, pitch, 20);
delay(10);
}
Lesson 7 Keyboard Instrument
按鍵發出樂器的聲音
int notes[]={262,294,330,349}; void setup() { Serial.begin(9600); } void loop() { int keyVal=analogRead(A0); Serial.println(keyVal); if(keyVal==1023) { tone(8,notes[0]); } else if (keyVal>=900 && keyVal<=1010) { tone(8,notes[1]); } else if(keyVal>=505 && keyVal<=511) { tone(8,notes[2]); } else if (keyVal>=512 && keyVal<=512) { tone(8,notes[3]); } else { noTone(8); } }
利用手去轉馬達,使得風扇轉動
#include <servo .h="">
Servo myServo;
int const potPin =A0;
int potVal;
int angle;
void setup(){
myServo.attach(9);
Serial.begin(9600);
}
void loop(){
potVal = analogRead(potPin);
Serial.print("potVal: ");
Serial.print(potVal);
//這裡的 map function 可以把 0~1023 轉換到 0~179度
//很方便的函示
angle=map(potVal, 0, 1023, 0, 179);
Serial.print(", angle: ");
Serial.print(angle);
Serial.print("\r\n");
myServo.write(angle);
delay(15);
}
Lesson 6 Light Theremin
利用光線的強弱來發出聲音
int sensorValue;
int sensorLow = 1023;
int sensorHigh = 0;
const int ledPin = 13;
void setup() {
pinMode(ledPin, OUTPUT);
digitalWrite(ledPin, HIGH);
//遮住/打開光敏電阻,讓程式修正最大和最小值
while (millis() < 5000) {
sensorValue = analogRead(A0);
if (sensorValue > sensorHigh) {
sensorHigh = sensorValue;
}
if (sensorValue < sensorLow) {
sensorLow = sensorValue;
}
}
//開始進入
digitalWrite(ledPin, LOW);
}
void loop() {
sensorValue = analogRead(A0);
//對應最高和最低的數值,對應為 50~4000 hz
int pitch = map(sensorValue, sensorLow, sensorHigh, 50, 4000);
tone(8, pitch, 20);
delay(10);
}
Lesson 7 Keyboard Instrument
按鍵發出樂器的聲音
int notes[]={262,294,330,349}; void setup() { Serial.begin(9600); } void loop() { int keyVal=analogRead(A0); Serial.println(keyVal); if(keyVal==1023) { tone(8,notes[0]); } else if (keyVal>=900 && keyVal<=1010) { tone(8,notes[1]); } else if(keyVal>=505 && keyVal<=511) { tone(8,notes[2]); } else if (keyVal>=512 && keyVal<=512) { tone(8,notes[3]); } else { noTone(8); } }
2013年11月24日 星期日
Week12
Part1 Love O Meter
利用TMP電阻感應去增加亮燈數目
利用TMP電阻感應去增加亮燈數目
const int sensorPin = A0;
const float baselineTemp = 26.0; //起始溫度
void setup()
{
Serial.begin(9600);
for (int pinNumber = 2; pinNumber < 5; pinNumber++)
{
pinMode(pinNumber, OUTPUT);
digitalWrite(pinNumber, LOW);
}
}
void loop()
{
int sensorVal = analogRead(sensorPin);
Serial.print("Sensor Value: ");
Serial.print(sensorVal);
float voltage = (sensorVal/1024.0) * 5.0;
Serial.print(", Volts:");
Serial.print(voltage);
Serial.print(", degrees C: ");
float temperature = (voltage - .5) * 100;
Serial.println(temperature);
if (temperature < baselineTemp)
{
digitalWrite(2, LOW);
digitalWrite(3, LOW);
digitalWrite(4, LOW);
}
else if (temperature >= baselineTemp + 2 && temperature < baselineTemp + 4) //增加四度亮第一顆
{
digitalWrite(2, HIGH);
digitalWrite(3, LOW);
digitalWrite(4, LOW);
}
else if (temperature >= baselineTemp + 4 && temperature < baselineTemp + 6) //增加六度亮第二顆
{
digitalWrite(2, HIGH);
digitalWrite(3, HIGH);
digitalWrite(4, LOW);
}
else if (temperature > baselineTemp + 6) //增加六度亮第三顆
{
digitalWrite(2, HIGH);
digitalWrite(3, HIGH);
digitalWrite(4, HIGH);
}
delay(1);
}
Part 2 Color Mixing LAMP
利用光敏電阻感應去改變顏色的亮度和變化
利用光敏電阻感應去改變顏色的亮度和變化
const int Brightness = 20; // set overall brightness, use lower value in darkroom to protect your eyes (0-255)
const int greenLEDPin = 9; // LED connected to digital pin 9
const int redLEDPin = 10; // LED connected to digital pin 10
const int blueLEDPin = 11; // LED connected to digital pin 11
const int redSensorPin = A0; // pin with the photoresistor with the red gel
const int greenSensorPin = A1; // pin with the photoresistor with the green gel
const int blueSensorPin = A2; // pin with the photoresistor with the blue gel
int redSensorValue = 0; // variable to hold the value from the red sensor
int greenSensorValue = 0; // variable to hold the value from the green sensor
int blueSensorValue = 0; // variable to hold the value from the blue sensor
int redSensorHigh = 0; //High and low value for mapping. Notice that 'High' value were set low at 0, so that during calibration, its value would be be pushed up. See project 6.
int greenSensorHigh = 0;
int blueSensorHigh = 0;
int redSensorLow = 1023; // the opposite is true for 'Low' value
int greenSensorLow = 1023;
int blueSensorLow = 1023;
void setup() {
// initialize serial communications at 9600 bps:
Serial.begin(9600);
// set the digital pins as outputs
pinMode(greenLEDPin,OUTPUT);
pinMode(redLEDPin,OUTPUT);
pinMode(blueLEDPin,OUTPUT);
//switching on your lamp before calibration, as it would affect calibration too, especially in dark environment
analogWrite(redLEDPin, Brightness);
analogWrite(greenLEDPin, Brightness);
analogWrite(blueLEDPin, Brightness);
//actual calibration which takes 10 seconds. During calibration, LED would shine at constant brightness. After that, it'll start to respond.
while (millis() < 10000) {
redSensorValue = analogRead(redSensorPin); //read pin
if (redSensorValue > redSensorHigh) { //push 'High' value up based on sensor value. At the end of calibration, 'High' value would take the highest 'SensorValue' during the 10 seconds.
redSensorHigh = redSensorValue;
}
if (redSensorValue < redSensorLow) { //opposite is true for 'Low' value
redSensorLow = redSensorValue;
}
delay(5);
greenSensorValue = analogRead(greenSensorPin);
if (greenSensorValue > greenSensorHigh) {
greenSensorHigh = greenSensorValue;
}
if (greenSensorValue < greenSensorLow) {
greenSensorLow = greenSensorValue;
}
delay(5);
blueSensorValue = analogRead(blueSensorPin);
if (blueSensorValue > blueSensorHigh) {
blueSensorHigh = blueSensorValue;
}
if (blueSensorValue < blueSensorLow) {
blueSensorLow = blueSensorValue;
}
delay(5);
}
}
void loop() {
// Read the sensors first:
// read the value from the red-filtered photoresistor:
redSensorValue = analogRead(redSensorPin);
// give the ADC a moment to settle
delay(5);
// read the value from the green-filtered photoresistor:
greenSensorValue = analogRead(greenSensorPin);
// give the ADC a moment to settle
delay(5);
// read the value from the blue-filtered photoresistor:
blueSensorValue = analogRead(blueSensorPin);
// print out the values to the serial monitor
Serial.print("raw sensor Values \t red: ");
Serial.print(redSensorValue);
Serial.print("\t green: ");
Serial.print(greenSensorValue);
Serial.print("\t Blue: ");
Serial.println(blueSensorValue);
/*
In order to use the values from the sensor for the LED,
you need to do some math. The ADC provides a 10-bit number,
but analogWrite() uses 8 bits. You'll want to divide your
sensor readings by 4 to keep them in range of the output.
*/
/*
Changed from a mere division by 4 in the original code to mapping.
Lowest value recorded at calibration would be mapped to 0, and highest value would be mapped to brightness set earlier.
The constraint function is set to prevent flickering, when value are negative or exceeds 255.
*/
int redValue = map(redSensorValue,redSensorLow,redSensorHigh,0,Brightness);
redValue = constrain(redValue,0,255); //紅色最大值255
int greenValue = map(greenSensorValue,greenSensorLow,greenSensorHigh,0,Brightness);
greenValue = constrain(greenValue,0,255); //綠色最大值255
int blueValue = map(blueSensorValue,blueSensorLow,blueSensorHigh,0,Brightness);
blueValue = constrain(blueValue,0,255); //藍色最大值255
// print out the mapped values
Serial.print("Mapped sensor Values \t red: ");
Serial.print(redValue);
Serial.print("\t green: ");
Serial.print(greenValue);
Serial.print("\t Blue: ");
Serial.println(blueValue);
/*
Now that you have a usable value, it's time to PWM the LED.
*/
analogWrite(redLEDPin, redValue);
analogWrite(greenLEDPin, greenValue);
analogWrite(blueLEDPin, blueValue);
}
2013年11月17日 星期日
99163116鄭祥斌, Week11, HW11
1.插入Arduino(硬體),看COMPort
2.跑Arduino軟體(啟動-Arduino)
FILE-Example-Basic-Blink
3.範例Blink
改 delay(1000) 慢閃
delay(200) 快閃
4.上傳前,Tool-Port要改一下
程式碼:
void setup(){
pinMode(13,OUTPUT);
}
void loop(){
digitalWrite(13,HIGH);
delay(1000);
digitalWrite(13,LOW);
delay(200);
digitalWrite(13,HIGH);
delay(100);
digitalWrite(13,LOW);
delay(800);
digitalWrite(13,HIGH);
delay(1000);
digitalWrite(13,LOW);
delay(200);
digitalWrite(13,HIGH);
delay(100);
digitalWrite(13,LOW);
delay(100);
digitalWrite(13,HIGH);
delay(100);
digitalWrite(13,LOW);
delay(500);
digitalWrite(13,HIGH);
delay(1000);
digitalWrite(13,LOW);
delay(200);
}
LED接法:長(正極)接13,短(負極)接GND
void setup(){
pinMode(13,OUTPUT);
pinMode(12,OUTPUT);
pinMode(11,OUTPUT);
pinMode(8,OUTPUT);
}
void loop(){
digitalWrite(13,HIGH);
delay(200);
digitalWrite(12,HIGH);
delay(200);
digitalWrite(11,HIGH);
delay(1000);
digitalWrite(13,LOW);
delay(200);
digitalWrite(12,LOW);
delay(200);
digitalWrite(11,LOW);
delay(1000);
digitalWrite(13,HIGH);
delay(1000);
digitalWrite(12,HIGH);
delay(600);
digitalWrite(11,HIGH);
delay(200);
digitalWrite(13,LOW);
delay(1000);
digitalWrite(12,LOW);
delay(600);
digitalWrite(11,LOW);
delay(200);
digitalWrite(13,HIGH);
delay(1000);
digitalWrite(12,HIGH);
delay(100);
digitalWrite(11,HIGH);
delay(500);
digitalWrite(13,LOW);
delay(500);
digitalWrite(12,LOW);
delay(100);
digitalWrite(11,LOW);
delay(1000);
digitalWrite(8,HIGH);
delay(100);
digitalWrite(8,LOW);
delay(200);
digitalWrite(8,HIGH);
delay(100);
digitalWrite(8,LOW);
delay(200);
}
void setup(){
pinMode(13,OUTPUT);
pinMode(12,OUTPUT);
pinMode(11,OUTPUT);
pinMode(8,OUTPUT);
}
void loop(){
digitalWrite(13,HIGH);
delay(200);
digitalWrite(13,LOW);
delay(200);
digitalWrite(12,HIGH);
delay(200);
digitalWrite(12,LOW);
delay(200);
digitalWrite(11,HIGH);
delay(200);
digitalWrite(11,LOW);
delay(200);
digitalWrite(8,HIGH);
delay(200);
digitalWrite(8,LOW);
delay(200);
digitalWrite(11,HIGH);
delay(200);
digitalWrite(11,LOW);
delay(200);
digitalWrite(12,HIGH);
delay(200);
digitalWrite(12,LOW);
delay(200);
digitalWrite(13,HIGH);
delay(200);
digitalWrite(13,LOW);
delay(200);
digitalWrite(13,HIGH);
delay(1000);
digitalWrite(12,HIGH);
delay(1000);
digitalWrite(11,HIGH);
delay(1000);
digitalWrite(8,HIGH);
delay(1000);
digitalWrite(13,LOW);
delay(200);
digitalWrite(12,LOW);
delay(200);
digitalWrite(11,LOW);
delay(200);
digitalWrite(8,LOW);
delay(200);
}
2.跑Arduino軟體(啟動-Arduino)
FILE-Example-Basic-Blink
3.範例Blink
改 delay(1000) 慢閃
delay(200) 快閃
4.上傳前,Tool-Port要改一下
程式碼:
void setup(){
pinMode(13,OUTPUT);
}
void loop(){
digitalWrite(13,HIGH);
delay(1000);
digitalWrite(13,LOW);
delay(200);
digitalWrite(13,HIGH);
delay(100);
digitalWrite(13,LOW);
delay(800);
digitalWrite(13,HIGH);
delay(1000);
digitalWrite(13,LOW);
delay(200);
digitalWrite(13,HIGH);
delay(100);
digitalWrite(13,LOW);
delay(100);
digitalWrite(13,HIGH);
delay(100);
digitalWrite(13,LOW);
delay(500);
digitalWrite(13,HIGH);
delay(1000);
digitalWrite(13,LOW);
delay(200);
}
LED接法:長(正極)接13,短(負極)接GND
void setup(){
pinMode(13,OUTPUT);
pinMode(12,OUTPUT);
pinMode(11,OUTPUT);
pinMode(8,OUTPUT);
}
void loop(){
digitalWrite(13,HIGH);
delay(200);
digitalWrite(12,HIGH);
delay(200);
digitalWrite(11,HIGH);
delay(1000);
digitalWrite(13,LOW);
delay(200);
digitalWrite(12,LOW);
delay(200);
digitalWrite(11,LOW);
delay(1000);
digitalWrite(13,HIGH);
delay(1000);
digitalWrite(12,HIGH);
delay(600);
digitalWrite(11,HIGH);
delay(200);
digitalWrite(13,LOW);
delay(1000);
digitalWrite(12,LOW);
delay(600);
digitalWrite(11,LOW);
delay(200);
digitalWrite(13,HIGH);
delay(1000);
digitalWrite(12,HIGH);
delay(100);
digitalWrite(11,HIGH);
delay(500);
digitalWrite(13,LOW);
delay(500);
digitalWrite(12,LOW);
delay(100);
digitalWrite(11,LOW);
delay(1000);
digitalWrite(8,HIGH);
delay(100);
digitalWrite(8,LOW);
delay(200);
digitalWrite(8,HIGH);
delay(100);
digitalWrite(8,LOW);
delay(200);
}
void setup(){
pinMode(13,OUTPUT);
pinMode(12,OUTPUT);
pinMode(11,OUTPUT);
pinMode(8,OUTPUT);
}
void loop(){
digitalWrite(13,HIGH);
delay(200);
digitalWrite(13,LOW);
delay(200);
digitalWrite(12,HIGH);
delay(200);
digitalWrite(12,LOW);
delay(200);
digitalWrite(11,HIGH);
delay(200);
digitalWrite(11,LOW);
delay(200);
digitalWrite(8,HIGH);
delay(200);
digitalWrite(8,LOW);
delay(200);
digitalWrite(11,HIGH);
delay(200);
digitalWrite(11,LOW);
delay(200);
digitalWrite(12,HIGH);
delay(200);
digitalWrite(12,LOW);
delay(200);
digitalWrite(13,HIGH);
delay(200);
digitalWrite(13,LOW);
delay(200);
digitalWrite(13,HIGH);
delay(1000);
digitalWrite(12,HIGH);
delay(1000);
digitalWrite(11,HIGH);
delay(1000);
digitalWrite(8,HIGH);
delay(1000);
digitalWrite(13,LOW);
delay(200);
digitalWrite(12,LOW);
delay(200);
digitalWrite(11,LOW);
delay(200);
digitalWrite(8,LOW);
delay(200);
}
2013年11月11日 星期一
Week 10 期中作品展示
組員:鄭祥斌 99163116
期中作品展示
程式碼
int N=4;
int score=0;
int []sequence=new int[1000];
int bloodA=125;
int bloodB=125;
float CarX=150;
float CarY=500;
float []thingX= new float[4], thingY= new float[4], thingType= new float[4];
PImage imgZombie;
PImage imgCar;
PImage imgStop;
PImage imgWork;
PImage imgRoad;
PImage imgPolice;
int stage=0;
void setup() {
size(500, 600);
imgZombie=loadImage("zombie.png");
imgCar=loadImage("car.gif");
imgWork=loadImage("work.gif");
imgStop=loadImage("http://www.jiaotongbiaopai.com/upfile/article/201362622221081709468.gif");
imgRoad=loadImage("http://image.cn.made-in-china.com/2f0j01hBuQCfSPJlrW/%E9%A9%AC%E8%B7%AF%E5%88%92%E7%BA%BF%E6%BC%86.jpg");
imgPolice=loadImage("http://pic3.nipic.com/20090602/2801713_220519017_2.jpg");
image(imgPolice, 500, 600);
image(imgRoad, 500, 600);
for (int i=0;i<N;i++) {
//sequence[i]=int (random(3)) ;
newThing(i);
}
}
//int now=0;
int countDown=5*30;
void keyPressed() {
if (keyCode==RIGHT) CarX+=40;
if (keyCode==LEFT) CarX-=40;
}
void newThing(int i) {
thingY[i]=-random(200);
thingX[i]=random(400);
thingType[i]=int(random(3))+1;
}
void drawZombie(int i ) {
fill(255, 0, 0);
image (imgZombie, thingX[i], thingY[i], 40, 60);
}
void drawStop (int i) {
fill (0);
image (imgStop, thingX[i], thingY[i], 40, 60);
}
void drawWork(int i) {
fill(#FF6803);
image (imgWork, thingX[i], thingY[i], 60, 60);
}
void draw() {
background(255);
switch(stage) {
case 0:
if (countDown>0) {
image(imgPolice, 0, 0, 500, 600) ;
countDown--;
textSize(30);
text("Are you ready?", 150, 250);
text("Start: "+countDown/30, 180, 300);
return ;
}
image(imgRoad, 0, 0, 500, 600);
// for(int i=0;i<N;i++){
// //image(imgZombie, sequence[i]*100, 400-(i-now)*100);
// }
for (int i=0;i<N;i++) {
if (thingType[i]==1)drawZombie(i);
else if (thingType[i]==2)drawStop(i);
else if (thingType[i]==3)drawWork(i);
thingY[i]+=4;
if (thingY[i]>500) newThing(i);
}
image(imgCar, CarX, CarY, 100, 100);
//for(int i=0;i<4;i++){
//score(i);
//}
fill(0,220,0);
rect(0,0,bloodA*2,50);
fill(255,220,0);
rect(250,0,bloodB*2,50);
}
}
遊戲介紹
透過接收各種的標誌來了解交通標誌,因此有一台小汽車可利用鍵盤移動,接從上方掉下的交通號誌,左上的方條為汽車的生命值,右上方的為所剩時間,假如碰撞到的障礙物越多,他的生命質就越低,本遊戲的方數計算為100-綠色長方條後的分數,所以生命值越低分數就越高。
心得
特過這次製作的小遊戲,讓我們能夠了解processing的語法和運作,同時兼具教育和娛樂的實用性,在製作過程中有很多bug出現,為了能製作出好玩遊戲努力的克服了,雖然最後程式仍然有些許的bug但不影響遊戲運作,在寫作業中找到了很大的成就感,老師透過評分的方式,讓大家看到不同創意展現,因此在日後結合硬體操作的遊戲上,更令人期待能設計出什麼更棒的遊戲內容。
期中作品展示
程式碼
int N=4;
int score=0;
int []sequence=new int[1000];
int bloodA=125;
int bloodB=125;
float CarX=150;
float CarY=500;
float []thingX= new float[4], thingY= new float[4], thingType= new float[4];
PImage imgZombie;
PImage imgCar;
PImage imgStop;
PImage imgWork;
PImage imgRoad;
PImage imgPolice;
int stage=0;
void setup() {
size(500, 600);
imgZombie=loadImage("zombie.png");
imgCar=loadImage("car.gif");
imgWork=loadImage("work.gif");
imgStop=loadImage("http://www.jiaotongbiaopai.com/upfile/article/201362622221081709468.gif");
imgRoad=loadImage("http://image.cn.made-in-china.com/2f0j01hBuQCfSPJlrW/%E9%A9%AC%E8%B7%AF%E5%88%92%E7%BA%BF%E6%BC%86.jpg");
imgPolice=loadImage("http://pic3.nipic.com/20090602/2801713_220519017_2.jpg");
image(imgPolice, 500, 600);
image(imgRoad, 500, 600);
for (int i=0;i<N;i++) {
//sequence[i]=int (random(3)) ;
newThing(i);
}
}
//int now=0;
int countDown=5*30;
void keyPressed() {
if (keyCode==RIGHT) CarX+=40;
if (keyCode==LEFT) CarX-=40;
}
void newThing(int i) {
thingY[i]=-random(200);
thingX[i]=random(400);
thingType[i]=int(random(3))+1;
}
void drawZombie(int i ) {
fill(255, 0, 0);
image (imgZombie, thingX[i], thingY[i], 40, 60);
}
void drawStop (int i) {
fill (0);
image (imgStop, thingX[i], thingY[i], 40, 60);
}
void drawWork(int i) {
fill(#FF6803);
image (imgWork, thingX[i], thingY[i], 60, 60);
}
void draw() {
background(255);
switch(stage) {
case 0:
if (countDown>0) {
image(imgPolice, 0, 0, 500, 600) ;
countDown--;
textSize(30);
text("Are you ready?", 150, 250);
text("Start: "+countDown/30, 180, 300);
return ;
}
image(imgRoad, 0, 0, 500, 600);
// for(int i=0;i<N;i++){
// //image(imgZombie, sequence[i]*100, 400-(i-now)*100);
// }
for (int i=0;i<N;i++) {
if (thingType[i]==1)drawZombie(i);
else if (thingType[i]==2)drawStop(i);
else if (thingType[i]==3)drawWork(i);
thingY[i]+=4;
if (thingY[i]>500) newThing(i);
}
image(imgCar, CarX, CarY, 100, 100);
//for(int i=0;i<4;i++){
//score(i);
//}
fill(0,220,0);
rect(0,0,bloodA*2,50);
fill(255,220,0);
rect(250,0,bloodB*2,50);
}
}
遊戲介紹
透過接收各種的標誌來了解交通標誌,因此有一台小汽車可利用鍵盤移動,接從上方掉下的交通號誌,左上的方條為汽車的生命值,右上方的為所剩時間,假如碰撞到的障礙物越多,他的生命質就越低,本遊戲的方數計算為100-綠色長方條後的分數,所以生命值越低分數就越高。
心得
特過這次製作的小遊戲,讓我們能夠了解processing的語法和運作,同時兼具教育和娛樂的實用性,在製作過程中有很多bug出現,為了能製作出好玩遊戲努力的克服了,雖然最後程式仍然有些許的bug但不影響遊戲運作,在寫作業中找到了很大的成就感,老師透過評分的方式,讓大家看到不同創意展現,因此在日後結合硬體操作的遊戲上,更令人期待能設計出什麼更棒的遊戲內容。
2013年11月10日 星期日
99163116鄭祥斌
int N=4;
int score=0;
int []sequence=new int[1000];
int bloodA=125;
int bloodB=125;
float CarX=150;
float CarY=500;
float []thingX= new float[4], thingY= new float[4], thingType= new float[4];
PImage imgZombie;
PImage imgCar;
PImage imgStop;
PImage imgWork;
PImage imgRoad;
PImage imgPolice;
int stage=0;
void setup() {
size(500, 600);
imgZombie=loadImage("zombie.png");
imgCar=loadImage("car.gif");
imgWork=loadImage("work.gif");
imgStop=loadImage("http://www.jiaotongbiaopai.com/upfile/article/201362622221081709468.gif");
imgRoad=loadImage("http://image.cn.made-in-china.com/2f0j01hBuQCfSPJlrW/%E9%A9%AC%E8%B7%AF%E5%88%92%E7%BA%BF%E6%BC%86.jpg");
imgPolice=loadImage("http://pic3.nipic.com/20090602/2801713_220519017_2.jpg");
image(imgPolice, 500, 600);
image(imgRoad, 500, 600);
for (int i=0;i<N;i++) {
//sequence[i]=int (random(3)) ;
newThing(i);
}
}
//int now=0;
int countDown=5*30;
void keyPressed() {
if (keyCode==RIGHT) CarX+=40;
if (keyCode==LEFT) CarX-=40;
}
void newThing(int i) {
thingY[i]=-random(200);
thingX[i]=random(400);
thingType[i]=int(random(3))+1;
}
void drawZombie(int i ) {
fill(255, 0, 0);
image (imgZombie, thingX[i], thingY[i], 40, 60);
}
void drawStop (int i) {
fill (0);
image (imgStop, thingX[i], thingY[i], 40, 60);
}
void drawWork(int i) {
fill(#FF6803);
image (imgWork, thingX[i], thingY[i], 60, 60);
}
void draw() {
background(255);
switch(stage) {
case 0:
if (countDown>0) {
image(imgPolice, 0, 0, 500, 600) ;
countDown--;
textSize(30);
text("Are you ready?", 150, 250);
text("Start: "+countDown/30, 180, 300);
return ;
}
image(imgRoad, 0, 0, 500, 600);
// for(int i=0;i<N;i++){
// //image(imgZombie, sequence[i]*100, 400-(i-now)*100);
// }
for (int i=0;i<N;i++) {
if (thingType[i]==1)drawZombie(i);
else if (thingType[i]==2)drawStop(i);
else if (thingType[i]==3)drawWork(i);
thingY[i]+=4;
if (thingY[i]>500) newThing(i);
}
image(imgCar, CarX, CarY, 100, 100);
//for(int i=0;i<4;i++){
//score(i);
//}
fill(255,0,0);
rect(0,0,bloodA*2,50);
rect(250,0,bloodB*2,50);
}
}
int score=0;
int []sequence=new int[1000];
int bloodA=125;
int bloodB=125;
float CarX=150;
float CarY=500;
float []thingX= new float[4], thingY= new float[4], thingType= new float[4];
PImage imgZombie;
PImage imgCar;
PImage imgStop;
PImage imgWork;
PImage imgRoad;
PImage imgPolice;
int stage=0;
void setup() {
size(500, 600);
imgZombie=loadImage("zombie.png");
imgCar=loadImage("car.gif");
imgWork=loadImage("work.gif");
imgStop=loadImage("http://www.jiaotongbiaopai.com/upfile/article/201362622221081709468.gif");
imgRoad=loadImage("http://image.cn.made-in-china.com/2f0j01hBuQCfSPJlrW/%E9%A9%AC%E8%B7%AF%E5%88%92%E7%BA%BF%E6%BC%86.jpg");
imgPolice=loadImage("http://pic3.nipic.com/20090602/2801713_220519017_2.jpg");
image(imgPolice, 500, 600);
image(imgRoad, 500, 600);
for (int i=0;i<N;i++) {
//sequence[i]=int (random(3)) ;
newThing(i);
}
}
//int now=0;
int countDown=5*30;
void keyPressed() {
if (keyCode==RIGHT) CarX+=40;
if (keyCode==LEFT) CarX-=40;
}
void newThing(int i) {
thingY[i]=-random(200);
thingX[i]=random(400);
thingType[i]=int(random(3))+1;
}
void drawZombie(int i ) {
fill(255, 0, 0);
image (imgZombie, thingX[i], thingY[i], 40, 60);
}
void drawStop (int i) {
fill (0);
image (imgStop, thingX[i], thingY[i], 40, 60);
}
void drawWork(int i) {
fill(#FF6803);
image (imgWork, thingX[i], thingY[i], 60, 60);
}
void draw() {
background(255);
switch(stage) {
case 0:
if (countDown>0) {
image(imgPolice, 0, 0, 500, 600) ;
countDown--;
textSize(30);
text("Are you ready?", 150, 250);
text("Start: "+countDown/30, 180, 300);
return ;
}
image(imgRoad, 0, 0, 500, 600);
// for(int i=0;i<N;i++){
// //image(imgZombie, sequence[i]*100, 400-(i-now)*100);
// }
for (int i=0;i<N;i++) {
if (thingType[i]==1)drawZombie(i);
else if (thingType[i]==2)drawStop(i);
else if (thingType[i]==3)drawWork(i);
thingY[i]+=4;
if (thingY[i]>500) newThing(i);
}
image(imgCar, CarX, CarY, 100, 100);
//for(int i=0;i<4;i++){
//score(i);
//}
fill(255,0,0);
rect(0,0,bloodA*2,50);
rect(250,0,bloodB*2,50);
}
}
2013年10月21日 星期一
2013年10月13日 星期日
99163116鄭祥斌
float [] ballX=new float [50], ballY= new float[50];
float [] ballVX=new float [50], ballVY= new float[50];
int top=0;
PImage imgBall;
void setup() {
size(600, 600);
imgBall = loadImage("http://cdn2-b.examiner.com/sites/default/files/styles/image_content_width/hash/45/19/greenfireball-350_0.jpg?itok=D_0Cf2Jw");
for (int i=0;i<50;i++) {
newBall(i);
}
}
void draw() {
background(0);
for (int i=0;i<50;i++) {
image(imgBall, ballX[i],ballY[i], 20, 20);
ballX[i] += ballVX[i];
ballY[i] += ballVY[i];
}
}
void newBall(int i) {
float angle=random(2*PI);
ballVX[i]=cos(angle);
ballVY[i]=sin(angle);
ballX[i]=300;
ballY[i]=300;
}
float [] ballX=new float [50], ballY= new float[50];
float [] ballVX=new float [50], ballVY= new float[50];
int top=0;
PImage imgBall;
void setup() {
size(600, 600);
imgBall = loadImage("http://cdn2-b.examiner.com/sites/default/files/styles/image_content_width/hash/45/19/greenfireball-350_0.jpg?itok=D_0Cf2Jw");
for (int i=0;i<50;i++) {
newBall(i);
}
}
void draw() {
background(0);
for (int i=0;i<50;i++) {
image(imgBall, ballX[i],ballY[i], 20, 20);
ballX[i] += ballVX[i];
ballY[i] += ballVY[i];
if(ballX[i]<0 || ballX[i]>600 || ballY[i]<0 || ballY[i]>600) newBall(i);
}
}
void newBall(int i) {
float angle=random(2*PI);
ballVX[i]=cos(angle);
ballVY[i]=sin(angle);
int dir= int(random(4));
if(dir==0) {ballX[i]=random(600); ballY[i]=0;}
else if(dir==1){ ballX[i]=random(600); ballY[i]=600;}
else if(dir==2){ ballX[i]=0; ballY[i]=random(600);}
else if(dir==3){ ballX[i]=600; ballY[i]=random(600);}
}
float [] ballVX=new float [50], ballVY= new float[50];
int top=0;
PImage imgBall;
void setup() {
size(600, 600);
imgBall = loadImage("http://cdn2-b.examiner.com/sites/default/files/styles/image_content_width/hash/45/19/greenfireball-350_0.jpg?itok=D_0Cf2Jw");
for (int i=0;i<50;i++) {
newBall(i);
}
}
void draw() {
background(0);
for (int i=0;i<50;i++) {
image(imgBall, ballX[i],ballY[i], 20, 20);
ballX[i] += ballVX[i];
ballY[i] += ballVY[i];
}
}
void newBall(int i) {
float angle=random(2*PI);
ballVX[i]=cos(angle);
ballVY[i]=sin(angle);
ballX[i]=300;
ballY[i]=300;
}
float [] ballX=new float [50], ballY= new float[50];
float [] ballVX=new float [50], ballVY= new float[50];
int top=0;
PImage imgBall;
void setup() {
size(600, 600);
imgBall = loadImage("http://cdn2-b.examiner.com/sites/default/files/styles/image_content_width/hash/45/19/greenfireball-350_0.jpg?itok=D_0Cf2Jw");
for (int i=0;i<50;i++) {
newBall(i);
}
}
void draw() {
background(0);
for (int i=0;i<50;i++) {
image(imgBall, ballX[i],ballY[i], 20, 20);
ballX[i] += ballVX[i];
ballY[i] += ballVY[i];
if(ballX[i]<0 || ballX[i]>600 || ballY[i]<0 || ballY[i]>600) newBall(i);
}
}
void newBall(int i) {
float angle=random(2*PI);
ballVX[i]=cos(angle);
ballVY[i]=sin(angle);
int dir= int(random(4));
if(dir==0) {ballX[i]=random(600); ballY[i]=0;}
else if(dir==1){ ballX[i]=random(600); ballY[i]=600;}
else if(dir==2){ ballX[i]=0; ballY[i]=random(600);}
else if(dir==3){ ballX[i]=600; ballY[i]=random(600);}
}
2013年9月30日 星期一
99163116 鄭祥斌
void setup(){
size(400,400);
background(255);
}
void draw(){
}
void mouseDragged(){
line(mouseX, mouseY, pmouseX, pmouseY); (pmouseX,pmouseY)劃一條線到滑鼠之前的位置
storke(125,100,0); 筆觸顏色
strokeWeight(5); 筆觸寬度
}
void setup(){
size(750,750);
background(255);
}
void draw(){
fill(255,0,0);
rect(0,0,150,150);
fill(255,111,0);
rect(0,150,150,150);
fill(255,226,0);
rect(0,300,150,150);
fill(0,255,0);
rect(0,450,150,150);
fill(0,0,255);
rect(0,600,150,150);
fill(250,0,255);
rect(150,600,150,150);
fill(139,0,255);
rect(300,600,150,150);
fill(193,132,8);
rect(450,600,150,150);
fill(5,255,253);
rect(600,600,150,150);
}
void mouseDragged(){
line(mouseX, mouseY, pmouseX, pmouseY);
strokeWeight(5);
}
void mouseReleased(){
if (mouseX<150 && mouseY<150) stroke(255,0,0);
else if(mouseX<150 && mouseY<300) stroke(255,111,0);
else if(mouseX<150 && mouseY<450) stroke(255,226,0);
else if(mouseX<150 && mouseY<600) stroke(0,255,0);
else if(mouseX<150 && mouseY<750) stroke(0,0,255);
else if(mouseX<300 && mouseY<750) stroke(250,0,255);
else if(mouseX<450 && mouseY<750) stroke(139,0,255);
else if(mouseX<600 && mouseY<750) stroke(193,132,8);
else if(mouseX<750 && mouseY<750) stroke(5,255,253);
}
void setup(){
size(750,750);
background(255);
noStroke();
colorMode(HSB, 100);
for (int i = 0; i < 100; i++) {
for (int j = 0; j < 100; j++) {
stroke(i, j, 100);
point(i, j);
}
}
}
void draw(){
}
void mouseDragged(){
line(mouseX, mouseY, pmouseX, pmouseY);
strokeWeight(5);
}
void mouseReleased(){
if (mouseX<150 && mouseY<150) stroke(mouseX,mouseY,100);
}
void setup() {
size(750, 750);
background(255);
noStroke();
colorMode(RGB, 255);
fill(255, 0, 0);
rect(0, 0, 150, 150);
fill(255, 111, 0);
rect(0, 150, 150, 150);
fill(255, 226, 0);
rect(0, 300, 150, 150);
fill(0, 255, 0);
rect(0, 450, 150, 150);
fill(0, 0, 255);
rect(0, 600, 150, 150);
fill(250, 0, 255);
rect(150, 600, 150, 150);
fill(139, 0, 255);
rect(300, 600, 150, 150);
fill(193, 132, 8);
rect(450, 600, 150, 150);
fill(5, 255, 253);
rect(600, 600, 150, 150);
colorMode(HSB, 100);
for (int i = 0; i < 150; i++) {
for (int j = 0; j < 150; j++) {
stroke(i, j, 100);
point(i+600, j);
}
}
}
void draw() {
}
void mouseDragged() {
line(mouseX, mouseY, pmouseX, pmouseY);
strokeWeight(5);
}
void mouseReleased() {
if (mouseX<150 && mouseY<150) stroke(#FF0000);
else if (mouseX<150 && mouseY<300) stroke(#FF6F00);
else if (mouseX<150 && mouseY<450) stroke(#FFE200);
else if (mouseX<150 && mouseY<600) stroke(#00FF00);
else if (mouseX<150 && mouseY<750) stroke(#0000FF);
else if (mouseX<300 && mouseY<750) stroke(#FA00FF);
else if (mouseX<450 && mouseY<750) stroke(#8B00FF);
else if (mouseX<600 && mouseY<750) stroke(#C18408);
else if (mouseX<750 && mouseY<750) stroke(#05FFFD);
else if (mouseX<750 && mouseY<150) {
colorMode(HSB, 100);
stroke(mouseX, mouseY, 100);
//colorMode(RGB,255);
}
}
size(400,400);
background(255);
}
void draw(){
}
void mouseDragged(){
line(mouseX, mouseY, pmouseX, pmouseY); (pmouseX,pmouseY)劃一條線到滑鼠之前的位置
storke(125,100,0); 筆觸顏色
strokeWeight(5); 筆觸寬度
}
void setup(){
size(750,750);
background(255);
}
void draw(){
fill(255,0,0);
rect(0,0,150,150);
fill(255,111,0);
rect(0,150,150,150);
fill(255,226,0);
rect(0,300,150,150);
fill(0,255,0);
rect(0,450,150,150);
fill(0,0,255);
rect(0,600,150,150);
fill(250,0,255);
rect(150,600,150,150);
fill(139,0,255);
rect(300,600,150,150);
fill(193,132,8);
rect(450,600,150,150);
fill(5,255,253);
rect(600,600,150,150);
}
void mouseDragged(){
line(mouseX, mouseY, pmouseX, pmouseY);
strokeWeight(5);
}
void mouseReleased(){
if (mouseX<150 && mouseY<150) stroke(255,0,0);
else if(mouseX<150 && mouseY<300) stroke(255,111,0);
else if(mouseX<150 && mouseY<450) stroke(255,226,0);
else if(mouseX<150 && mouseY<600) stroke(0,255,0);
else if(mouseX<150 && mouseY<750) stroke(0,0,255);
else if(mouseX<300 && mouseY<750) stroke(250,0,255);
else if(mouseX<450 && mouseY<750) stroke(139,0,255);
else if(mouseX<600 && mouseY<750) stroke(193,132,8);
else if(mouseX<750 && mouseY<750) stroke(5,255,253);
}
void setup(){
size(750,750);
background(255);
noStroke();
colorMode(HSB, 100);
for (int i = 0; i < 100; i++) {
for (int j = 0; j < 100; j++) {
stroke(i, j, 100);
point(i, j);
}
}
}
void draw(){
}
void mouseDragged(){
line(mouseX, mouseY, pmouseX, pmouseY);
strokeWeight(5);
}
void mouseReleased(){
if (mouseX<150 && mouseY<150) stroke(mouseX,mouseY,100);
}
void setup() {
size(750, 750);
background(255);
noStroke();
colorMode(RGB, 255);
fill(255, 0, 0);
rect(0, 0, 150, 150);
fill(255, 111, 0);
rect(0, 150, 150, 150);
fill(255, 226, 0);
rect(0, 300, 150, 150);
fill(0, 255, 0);
rect(0, 450, 150, 150);
fill(0, 0, 255);
rect(0, 600, 150, 150);
fill(250, 0, 255);
rect(150, 600, 150, 150);
fill(139, 0, 255);
rect(300, 600, 150, 150);
fill(193, 132, 8);
rect(450, 600, 150, 150);
fill(5, 255, 253);
rect(600, 600, 150, 150);
colorMode(HSB, 100);
for (int i = 0; i < 150; i++) {
for (int j = 0; j < 150; j++) {
stroke(i, j, 100);
point(i+600, j);
}
}
}
void draw() {
}
void mouseDragged() {
line(mouseX, mouseY, pmouseX, pmouseY);
strokeWeight(5);
}
void mouseReleased() {
if (mouseX<150 && mouseY<150) stroke(#FF0000);
else if (mouseX<150 && mouseY<300) stroke(#FF6F00);
else if (mouseX<150 && mouseY<450) stroke(#FFE200);
else if (mouseX<150 && mouseY<600) stroke(#00FF00);
else if (mouseX<150 && mouseY<750) stroke(#0000FF);
else if (mouseX<300 && mouseY<750) stroke(#FA00FF);
else if (mouseX<450 && mouseY<750) stroke(#8B00FF);
else if (mouseX<600 && mouseY<750) stroke(#C18408);
else if (mouseX<750 && mouseY<750) stroke(#05FFFD);
else if (mouseX<750 && mouseY<150) {
colorMode(HSB, 100);
stroke(mouseX, mouseY, 100);
//colorMode(RGB,255);
}
}
void setup() {
size(750, 750);
background(255);
noStroke();
colorMode(HSB, 100);
for (int i = 0; i < 100; i++) {
for (int j = 0; j < 100; j++) {
stroke(i, j, 100);
point(i, j);
}
}
fill(255);
rect(400, 0, 100, 100);
strokeWeight(30);
stroke(#000000);
point(450, 50);
}
void draw() {
}
//void mouseDragged() {
// line(mouseX, mouseY, pmouseX, pmouseY);
//}
void mousePressed() {
if (mouseX<150 && mouseY<150)
{
colorMode(HSB, 100);
stroke(mouseX, mouseY, 100);
}
// else if (mouseX<150 && mouseY<300) {
//else if (mouseX<150&&mouseY<300)
stroke(#8FF5E8);
//}
}
2013年9月22日 星期日
99163116 鄭祥斌
1.畫出五子棋
void setup() {
size(800, 800);
}
void draw() {
background(#F0D079);使用 Tool- Color Selector, 挑出你要的顏色, 可用 R,G,B 來描述,也可用 #0B33FF 之類的像亂碼的數字來設定顏色
noFill();
strokeWeight(6); 在 Help-Reference 裡面可以找 stroke 相關的功能
rect(50, 50, 700, 700);
strokeWeight(1);
for (int i=0;i<9;i++) {
line(50, 50+i*80, 750, 50+i*80); line() 是用來配上不同的 strokeWeight() 粗細
line(50+i*80, 50, 50+i*80, 750);
}
}
int nowX, nowY;
void setup() {
size(800, 800);
}
void draw() {
background(#F0D079);
noFill();
strokeWeight(6);
rect(50, 50, 700, 700);
strokeWeight(1);
for (int i=0;i<9;i++) {
line(50, 50+i*80, 750, 50+i*80);
line(50+i*80, 50, 50+i*80, 750);
}
fill(255,0,0);
rect(nowX*80+50, nowY*80+50, 80,80);
}
void mouseMoved(){
nowX = (mouseX-50)/80;
nowY = (mouseY-50)/80;
println("mouseX:" + mouseX+"mouseY:"+mouseY+"nowX:"+nowX+"nowY:"+nowY);
}
int nowX, nowY;
int [][] array = new int [8][8];宣告陣列
void setup() {
size(800, 800);
}
void draw() {
background(#F0D079);
noFill();不會蓋過原本顏色
strokeWeight(6);
rect(50, 50, 700, 700);
strokeWeight(1);
for (int i=0;i<9;i++) {
line(50, 50+i*80, 750, 50+i*80);
line(50+i*80, 50, 50+i*80, 750);
}
fill(24, 120, 219);配上淡藍色
rect(nowX*80+50, nowY*80+50, 80, 80);
fill(237,138,245);配上淡紫色
for (int i=0;i<8;i++) {使用for迴圈,來進行陣列的比較、畫圖
for (int j=0;j<8;j++) {
if (array[i][j]==1) rect(i*80+50, j*80+50, 80, 80);
}
}
}
void mousePressed() { 使用函式來將mouse改變array[i][j]裡面的值
array[nowX][nowY]=1;
}
void mouseMoved() {
nowX = (mouseX-50)/80;
nowY = (mouseY-50)/80;
println("mouseX:" + mouseX+"mouseY:"+mouseY+"nowX:"+nowX+"nowY:"+nowY);
}
int nowColor=1;
int nowX, nowY;
int [][] array = new int [8][8];
void setup() {
size(800, 800);
}
void draw() {
background(#F0D079);
noFill();
strokeWeight(6);
rect(50, 50, 700, 700);
strokeWeight(1);
for (int i=0;i<9;i++) {
line(50, 50+i*80, 750, 50+i*80);
line(50+i*80, 50, 50+i*80, 750);
}
fill(24, 120, 219);
ellipse(nowX*80+50, nowY*80+50, 80, 80);
//rect(nowX*80+50, nowY*80+50, 80, 80);
//fill(237,138,245);
for (int i=0;i<8;i++) {
for (int j=0;j<8;j++) {
if (array[i][j]==1) {
fill(0);
ellipse(i*80+50, j*80+50, 80, 80);
}
if (array[i][j]==2) {
fill(255);
ellipse(i*80+50, j*80+50, 80, 80);
}
}
}
}
void mousePressed() {
array[nowX][nowY]=nowColor;
if (nowColor==1 ) nowColor=2;
else if (nowColor==2) nowColor=1;
}
void mouseMoved() {
nowX = (mouseX-50)/80;
nowY = (mouseY-50)/80;
println("mouseX:" + mouseX+"mouseY:"+mouseY+"nowX:"+nowX+"nowY:"+nowY);
}
int nowX, nowY;
int [][] array = new int [8][8];
void setup() {
size(800, 800);
}
void draw() {
background(#F0D079);
noFill();
strokeWeight(6);
rect(50, 50, 700, 700);
strokeWeight(1);
for (int i=0;i<9;i++) {
line(50, 50+i*80, 750, 50+i*80);
line(50+i*80, 50, 50+i*80, 750);
}
fill(24, 120, 219);
ellipse(nowX*80+50, nowY*80+50, 80, 80);
//rect(nowX*80+50, nowY*80+50, 80, 80);
//fill(237,138,245);
for (int i=0;i<8;i++) {
for (int j=0;j<8;j++) {
if (array[i][j]==1) {
fill(0);
ellipse(i*80+50, j*80+50, 80, 80);
}
if (array[i][j]==2) {
fill(255);
ellipse(i*80+50, j*80+50, 80, 80);
}
}
}
}
void mousePressed() {
array[nowX][nowY]=nowColor;
if (nowColor==1 ) nowColor=2;
else if (nowColor==2) nowColor=1;
}
void mouseMoved() {
nowX = (mouseX-50)/80;
nowY = (mouseY-50)/80;
println("mouseX:" + mouseX+"mouseY:"+mouseY+"nowX:"+nowX+"nowY:"+nowY);
}
這部影片是當放出音樂時,然後在影片上跑出圖案,如果當圖案通過終點線時,敲擊到,即可得分。
2013年9月15日 星期日
99163116 鄭祥斌
void setup() { 設定迴圈
size(600, 400);
}
void draw() { 畫圖迴圈
for (int x=0;x<600;x+=50) {
for (int y=0;y<400;y+=50) {
rect(x, y, 100, 100); x,y座標為變數
}
}
}
void setup() {
size(600, 400);
}
void draw() {
for (int x=0;x<600;x+=50) {
for (int y=0;y<400;y+=50) {
fill(0,255,200); fill為設定顏色
rect(x, y, 100, 100);
}
}
}
參考範例
void setup() {
size(600, 400);
}
void draw() {
for (int x=0;x<600;x+=50) {
for (int y=0;y<400;y+=50) {
fill(200,100,150);
rect(x, y, 100, 100);
ellipse(x+25,y+25,20,20);設定橢圓形,然後將橢圓使用變數設定變為正圓形,且置中於方框內
}
}
}
void setup() {
size(600, 400);
}
void draw() {
for (int x=0;x<600;x+=50) {
for (int y=0;y<400;y+=50) {
fill(200,100,180);充填顏色(這裡調配的是紫色),在畫方形前所填充的顏色
rect(x, y, 100, 100);
fill(255,255,0);充填顏色(這裡調配的是黃色),在畫橢圓形前所填充的顏色
ellipse(x+25,y+25,20,20);
fill(0,255,255);充填顏色(這裡調配的是淡藍色),在畫三角形前所填充的顏色
triangle(x+12.5,y, x+25,y+25, x,y+25);設定三角形,然後放在圓形的左上角
}
}
}
橢圓形內是alpha值(透明度)
void setup() {
size(600, 400);
}
void draw() {
for (int x=0;x<600;x+=50) {
for (int y=0;y<400;y+=50) {
fill(200,100,180);
rect(x, y, 100, 100);
fill(255,255,0, dist(x,y,mouseX,mouseY)/0.85);dist是距離,然後後面*的數字越大,範圍越小
ellipse(x+25,y+25,20,20);
fill(0,255,255);
triangle(x+12.5,y, x+25,y+25, x,y+25);
}
}
}
橢圓形內是alpha值(透明度)
void setup() {
size(600, 400);
}
void draw() {
for (int x=0;x<600;x+=50) {
for (int y=0;y<400;y+=50) {
fill(200,100,180);
rect(x, y, 100, 100);
fill(255,255,0, dist(x,y,mouseX,mouseY)/0.85);dist是距離,然後後面*的數字越大,範圍越小
ellipse(x+25,y+25,20,20);
fill(0,255,255);
triangle(x+12.5,y, x+25,y+25, x,y+25);
}
}
}
color [][] myColor= new color[12][8];宣告彩色陣列為12*8
void setup() {
size(600, 400);
for (int x=0;x<600;x+=50) {
for (int y=0;y<400;y+=50) {
myColor[x/100][y/100]=color(random(256),random(256),random(256));設定新的陣列及亂數序列,來改變顏色變化...............random是亂數
}
}
}
void draw() {
for (int x=0;x<600;x+=50) {
for (int y=0;y<400;y+=50) {
fill(200, 100, 180);
rect(x, y, 100, 100);
fill(255, 255, 0, dist(x, y, mouseX, mouseY)/0.85);
ellipse(x+25, y+25, 20, 20);
fill(myColor[x/100][y/100]);設定陣列,x,y座標除以某數,是因為原本設定的彩色陣列為12*8,但圖片座標大小為600*400,所以才需除以100使得其數值大小得以匹配(example:600/100=6,400/100=4)
triangle(x+12.5, y, x+25, y+25, x, y+25);
}
}
}
stroke是筆的顏色
課堂作業4(心得):從開學到現在已經第2堂課了,目前上課的速度我覺得還ok但可以稍微慢一點,因為有時程式的部分要理解以及作筆記這樣才不會忘記,最後還要活用,所以如果課程內容接得很緊湊的話,怕會吸收不了!!課程內容的話目前都還蠻有趣的!!
2013年9月8日 星期日
99163116鄭祥斌
第一次上課教的程式碼
size(600,600); 設定大小為600*600的視窗
background(0,255,0); 背影(紅,綠,藍)
rect(100,100,200,200); 在座標100*100的位置畫出200*200大小的方形 (rect:方形)
PImage imgBird=loadImage("http://www.cmlab.csie.ntu.edu.tw/~jsyeh/processing/angryBirdsBrick/bird.png");
讀取在網址內憤怒鳥的圖片
PImage imgPig =loadImage("http://www.cmlab.csie.ntu.edu.tw/~jsyeh/processing/angryBirdsBrick/pig.gif");
讀取在網址內飛天豬的圖片
image(imgBird, 100,100, 100,100);
將憤怒鳥的圖片放在座標100*100上面,然後以100*100維度的大小呈現
image(imgPig, 200,200, 100,100);
將飛天豬的圖片放在座標200*200上面,然後以100*100維度的大小呈現
第三節上課內容:
PImage imgBird,imgPig; 宣告有imgBird,imgPig這2個參數
void setup(){
size(600,600);
imgBird=loadImage("http://www.cmlab.csie.ntu.edu.tw/~jsyeh/processing/angryBirdsBrick/bird.png");
imgPig =loadImage("http://www.cmlab.csie.ntu.edu.tw/~jsyeh/processing/angryBirdsBrick/pig.gif");
imageMode(CENTER);將滑鼠座標在圖片內置中,此範例是以imgBird為例子
}
void draw(){
background(0,255,0);
image(imgBird, mouseX, mouseY);
image(imgPig, 200,200, 100,100);
}
然後當程式執行的時候,游標移動時,憤怒鳥也會跟著移動且游標會在憤怒鳥的中心
教學網址:
https://class.coursera.org/digitalmedia-001/lecture/index
size(600,600); 設定大小為600*600的視窗
background(0,255,0); 背影(紅,綠,藍)
rect(100,100,200,200); 在座標100*100的位置畫出200*200大小的方形 (rect:方形)
PImage imgBird=loadImage("http://www.cmlab.csie.ntu.edu.tw/~jsyeh/processing/angryBirdsBrick/bird.png");
讀取在網址內憤怒鳥的圖片
PImage imgPig =loadImage("http://www.cmlab.csie.ntu.edu.tw/~jsyeh/processing/angryBirdsBrick/pig.gif");
讀取在網址內飛天豬的圖片
image(imgBird, 100,100, 100,100);
將憤怒鳥的圖片放在座標100*100上面,然後以100*100維度的大小呈現
image(imgPig, 200,200, 100,100);
將飛天豬的圖片放在座標200*200上面,然後以100*100維度的大小呈現
第三節上課內容:
PImage imgBird,imgPig; 宣告有imgBird,imgPig這2個參數
void setup(){
size(600,600);
imgBird=loadImage("http://www.cmlab.csie.ntu.edu.tw/~jsyeh/processing/angryBirdsBrick/bird.png");
imgPig =loadImage("http://www.cmlab.csie.ntu.edu.tw/~jsyeh/processing/angryBirdsBrick/pig.gif");
imageMode(CENTER);將滑鼠座標在圖片內置中,此範例是以imgBird為例子
}
void draw(){
background(0,255,0);
image(imgBird, mouseX, mouseY);
image(imgPig, 200,200, 100,100);
}
然後當程式執行的時候,游標移動時,憤怒鳥也會跟著移動且游標會在憤怒鳥的中心
教學網址:
https://class.coursera.org/digitalmedia-001/lecture/index
訂閱:
文章 (Atom)









































