顯示具有 00160945陳映儒 標籤的文章。 顯示所有文章
顯示具有 00160945陳映儒 標籤的文章。 顯示所有文章

2014年1月12日 星期日

2013年12月30日 星期一

第十七週 課堂作業及回家作業

老師不在請學長來
這週我們把Arduino和processing的部份結合起來
再做一些修改,例如加了分數計算和時間限制...等等
然後這週也討論了外型要怎麼做

/////processing////
import ddf.minim.*; import ddf.minim.analysis.*; Minim minim; AudioPlayer song;
PImage bg; PImage Aircraft; float Px=500; float Py=470; PImage boom; int off=0; PImage die; int score=-80, lastTime=60;
import processing.serial.*;
Serial serial;
void setup() { minim = new Minim(this); song = minim.loadFile("1.mp3", 2048);
serial=new Serial(this, "COM4", 9600);
frameRate(25); size (1100, 600); song.play(); bg = loadImage("sky.jpg"); Aircraft = loadImage("1.jpg"); Random(); }
float [] x= new float [8]; float y; char c=' ';
void draw() {
if (serial.available()>0) { c=(char)serial.read(); print(c); if (c=='3') { Px-=10; } if (c=='4') { Px+=10; } }
background(bg); image(Aircraft, Px, Py); boom=loadImage("boom.jpg"); int m=millis(); textSize(30); fill(m/10%10,m/10%10,m/10%255); text("Time:"+lastTime, 10,40); text("Score:"+score, 330,40); lastTime=60-millis()/1000;
if (off==0) { for (int i=0;i<8;i++) { image(boom, x[i], y++); if (dist(Px+35, Py+42.5, x[i]+45, y+45)<90.6) { off=1; print("boom"); song.close();//音樂停止 minim.stop(); super.stop(); } } if (y>525) { Random(); y=0; } } if (off==1) { die=loadImage("booms.jpg"); image(die, 0, 0); textSize(70); fill(255,0,0); text("Your score:"+score,500,100); } if(lastTime==0) { stop();
textSize(75); fill(255,0,0); text("Times up!", 150,140); text("You Win!", 150,220); text("Your score:"+score,150,300);
} }
void Random() { for (int i=0;i<8;i++) x[i]=random(1100); score+=80; }
/*void keyPressed() { if (keyCode==RIGHT) Px+=10; else if (keyCode==LEFT) Px-=10; } */


////Arduino////
int switchStateRed = 0; int switchStateBlue = 0; int switchStateW = 0; int switchStateA = 0; const int ledPin = 13; // led connected to digital pin 13 const int knockSensor = A0; // the piezo is connected to analog pin 0 const int threshold = 100; int sensorReading = 0; // variable to store the value read from the sensor pin int ledState = LOW;
void setup(){ pinMode(ledPin, OUTPUT); pinMode(4,INPUT); pinMode(5,INPUT); Serial.begin(9600); }
//int a=0,b=0;
void loop(){ sensorReading = analogRead(knockSensor); switchStateW = digitalRead(4); switchStateA = digitalRead(5);
if (sensorReading >= threshold) {
ledState = !ledState;
digitalWrite(ledPin, ledState);
} if(switchStateW == HIGH) {Serial.write('3');} if(switchStateA == HIGH) {Serial.write('4');} delay(33); }

2013年12月23日 星期一

第十六週 課堂作業及回家作業

第16週12/23寫Arduino的部份
用兩個按鈕控制左右移動


int switchStateRed = 0; int switchStateBlue = 0; int switchStateW = 0; int switchStateA = 0; const int ledPin = 13; // led connected to digital pin 13 const int knockSensor = A0; // the piezo is connected to analog pin 0 const int threshold = 100; int sensorReading = 0; // variable to store the value read from the sensor pin int ledState = LOW;
void setup(){ pinMode(ledPin, OUTPUT); pinMode(4,INPUT); pinMode(5,INPUT); Serial.begin(9600); }
//int a=0,b=0;
void loop(){ sensorReading = analogRead(knockSensor); switchStateW = digitalRead(4); switchStateA = digitalRead(5);
if (sensorReading >= threshold) {
ledState = !ledState;
digitalWrite(ledPin, ledState);
} if(switchStateW == HIGH) {Serial.write('3');} if(switchStateA == HIGH) {Serial.write('4');} delay(33); }

2013年12月15日 星期日

Week 15



PImage bg;
PImage Aircraft;
int Px=500;
int Py=625;
PImage boom;

void setup()
{
  frameRate(30);
  size (1300, 800);
  bg = loadImage("sky.jpg");
  Aircraft = loadImage("1.jpg");
  Random();
}


float [] x= new float [8];
float y;
void draw()
{
  background(bg);
  image(Aircraft, Px, Py);
  boom=loadImage("boom.jpg");
  for (int i=0;i<8;i++)
    image(boom, x[i], y++);
  if (y>625)
  {
    Random();
    y=0;
  }
}


void Random()
{
  for (int i=0;i<8;i++)
    x[i]=random(1300);
}


void keyPressed()
{
  if (keyCode==RIGHT)
    Px+=10;
  else if (keyCode==LEFT)
    Px-=10;
}

2013年12月8日 星期日

第14週上課內容

期末作品企劃

第14週12/9企劃書
第15週12/16 用processing把小遊戲寫出來
第16週12/23寫Arduino的部份
第17週12/30老師不在
第18週1/6結合起來
第19週看有什麼需要修改的再弄一弄

我們想做的遊戲是想做閃避飛彈的小遊戲,
直升機要左右閃躲隨機掉落的飛彈
時間內全數閃過即勝利,
若被飛彈擊中即失敗
至於裝置的部份
我們想做一個桿子
桿子向左往左移,桿子向右往右移

2013年12月1日 星期日

week 13

 

#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);
angle=map(potVal,0,1023,0,179); Serial.print(",angle:"); Serial.print(angle); myServo.write(angle); delay(15); }

          

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); int pitch= map(sensorValue,sensorLow,sensorHigh,50,4000); tone(8,pitch,20); delay(10); }


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>=990&&keyVal<=1010) { tone(8,notes[1]); } else if(keyVal>=505&&keyVal<=515) { tone(8,notes[2]); } else if(keyVal>=5&&keyVal<=10) { tone(8,notes[3]); } else{noTone(8);} }

2013年11月24日 星期日

week 12

第三章 作業





const int sensorPin=A0; const float baselineTemp=20.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); }


const int greenLEDPin=9; const int redLEDPin=11; const int blueLEDPin=10;
const int redSensorPin=A0; const int greenSensorPin=A1; const int blueSensorPin=A2;
int redValue=0; int greenValue=0; int blueValue=0;
int redSensorValue=0; int greenSensorValue=0; int blueSensorValue=0;
void setup() { Serial.begin(9600);
pinMode(greenLEDPin,OUTPUT); pinMode(redLEDPin,OUTPUT); pinMode(blueLEDPin,OUTPUT); }
void loop() { redSensorValue=analogRead(redSensorPin); delay(5); greenSensorValue=analogRead(greenSensorPin); delay(5); blueSensorValue=analogRead(blueSensorPin); // delay(5);
Serial.print("Raw Sensor Values \t Red:"); Serial.print(redSensorValue); Serial.print("\t Green:"); Serial.print(greenSensorValue); Serial.print("\t Blue:"); Serial.print(blueSensorValue);
redValue=redSensorValue/4; greenValue=greenSensorValue/4; blueValue=blueSensorValue/4;
Serial.print("Mapped Sensor Values \t Red:"); Serial.print(redValue); Serial.print("\t Green:"); Serial.print(greenValue); Serial.print("\t Blue:"); Serial.print(blueValue);
analogWrite(redLEDPin,redValue); analogWrite(greenLEDPin,greenValue); analogWrite(blueLEDPin,blueValue); }

2013年11月17日 星期日

第 11 週



void setup() { pinMode(13, OUTPUT); pinMode(12, OUTPUT); pinMode(10, OUTPUT); } void loop() { digitalWrite(13, HIGH); delay(20); digitalWrite(13, LOW); delay(20); digitalWrite(12, HIGH); delay(1000); digitalWrite(12, LOW); delay(200); digitalWrite(10, HIGH); delay(2000); digitalWrite(10, LOW); delay(200);
}

2013年11月10日 星期日

2013年10月20日 星期日

第七週課堂作業及回家作業



int area=30;        // Width of the shape
float posx, posy;    // Starting position of shape  
float xspeed = 3;  // Speed of the shape
float yspeed = 2.2;  // Speed of the shape
int xdirection = 1;  // Left or Right
int ydirection = 1;  // Top to Bottom
void setup()
{
  size(1080, 650);
  noStroke();
  frameRate(80);
  ellipseMode(RADIUS);
  posx = width/2;
  posy = height/2;
}
void draw()
{
  background(0);
  posx = posx + ( xspeed * xdirection );
  posy = posy + ( yspeed * ydirection );

   if (posy > height-area || posy < area) {
    ydirection *= -1;
  }
  fill(255);
  rect(mouseX, 625, 150, 25);

  if (posx > width-area || posx < area) {
    xdirection *= -1;
  }



  ellipse(posx, posy, 15, 15);
}


兩個人交一份沒關係, 標注你的學號姓名

1. 請列出你今天三個小時,要完成的事
想完成球可以觸碰到桿子反彈,未觸碰到掉落GAME OVER
2. 你在期中作品要做到什麼程度
想完成一個完整的打磚塊遊戲,上面有方塊可以消掉
3. Why? 你為什麼要做它
覺得這是一個打發時間的一個很好的小遊戲而且玩久了會上癮

第六週課堂作業及回家作業


2013年9月15日 星期日

Week02 第二週上課內容及課堂作業







1.


2.

3.



 4.

[課堂作業4] 請大家寫一下到現在的心得 (ex. 速度, 內容, 想學的東西, 期待、希望、夢想..)

暑假接觸到現在從不曉得在幹嘛到現在終於覺得自己會一些東西了,
謝謝老師一直耐心的教導
希望老師可以在簡單的東西用少一點時間教
在比較複雜的東西花多一點時間
謝謝老師



2013年9月8日 星期日

Week01 第一週上課內容及課堂作業

0 課程準備
   去年BLOG:2012interaction.blogspot.tw
1 加入課程FB社團:2013interaction(o)
2 編寫Google文件,填寫修課資料(姓名,email,手機)(o)
3 加入且設定Blog(0)
編交作業方式: tag: 000葉正聖老師, Week01, 00160011葉大明
逗號隔開, 學號姓名間不要有空格

1. 看一下去年學長姐們做的成果 (划船、吃角子老虎、數位手套、直昇機控制搖桿), 聖誔老公公下樓梯
2. 試著執行 Processing

http://www.cmlab.csie.ntu.edu.tw/~jsyeh/processing/angryBirdsBrick/

1.


2.



3.







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");

void setup()
{
size(600,600);                                  //視窗大小
imageMode(CENTER);                       //移動的點在中心
background(255,255,0);
}


void draw()
{
background(150,150,100);
image(imgPig,300,300,400,400);
image(imgBird,mouseX,mouseY);
}