顯示具有 00163071盧泰佑 標籤的文章。 顯示所有文章
顯示具有 00163071盧泰佑 標籤的文章。 顯示所有文章

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日 星期日

第十週期中作品展示



我們是像水果忍者的方式,計時20秒切到水果會計分,有背景音樂是我難過(但影片沒有錄製聲音)
我是和盧泰佑一組

2013年10月20日 星期日

week 07


int area=30;
float posx, posy;


float xspeed = 3;
float yspeed = 2.2;

int xdirection = 1;
int ydirection = 1;


void setup()
{
  size(1080, 650);
  noStroke();
  frameRate(100);
  ellipseMode(CENTER);
  posx = width/2;
  posy = height/2;
}

void draw()
{
  background(0);
  posx = posx + ( xspeed * xdirection );
  posy = posy + ( yspeed * ydirection );
  if (posx > width-area || posx < area) {
    xdirection *= -1;
  }
  if (posy > height-area || posy < area) {
    ydirection *= -1;
  }

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

2013年10月13日 星期日

Week 06


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://pic14.nipic.com/20110525/7232897_160817638162_2.jpg");
  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;
}



PImage imgCar;
int carx =0;
int cary =0;
void setup() {
  size(600, 600);
  imgCar = loadImage("http://www.wallpaperslot.com/data/media/424/Mini%20Cooper.jpg");
}
void draw() {
  background(255);
  image(imgCar, carx+10, cary+200, 200, 150);
}

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



http://i-gameworld.com/games/gb6407.php

2013年10月6日 星期日

Week 05



size(640, 480);
translate(300, 200);
for (int i=0;i<10;i++) {
  rotate(PI/10);
  ellipse(0, 0, 10, 100);
}
void setup() {
  size(640, 480);
  colorMode(HSB, 150);
}
int flower=10;
void draw() {
  translate(mouseX, mouseY);
  fill(mouseX, mouseY, 150);
  for (int i=0;i<flower;i++) {
    rotate(PI/10);
    ellipse(0, 0, 30, 100);
  }
}
void mouseClicked(){
 flower++; 
}
int X[] =new int[100];
int Y[] =new int[100];
int Z=0;
void setup() {
  size(640, 640);
}
float q=0.0;
void draw() {
  background(255);
  q+=0.04;
  for (int i=0;i<Z;i++) flower(X[i], Y[i]);
  flower(mouseX, mouseY);
}
void flower(float x, float y) {
  pushMatrix();
  translate(x, y);
  rotate(q);
  for (int i=0;i<20;i++) {
    fill(255, 255, 0);
    rotate(2);
    ellipse(0, 0, 10, 200);
  }
  fill(255, 99, 23);
  ellipse(0, 0, 30, 30);
  popMatrix();
}
void mousePressed() {
  X[Z]=mouseX; 
  Y[Z]=mouseY;
  Z++;
  if (Z>=100) Z=0;
}

-----------------------------------

我跟陳映如想做的遊戲





2013年9月29日 星期日

week 04

void setup(){
  size(400,400);
  background(200);

}
void draw(){
  fill(5,147,30);
  rect(0,0,50,50);
  fill(40,125,255);
  rect(0,50,50,50);
  fill(255,5,0);
  rect(0,100,50,50);
  fill(177,95,190);
  rect(0,150,50,50);
}
void mouseDragged(){
  line(mouseX,mouseY,pmouseX,pmouseY);
}
void mousePressed(){
 if(mouseX<50 && mouseY<50) stroke(5,147,30);
 else if(mouseX<50 && mouseY<100) stroke(40,125,255);
 else if(mouseX<50 && mouseY<150) stroke(255,5,0);
 else if(mouseX<50 && mouseY<200) stroke(177,95,190);
}

void setup(){
  size(400,400);
  background(255);
  noStroke();
  colorMode(RGB, 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);
}
void mousePressed(){
 if(mouseX<100 && mouseY<100) stroke(mouseX,mouseY,100);
}
void setup() {
  size(400, 400);
  background(255);
  noStroke();
  colorMode(RGB,255);
  fill(143,50,199);
  rect(0,100,100,100);
  
  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);
}
void mousePressed() {
  if (mouseX<100 && mouseY<100){
    colorMode(HSB,100);
    stroke(mouseX, mouseY, 100);
  }
  else if(mouseX<100 && mouseY<200){
    stroke(#8FF5E8);
  }
}

void setup() {
  size(400, 400);
  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);
  ellipse(350,50,100,100);
  strokeWeight(5);
  stroke(#000000);
  point(350,50);
}
void draw() {
}
void mouseDragged() {
  line(mouseX, mouseY, pmouseX, pmouseY);
}
void mousePressed() {
  if (mouseX<100 && mouseY<100){
    colorMode(HSB,100);
    stroke(mouseX, mouseY, 100);
  }
  else if(mouseX<100 && mouseY<200){
    stroke(#8FF5E8);
  }
}
(可以儲存了)
void setup() {
  size(400, 400);
  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);
  ellipse(350, 50, 100, 100);
  strokeWeight(5);
  stroke(#000000);
  point(350, 50);
}
void draw() {
}

void keyPressed() {
  if (keyPressed) {
    if (key=='s') {
      save("Image00163071.jpg") ;
    }
  }
}
void mouseDragged() {
  line(mouseX, mouseY, pmouseX, pmouseY);
}
void mousePressed() {
  if (mouseX<100 && mouseY<100) {
    colorMode(HSB, 100);
    stroke(mouseX, mouseY, 100);
  }
  else if (mouseX<100 && mouseY<200) {
    stroke(#8FF5E8);
  }
}


===============================================================
老師辛苦了  要睡覺阿 !!!



2013年9月22日 星期日

week 03



void setup(){
  size(800,800);
}
void draw(){
  background(#F0D079);
  noFill();
  strokeWeight(6);
  rect(50,50,720,720);
  strokeWeight(1);
  for(int i=0;i<9;i++){
    line(50,50+i*80,770,50+i*80);
    line(50+i*80,50,50+i*80,770);
  }
}


int nowX,nowY;
void setup(){
  size(800,800);
}
void draw(){
  background(#F0D079);
  noFill();
  strokeWeight(6);
  rect(50,50,720,720);
  strokeWeight(1);
  for(int i=0;i<9;i++){
    line(50,50+i*80,770,50+i*80);
    line(50+i*80,50,50+i*80,770);
  }
  fill(255,0,0);
  ellipse (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 myColor=1;
int nowX,nowY;
int [][] array = new int [10][10];
void setup(){
  size(800,800);
}
void draw(){
  background(#F0D079);
  noFill();
  strokeWeight(6);
  rect(50,50,720,720,10);
  
  strokeWeight(1);
  for(int i=0;i<10;i++){
    line(50,50+i*80,770,50+i*80);
    line(50+i*80,50,50+i*80,770);
  }
  
  fill(255,0,0);
  ellipse(nowX*80+50,nowY*80+50,80,80);
  for(int i=0;i<10;i++){
     for(int j=0;j<10;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]=myColor;
  if(myColor==1)myColor=2; 
  else if(myColor==2)myColor=1;
}
void mouseMoved(){
  nowX = (mouseX)/80;
  nowY = (mouseY)/80;
  println(" mouseX: " + mouseX + " mouseY: " + mouseY + " nowX: " + nowX + " nowY: " + nowY); 
}





2013年9月15日 星期日

week 02




void setup(){
    size(600,400);
}

void draw(){
    for(int x=0;x<600;x+=100){
      for(int y=0;y<400;y+=100){
        rect(x,y,100,100);
      }
    }
}


void setup(){
    size(600,400);
}

void draw(){
    for(int x=0;x<600;x+=100){
      for(int y=0;y<400;y+=100){
        rect(x,y,100,100);
        fill(0,4,136,dist(x,y,mouseX-mouseY,y));
        triangle(x+10, y+90, x+55, y+10, x+90, y+90);
        fill(255,0,0,120);
        ellipse(x+75, y+35, 35, 45);
        fill(255,255,255);
      }
    }
}

color [][]myColor = new color[6][4];
void setup(){
    size(600,400);
    for(int x=0;x<600;x+=100){
       for(int y=0;y<400;y+=100){
          myColor[x/100][y/100] = color(random(152),random(126),random(1));
       } 
    }
}

void draw(){
    for(int x=0;x<600;x+=100){
      for(int y=0;y<400;y+=100){
        rect(x,y,100,100);
        fill(myColor[x/300][y/100],dist(x,y,mouseX-mouseY,y));
        triangle(x+10, y+90, x+55, y+10, x+90, y+90);
        fill(255,255,255,150);
        ellipse(x+53, y+55, 45, 45);
        fill(myColor[x/100][y/100],156);
      }
    }
}



color [][]myColor = new color[6][4];

void setup(){
    size(600,400);
    colorMode(HSB,255,255,255);  //另外一種調色變化 HSB
    for(int x=0;x<600;x+=100){
       for(int y=0;y<400;y+=100){
         myColor[x/100][y/100] = color(random(255), 255,255);
          //myColor[x/100][y/100] =  color(random(255),random(225),random(255));
       }
    }
}

void draw(){
    for(int x=0;x<600;x+=100){
      for(int y=0;y<400;y+=100){
        rect(x,y,100,100);
        fill(myColor[x/300][y/100],dist(x,y,mouseX-mouseY,y));
        triangle(x+10, y+90, x+55, y+10, x+90, y+90);
        fill(255,255,255,150);
        ellipse(x+53, y+55, 45, 45);
        fill(myColor[x/100][y/100],156);
      }
    }
}
color [][]myColor = new color[6][4];

void setup(){
    size(600,400);
    colorMode(HSB,255,255,255);  //另外一種調色變化 HSB
    for(int x=0;x<600;x+=100){
       for(int y=0;y<400;y+=100){
         myColor[x/100][y/100] = color(random(255), 255,255);
          //myColor[x/100][y/100] =  color(random(255),random(225),random(255));
       } 
    }
}

void draw(){
    for(int x=0;x<600;x+=100){
      for(int y=0;y<400;y+=100){
        rect(x,y,100,100);
        fill(myColor[x/300][y/100],dist(x,y,mouseX-mouseY,y));
        triangle(x+10, y+90, x+55, y+10, x+90, y+90);
        fill(255,255,255,150);
        ellipse(x+53, y+55, 45, 45);
        fill(myColor[x/100][y/100],156);
        
        
        triangle(x+10,y+25,x+35,y+35,x+98,y+125);
      }
    }
}



心得 : 上課速度我覺得OK~  上課內容重質不重量



2013年9月9日 星期一

Week01



size(600,600);
background(255, 0, 0);
rect(100,100, 200,200);
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, 0,0);
image(imgPig, 200,200,  100,100);



PImage imgBird, imgPig;

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);
}
void draw(){
  background(25, 200, 150);
  image(imgBird, mouseX,mouseY);
  image(imgPig, 200,200,100,100);
}