顯示具有 99160132劉翊晨 標籤的文章。 顯示所有文章
顯示具有 99160132劉翊晨 標籤的文章。 顯示所有文章

2013年1月18日 星期五

我們的期末作業是將期中做的打地鼠遊戲,由滑鼠控制改成用按鈕來決定要打擊的位置。

arduino
import processing.serial.*;
Serial myPort; 
int val;
float x;
float y;
float easing = 0.05;
int score;
int savetime;
PImage bang, bang1, mouse,mouse2,mouse3;
int hole=0;
   
import ddf.minim.*;
AudioPlayer player;
Minim minim;
AudioPlayer bm;
void setup() {
  size(800, 600);
  noStroke();
  bang = loadImage("bang.png");
  bang1 = loadImage("bang1.png");
  mouse=loadImage("mouse1.jpg");
  mouse2=loadImage("mouse2.png");
  savetime = millis();
  minim = new Minim(this); 
  player = minim.loadFile("123.mp3");
  player.play();
  size(200, 200);
 
  String portName = Serial.list()[0];
  myPort = new Serial(this, "COM1", 9600);
}
void draw(){
  if ( myPort.available() > 0) { 
    val = myPort.read();        
  }
  background(255);            
  if (val == 0) {            
    fill(0);                  
  }
  else {                    
    fill(204);               
  }
  rect(50, 50, 100, 100);
}
void draw() {
  image(mouse, 0, 0);
  float targetX = mouseX;
  if (mousePressed) {
    image(bang1, mouseX-60, mouseY-60);
    }
    else {
      image(bang, mouseX-60, mouseY-60);
    }
    if(millis()%1000<30){  
      hole=int(random(1,10)); 
    }
  
   
   fill(255,0,0); 
   if(hole==1){   image(mouse2, 80, 25);  } 
   if(hole==2){   image(mouse2, 340, 25); } 
   if(hole==3){   image(mouse2, 600,25);  } 
   if(hole==4){   image(mouse2, 50,190);   } 
   if(hole==5){   image(mouse2, 350,190);   } 
   if(hole==6){   image(mouse2, 620,190);}
   if(hole==7){   image(mouse2, 40,370);   }
   if(hole==8){   image(mouse2, 350,370);   }
   if(hole==9){   image(mouse2,645,370);   }  
   fill(255,255,255); 
    fill(255,255,255);
    textSize(24);
    text("S  C  O  R  E   : "+score, 100, 550);
    int passtime = millis() - savetime;
    int gametime = 15-passtime/1000;
    textSize(24);
    text("T I M E : "+gametime,500,550);
    if( gametime <= 0 ){
    background(255,255,0);
    fill(255,0,0);
    textSize(30);
  
    text(" T I M E    IS    UP ",200,200);
    text(" Y O U R    S  C  O  R  E  :  "+score, 200,300);
 
 
 }
}
void keyPressed(){
  if(key=='1' && hole==7){
    score=score+=100;
     }
  if(key=='2' && hole==8){
    score=score+=100;
     }
  if(key=='3' && hole==9){
    score=score+=100;
     }
  if(key=='4' && hole==4){
    score=score+=100;
     }
  if(key=='5' && hole==5){
    score=score+=100;
     }
  if(key=='6' && hole==6){
    score=score+=100;
     }
  if(key=='7' && hole==1){
    score=score+=100;
     }
  if(key=='8' && hole==2){
    score=score+=100;
     }
  if(key=='9' && hole==3){
    score=score+=100;
     }  
   minim=new Minim(this);
   bm=minim.loadFile("kk.wav", 2048);
   bm.play();
   }

processing
import processing.serial.*;
Serial myPort; 
int val;
float x;
float y;
float easing = 0.05;
int score;
int savetime;
PImage bang, bang1, mouse,mouse2,mouse3;
int hole=0;
   
import ddf.minim.*;
AudioPlayer player;
Minim minim;
AudioPlayer bm;
void setup() {
  size(800, 600);
  noStroke();
  bang = loadImage("bang.png");
  bang1 = loadImage("bang1.png");
  mouse=loadImage("mouse1.jpg");
  mouse2=loadImage("mouse2.png");
  savetime = millis();
  minim = new Minim(this); 
  player = minim.loadFile("123.mp3");
  player.play();
  size(200, 200);
 
  String portName = Serial.list()[0];
  myPort = new Serial(this, "COM1", 9600);
}
void draw(){
  if ( myPort.available() > 0) { 
    val = myPort.read();        
  }
  background(255);            
  if (val == 0) {            
    fill(0);                  
  }
  else {                    
    fill(204);               
  }
  rect(50, 50, 100, 100);
}
void draw() {
  image(mouse, 0, 0);
  float targetX = mouseX;
  if (mousePressed) {
    image(bang1, mouseX-60, mouseY-60);
    }
    else {
      image(bang, mouseX-60, mouseY-60);
    }
    if(millis()%1000<30){  
      hole=int(random(1,10)); 
    }
  
   
   fill(255,0,0); 
   if(hole==1){   image(mouse2, 80, 25);  } 
   if(hole==2){   image(mouse2, 340, 25); } 
   if(hole==3){   image(mouse2, 600,25);  } 
   if(hole==4){   image(mouse2, 50,190);   } 
   if(hole==5){   image(mouse2, 350,190);   } 
   if(hole==6){   image(mouse2, 620,190);}
   if(hole==7){   image(mouse2, 40,370);   }
   if(hole==8){   image(mouse2, 350,370);   }
   if(hole==9){   image(mouse2,645,370);   }  
   fill(255,255,255); 
    fill(255,255,255);
    textSize(24);
    text("S  C  O  R  E   : "+score, 100, 550);
    int passtime = millis() - savetime;
    int gametime = 15-passtime/1000;
    textSize(24);
    text("T I M E : "+gametime,500,550);
    if( gametime <= 0 ){
    background(255,255,0);
    fill(255,0,0);
    textSize(30);
  
    text(" T I M E    IS    UP ",200,200);
    text(" Y O U R    S  C  O  R  E  :  "+score, 200,300);
 
 
 }
}
void keyPressed(){
  if(key=='1' && hole==7){
    score=score+=100;
     }
  if(key=='2' && hole==8){
    score=score+=100;
     }
  if(key=='3' && hole==9){
    score=score+=100;
     }
  if(key=='4' && hole==4){
    score=score+=100;
     }
  if(key=='5' && hole==5){
    score=score+=100;
     }
  if(key=='6' && hole==6){
    score=score+=100;
     }
  if(key=='7' && hole==1){
    score=score+=100;
     }
  if(key=='8' && hole==2){
    score=score+=100;
     }
  if(key=='9' && hole==3){
    score=score+=100;
     }
 minim=new Minim(this);
     bm=minim.loadFile("kk.wav", 2048);
     bm.play();
   }
  
 

  
 

2012年12月4日 星期二

HW11,Week13

int buttonPin1 = 2;     // the number of the pushbutton pin
int buttonPin2 = 3;
int buttonPin3 = 4;
int buttonPin4 = 5;
int buttonPin5 = 6;
int buttonState1 = 0;       
int buttonState2 = 0;
int buttonState3 = 0;
int buttonState4 = 0;
int buttonState5 = 0;
int speakerPin = 9;
void setup() {
   pinMode(buttonPin1, INPUT);    
   pinMode(buttonPin2, INPUT);
   pinMode(buttonPin3, INPUT);
   pinMode(buttonPin4, INPUT);
   pinMode(buttonPin5, INPUT);
}

void loop(){
   buttonState1 = digitalRead(buttonPin1);
   buttonState2 = digitalRead(buttonPin2);
   buttonState3 = digitalRead(buttonPin3);
   buttonState4 = digitalRead(buttonPin4);
   buttonState5 = digitalRead(buttonPin5);
  
   if (buttonState1 == HIGH) { 
     tone(9, 262,100);  
   }
   else { }
  
   if (buttonState2 == HIGH) { 
     tone(9, 294,100);  
   }
   else { }
   if (buttonState3 == HIGH) { 
     tone(9, 330,100);  
   }
   else { }
   if (buttonState4 == HIGH) { 
     tone(9, 349,100);  
   }
   else { }
   if (buttonState5 == HIGH) { 
     tone(9, 392,100);  
   }
   else { }
}

2012年11月27日 星期二

week12,HW10

int sensorPin = A0;    // select the input pin for the potentiometer
int ledPin = 13;      // select the pin for the LED
int sensorValue = 0;  // variable to store the value coming from the sensor
void setup() {
  Serial.begin(9600);
  pinMode(13, OUTPUT);
  pinMode(12, OUTPUT); 
  pinMode(11, OUTPUT); 
  pinMode(10, OUTPUT); 
  pinMode(9, OUTPUT); 
  pinMode(8, OUTPUT);
  pinMode(7, OUTPUT);   
}
void loop() {
  sensorValue = analogRead(sensorPin); 
  Serial.println(sensorValue); 
 
  for (int i=13; i>=7; i--) {
    digitalWrite(i, HIGH);
    delay(sensorValue/10);
  }
   for (int i=13; i>=7; i--) {
    digitalWrite(i, LOW);
    delay(sensorValue/10);
  }
//  digitalWrite(13, HIGH);
//  delay(100);
//  digitalWrite(12, HIGH);
//  delay(100);
//  digitalWrite(11, HIGH);
//  delay(100); 
//  digitalWrite(10, HIGH);
//  delay(100); 
//  digitalWrite(9, HIGH);
//  delay(100);
//  digitalWrite(8, HIGH);
//  delay(100);
//  digitalWrite(7, HIGH); 
}

2012年11月12日 星期一

Midtern

float x;
float y;
float easing = 0.05;
int score;
int savetime;
PImage bang, bang1, mouse,mouse2,mouse3;
int hole=0;
import ddf.minim.*;
AudioPlayer player;
Minim minim;
AudioPlayer bm;
void setup() {
  size(800, 600);
  noStroke();
  bang = loadImage("bang.png");
  bang1 = loadImage("bang1.png");
  mouse=loadImage("mouse1.jpg");
  mouse2=loadImage("mouse2.png");
  savetime = millis();
  minim = new Minim(this); 
  player = minim.loadFile("123.mp3");
  player.play();
}
void draw() {
  image(mouse, 0, 0);
  float targetX = mouseX;
  if (mousePressed) {
    image(bang1, mouseX-60, mouseY-60);
    }
    else {
      image(bang, mouseX-60, mouseY-60);
    }
    if(millis()%1000<30){  
      hole=int(random(1,10)); 
    }
  
   
   fill(255,0,0); 
   if(hole==1){   image(mouse2, 80, 25);  } 
   if(hole==2){   image(mouse2, 340, 25); } 
   if(hole==3){   image(mouse2, 600,25);  } 
   if(hole==4){   image(mouse2, 50,190);   } 
   if(hole==5){   image(mouse2, 350,190);   } 
   if(hole==6){   image(mouse2, 620,190);}
   if(hole==7){   image(mouse2, 40,370);   }
   if(hole==8){   image(mouse2, 350,370);   }
   if(hole==9){   image(mouse2,645,370);   }  
   fill(255,255,255); 
    fill(255,255,255);
    textSize(24);
    text("S  C  O  R  E   : "+score, 100, 550);
    int passtime = millis() - savetime;
    int gametime = 40-passtime/1000;
    textSize(24);
    text("T I M E : "+gametime,500,550);
    if( gametime <= 0 ){
    background(255,255,0);
    fill(255,0,0);
    textSize(30);
  
    text(" T I M E    IS    UP ",200,200);
    text(" Y O U R    S  C  O  R  E  :  "+score, 200,300);
 
 
 }
}
void mouseClicked(){
    if( mouseX-60>70 && mouseX-60<200 && mouseY-60>15 && mouseY-60<188 && hole==1){
       score=score+=100;
     }
     if( mouseX-60>320 && mouseX-60<470 && mouseY-60>15 && mouseY-60<188 && hole==2){
       score=score+=100;
     }
     if( mouseX-60>580 && mouseX-60<730 && mouseY-60>15 && mouseY-60<188 && hole==3){
       score=score+=100;
     }
     if( mouseX-60>30 && mouseX-60<180 && mouseY-60>170 && mouseY-60<353 && hole==4){
       score=score+=100;
     }
     if( mouseX-60>330 && mouseX-60<480 && mouseY-60>170 && mouseY-60<353 && hole==5){
       score=score+=100;
     }
     if( mouseX-60>600 && mouseX-60<750 && mouseY-60>170 && mouseY-60<353 && hole==6){
       score=score+=100;
     }
     if( mouseX-60>20 && mouseX-60<170 && mouseY-60>350 && mouseY-60<533 && hole==7){
       score=score+=100;
     }
     if( mouseX-60>330 && mouseX-60<480 && mouseY-60>350 && mouseY-60<533 && hole==8){
       score=score+=100;
     }
     if( mouseX-60>625 && mouseX-60<775 && mouseY-60>350 && mouseY-60<533 && hole==9){
       score=score+=100;
     }
     minim=new Minim(this);
     bm=minim.loadFile("kk.wav", 2048);
     bm.play();
   }

1.之前完成了背景  和貼圖
2.本來想讓地鼠隨機從洞裡跑出來 然後可以用槌子打她
3.無法讓地鼠從洞裡隨機跑出來   也不知道如何既時間 和 分數

4.今天做了 槌子和打下去的槌子 背景


當初用到草稿 所以重新發布一次

2012年10月23日 星期二

HW07

int d1=0,d2=0,d3=0,d4=0,d5=0,d6=0,d7=0,d8=0,d9=0;
void setup(){
  size(800,600);
  PImage mouse;
  mouse=loadImage("mouse1.jpg");
 
  image(mouse, 0,0);
}
void draw(){
  if(d7==1){
    fill(255,0,0);
    ellipse(140,125,130,90);
  
  }else{
    fill(128,128,128);
  }
 
  if(d8==1){
    fill(255,0,0);
  }else{
    fill(128,128,128);
  }
   ellipse(390,125,130,90); 
  if(d9==1){
    fill(255,0,0);
  }else{
    fill(128,128,128);
  }
  ellipse(660,125,130,90); 
  if(d4==1){
    fill(255,0,0);
  }else{
    fill(128,128,128);
  }
  ellipse(100,300,130,90); 
  if(d5==1){
    fill(255,0,0);
  }else{
    fill(128,128,128);
  }
  ellipse(390,300,130,90); 
 if(d6==1){
    fill(255,0,0);
  }else{
    fill(128,128,128);
  }
  ellipse(660,290,130,90); 
  if(d1==1){
    fill(255,0,0);
  }else{
    fill(128,128,128);
  }
  ellipse(100,470,130,90); 
  if(d2==1){
    fill(255,0,0);
  }else{
    fill(128,128,128);
  }
  ellipse(395,475,130,90); 
  if(d3==1){
    fill(255,0,0);
  }else{
    fill(128,128,128);
  }
  ellipse(685,490,130,90); 
}
void keyPressed(){
  if(key=='1'){
    d1=1;
  }else if(key=='2'){
    d2=1;
  }else if(key=='3'){
    d3=1;
  }else if(key=='4'){
    d4=1;
  }else if(key=='5'){
    d5=1;
  }else if(key=='6'){
    d6=1;
  }else if(key=='7'){
    d7=1;
  }else if(key=='8'){
    d8=1;
  }else if(key=='9'){
    d9=1;
  }                       
}
void keyReleased(){
  if(key=='1'){
    d1=0;
  }else if(key=='2'){
    d2=0;
  }else if(key=='3'){
    d3=0;
  }else if(key=='4'){
    d4=0;
  }else if(key=='5'){
    d5=0;
  }else if(key=='6'){
    d6=0;
  }else if(key=='7'){
    d7=0;
  }else if(key=='8'){
    d8=0;
  }else if(key=='9'){
    d9=0;
  }                       
}
這禮拜我們在課堂上學到按鍵   我們想利用按鍵當感應區 當地鼠出來時可以利用鍵盤打他

問題如何讓地鼠可以隨機出現在洞裡面    還有如何調整速度等等...
.
2.視訊學校做不出來

2012年10月16日 星期二

HW06

1.我覺得廖子萱他麼那一組要做的東西很有內容,而且也很有趣,做出來應該會很耐玩。
2.我們會先把素材都找出來或做出來,先把背景貼上去,之後再將代替地鼠的圖片放上去,可能會設定成將地鼠的圖片在一段時間內隨機出現在地鼠洞上,然後設定槌子在地鼠上面點擊就會增加分數。以下是目前找到要用的素材。
 
 

2012年10月9日 星期二

HW05,Week05

(1)
void setup(){
  size(600,600);
}
float rrr=0.01;
void draw(){
  background(133,210,248);
  translate(mouseX,mouseY);
  rotate(rrr);rrr+=0.01;
  fill(255,0,0);
  for(int i=0;i<36;i++){
    rotate( PI/5);
  fill(255,0,0);
  ellipse(100,10,300,50);
}
  for(int i=0;i<36;i++){
    fill(random(255),random(255),random(255));
    rotate( PI/5);
    ellipse(100,50,200,100);
  }
  fill(105,255,0);
  ellipse(0,0,200,200);
}
(2)

(3)
 我們想要做類似打地鼠的小遊戲,希望後面能做的順利,首先要先把地鼠跟背景圖案先做出來才是我們現在目前的重要工作。

2012年10月2日 星期二

week04 HW04

void setup(){
  background(0,0,225);
  size(500,400);
  fill(255,0,0);rect(0,0,50,50);
  fill(0,0,0);rect(0,50,50,50);
  fill(255,255,255);
  rect(0,100,50,50);
  rect(0,150,50,50);
  rect(450,0,50,50);
  rect(450,50,50,50);
}
int www=5;
void draw(){
  if(mousePressed && mouseX<50 && mouseY<50) stroke(255,0,0);
  else if(mousePressed && mouseX<50 && mouseY<100) stroke(0,0,0);
  else if(mousePressed && mouseX<50 && mouseY<150) save("aaaa.png");
  else if(mousePressed && mouseX<50 && mouseY<200){
    PImage file = loadImage("aaaa.png");
    image(file, 0,0,500,400);
 
  }else if(mousePressed && mouseX>450 && mouseY<50){
    strokeWeight(++www);
  }
  else if(mousePressed && mouseX>450 && mouseY<1000){
    strokeWeight(--www);
    if(www<2)www=2;
  }
  else if(mousePressed)  line(mouseX, mouseY, pmouseX, pmouseY);
}

2012年9月25日 星期二

Week3,HW3

void setup(){
  size(600,600);
  background(0,0,255);
}
void draw(){
 
  fill(255,255,255);
  ellipse(100,100,100,100);
 
  fill(0,255,0);
  rect(mouseX,mouseY,50,50);
 
}

void setup(){
  size(600,600);
  frameRate(1);
}
float x=100,y=100;
void draw(){
  background(0,0,0);
  fill(255,255,0);
  ellipse(mouseX,mouseY,50,50);
  fill(0,255,0);
  ellipse(x,y,150,150);
  x=x*0.9 + mouseX*0.1;
  y=y*0.9 + mouseY*0.1;
}

心得感想:
今天老師教了很多,讓我在這三堂課學到了不少,有跟隨的,也有殘影變化的
雖然第三個很難,但我會盡我的努力去學看看,謝謝老師。

2012年9月18日 星期二




size(800,800); PImage kitty; kitty = loadImage("http://4.bp.blogspot.com/_ZzqosGpYFAw/TLFI6tHuiDI/AAAAAAAADDA/bbBoJ0Xz-50/s1600/Hello+Kitty.gif"); image(kitty, 20,20);


size(600,600);
for(int i=0;i<50;i++){
  fill( random(255), random(255), random(255));
  rect(random(500),random(500),random(500),random(500));
}






size(400,300);
for(int i=0;i<40;i++){
  for(int k=0;k<30;k++){
    fill(i*255/30,k*255/20,50);
    rect(i*10,k*10,  100,10);
  }
}

size(400,300);
for(int i=0;i<4;i++){
  for(int k=0;k<3;k++){
    fill(i*255/6,k*255/3,1);
    ellipse(i*100+50,k*100+50,100,100);
    fill(255,255,255);
    ellipse(i*100+50,k*100+50,98,30);
    fill(i*255/10,k*255/10,10);
    ellipse(i*100+50,k*100+50,30,30);
    
  }
}


今天是我第一次上課,剛開始本以為會很難,做完課堂作業後才發現還跟得上進度,也沒有想像中的困難。