顯示具有 99160795李之寧 標籤的文章。 顯示所有文章
顯示具有 99160795李之寧 標籤的文章。 顯示所有文章

2013年1月19日 星期六

Week 11 , HW 09

1.尋找:有關Arduino的影片




2.寫下:有了 Processing + Arduino 可以做出甚麼?





















我們想到的是一樣可以做我們期中時的射擊遊戲,但是我們把它從滑鼠的射酒瓶改成直升機攔截飛彈可以搭配按鈕(搖桿)左右移動跟射擊的形式,來做互動遊戲

2013年1月18日 星期五

Week 19 , Final

系統名稱: 直升機保衛戰


1. 遊戲進行和裝置介紹

 

遊戲剛開始畫面















直升機射擊時的畫面

  

攔截失敗時的畫面(損失生命)














操作裝置(搖桿+射擊按鈕)






2. 遊戲玩法說明

        一開始進入遊戲, 畫面上方會隨機出現轟炸飛彈,此時必須使用搖桿控制直升機左右移動,並且按射擊鍵攔截飛彈,如果攔截飛彈失敗或是碰到機身,此時就會扣掉右下角的生命值,當生命值為0時,遊戲結束並且秀出得分狀況。


3. 遊戲Demo影片

 

4.程式碼

 
 /*Arduino*/
int pushButton = 2;
int pushButton2 = 6;
int pushButton3 = 7;
void setup() {

 Serial.begin(9600);
 pinMode(pushButton, INPUT_PULLUP);
 pinMode(pushButton2, INPUT_PULLUP);
 pinMode(pushButton3, INPUT_PULLUP);
}
int a=0;
int a2=0;
int a3=0;
// the loop routine runs over and over again forever:
void loop() {
 // read the input pin:
 int buttonState = digitalRead(pushButton);
 int buttonState2 = digitalRead(pushButton2);
  int buttonState3 = digitalRead(pushButton3);
 // print out the state of the button:
 if (buttonState == HIGH && a==0 ) { // If switch is ON,
   Serial.print(1); 
   a=1; // send 1 to Processing
 }
 if (buttonState == LOW && a==1) { // If the switch is not ON,
   Serial.println(0); 
   a=0; // send 0 to Processing
 }
 if (buttonState2 == HIGH && a2==0 ) { // If switch is ON,
   Serial.print(2); 
   a2=2; // send 1 to Processing
 }
 if (buttonState2 == LOW && a2==1) { // If the switch is not ON,
   Serial.println(3); 
   a2=3; // send 0 to Processing
 }
 if (buttonState3 == HIGH && a3==0 ) { // If switch is ON,
   Serial.print(4); 
   a3=4; // send 1 to Processing
 }
 if (buttonState3 == LOW && a3==1) { // If the switch is not ON,
   Serial.println(5); 
   a2=5; // send 0 to Processing
 }
 // Serial.println(buttonState);
 delay(10); // delay in between reads for stability
}
   

/*Processing*/
import processing.serial.*;
Serial myPort;  
int val;
PImage bg,helicopter,bomb;
PImage [] life = new PImage[5];
float hx=350,hy=400;
PImage [] missile = new PImage[5];
int[] mx = new int [5];
int[] my = new int [5];
int bx=0,by=0;

void setup(){
  size(840,525);
  String portName = Serial.list()[0];
  myPort = new Serial(this, "COM5", 9600);
  
  bg =loadImage("sky.jpg");
  helicopter= loadImage ("Helicopter.png");
  for(int i=0;i<5;i++){
   life[i]= loadImage("Life.png");
  }
  for(int i=0;i<5;i++){
   missile[i]= loadImage("Missile.png");
  }
  for(int i=0;i<5;i++){
    mx[i]=i*200;
    my[i]=(-300+i*40);
  }
  bomb= loadImage ("bomb.png");
}
void draw(){
  background(bg);
  life();
  helicopterA();
  missilefly();
  myserial();
  bomb();
}
void  helicopterA(){
  image(helicopter,hx,hy);
}
void life(){
  fill(180,180,180);
  rect(740,340,60,160);
  fill(255,0,0);
  rect(740,300,60,40);
  fill(255,255,255);
  textFont(createFont("Georgia", 25));
  text("LIFE ",742,330);
  for(int i=0;i<5;i++){
  image(life[i],690,320+(30*i),150,100);
  }

}
void missilefly(){
  for(int i=0;i<5;i++){
    image(missile[i],mx[i],my[i],50,100);
  }
  for(int i=0;i<5;i++){
    my[i]+=2;
  }
  for(int i=0;i<5;i++){
    if(my[i]==600){
      my[i]=(-300+i*40);
    }
  }
}

void myserial(){
  if ( myPort.available() &rt; 0) {  // If data is available,
    val = myPort.read();         // read it and store it in val
  }
  if (val == 0) {              // If the serial value is 0,
    translate(hx,hx+=10);
  } 
  else if(val == 2){                       // If the serial value is not 0,
    translate(hx,hx-=10);   
  }

}
void bomb(){
 int p=0;
  image(bomb,hx+90,hy+by,10,15);  
    if(val != 4 && by!=0){
      by-=10;
    }
  
    if (val == 4){
       by-=10;
    }
  if((hy+by)<=0){
    by=0;
 }
} 


5.心得

這次得專題製作跟以前碰過的都不太相同,除了還是有程式的撰寫之外,還必須同時結合到2個程式,所以中間的連結很重要。

此外在接Arduino線路時,必須克服許多問題(ex.接觸不良、接腳錯誤.....等)因此也花了較多的時間在處理硬體上面的問題,但是還好最後都有想出辦法解決(ex.絕緣膠帶,多接幾次線路並檢查)。

麒時後來在Demo時還覺得蠻有成就感的,畢竟是自己從無到有生出來的, 所以很開心!!

也謝謝各位同學在票選時對我們的厚愛,害我們自己都下了一跳呢! 謝謝大家 :)


6.工作分配



遊戲作品構思:

李之寧 、邱垂傑



遊戲程式:

Arduino + 合併 李之寧

Processing 邱垂傑




遊戲硬體:

Arduino 各線路連接 李之寧

搖桿本體製作 邱垂傑

 

  

2012年12月18日 星期二

Week 15, HW12


一、期末作品主題

期中時是做射擊酒瓶的遊戲,用滑鼠點擊移動中的酒瓶,並在限定的時間裡看可以得到多少分數。期末也打算做射擊方面的遊戲,但是會全部從新開始,我們想要做直升機的攔截遊戲,搭配arduino 的按鍵做出射擊的動作。

 

二、期末作品描述

直升機攔截遊戲,場景是銘傳大學,會讓直升機去攔截飛彈,畫面中會有從不同地方出現的飛彈,想轟炸我們美麗的校園。主要要搭配Arduino 的上、下、左、右 跟射擊鍵,操控直升機射擊出飛彈,來抵消從上方出現的飛彈,成功防禦我們的校園。當然期中時有做的功能,倒數計時、記分都會繼續保留,我們打算另外加上,如果沒有抵擋成功,使校園被炸到的話,會有失敗的畫面產生。

 

三、作品所需素材

畫面素材:

開始畫面












移動直升機













轟炸用飛彈






四、心得
後來跟老師討論過後,如果只做上下左右的按鈕再加一顆射擊鍵,這樣不如直接用鍵盤完還來的方便快速,因此後來稍稍的做了修改,可能會加入搖桿的功能,或是上下的功能改成用腳踏! 仿照值生機的內部操作。



2012年12月4日 星期二

Week 13, HW11

1. 自動撥音樂(整首小蜜蜂)

int speakerPin = 9;

int length = 24; // the number of notes
char notes[] = "geefddcdefggggeefddceggc "; // a space represents a rest
int beats[] = { 1, 1, 2, 1, 1, 2, 1, 1, 1, 1, 1, 1, 
2, 1, 1, 2, 1, 1, 2, 1, 1, 1, 1, 4};
int tempo = 300;

void playTone(int tone, int duration) {
  for (long i = 0; i < duration * 1000L; i += tone * 2) {
    digitalWrite(speakerPin, HIGH);
    delayMicroseconds(tone);
    digitalWrite(speakerPin, LOW);
    delayMicroseconds(tone);
  }
}

void playNote(char note, int duration) {
  char names[] = { 'c', 'd', 'e', 'f', 'g', 'a', 'b', 'C' };
  int tones[] = { 1915, 1700, 1519, 1432, 1275, 1136, 1014, 956 };

  // play the tone corresponding to the note name
  for (int i = 0; i < 8; i++) {
    if (names[i] == note) {
      playTone(tones[i], duration);
    }
  }
}

void setup() {
  pinMode(speakerPin, OUTPUT);
}

void loop() {
  for (int i = 0; i < length; i++) {
    if (notes[i] == ' ') {
      delay(beats[i] * tempo); // rest
    } else {
      playNote(notes[i], beats[i] * tempo);
    }

    // pause between notes
    delay(tempo / 2); 
  }
}

2.可用按鍵彈音階

const int buttonPin1 = 2;
const int buttonPin2 = 3;
const int buttonPin3 = 4;
const int buttonPin4 = 5;
const int buttonPin5 = 6;

int speakerPin = 9;

int buttonState1 = 0; // variable for reading the pushbutton status
int buttonState2 = 0;
int buttonState3 = 0;
int buttonState4 = 0;
int buttonState5 = 0;

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);
  int duration;
  
  if (buttonState1 == HIGH)  tone(speakerPin, 261,duration); //tone(pin, frequency, duration) 
  else if (buttonState2 == HIGH)  tone(speakerPin, 294,duration);
  else if (buttonState3 == HIGH)  tone(speakerPin, 329,duration);
  else if (buttonState4 == HIGH)  tone(speakerPin, 349,duration);
  else if (buttonState5 == HIGH)  tone(speakerPin, 392,duration);
  else {
  noTone(speakerPin);
  }
} 
 
3.心得
這節課教我們用 Arduino 撥放音樂,還有搭配按鈕彈音階, 讓我想到可以做鋼琴的小遊戲。
而且他的程式碼跟原裡沒有很難,董元李後就可以延伸很多不同的曲子。
可惜這節課當時沒有借到手機或相機,沒有把接出來的執行樣子拍攝下來,
有機會再用得獎的Arduino 再接一次~

2012年11月27日 星期二

Week 12 , HW10

1. Ardunio 影片




2.Ardunio 程式碼

/*
  Analog Input
 Demonstrates analog input by reading an analog sensor on analog pin 0 and
 turning on and off a light emitting diode(LED)  connected to digital pin 13.
 The amount of time the LED will be on and off depends on
 the value obtained by analogRead().

 The circuit:
 * Potentiometer attached to analog input 0
 * center pin of the potentiometer to the analog pin
 * one side pin (either one) to ground
 * the other side pin to +5V
 * LED anode (long leg) attached to digital output 13
 * LED cathode (short leg) attached to ground

 * Note: because most Arduinos have a built-in LED attached
 to pin 13 on the board, the LED is optional.


 Created by David Cuartielles
 modified 30 Aug 2011
 By Tom Igoe

 This example code is in the public domain.

 http://arduino.cc/en/Tutorial/AnalogInput

 */
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() {
  // declare the ledPin as an OUTPUT:
  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() {
  // read the value from the sensor:
  sensorValue = analogRead(sensorPin);
  Serial.println(sensorValue); 
  // turn the ledPin on
    digitalWrite(13, HIGH);
    digitalWrite(12, HIGH);
    digitalWrite(11, HIGH);
    digitalWrite(10, HIGH);
    digitalWrite(9, HIGH);
    digitalWrite(8, HIGH);
    digitalWrite(7, HIGH);
    delay(sensorValue);

    digitalWrite(13, LOW);
    digitalWrite(12, LOW);
    digitalWrite(11, LOW);
    digitalWrite(10, LOW);
    digitalWrite(9, LOW);
    digitalWrite(8, LOW);
    digitalWrite(7, LOW);
    delay(sensorValue);
 
  // stop the program for <sensorValue> milliseconds:
 // delay(sensorValue);         
  // turn the ledPin off:       
 // digitalWrite(ledPin, LOW);  
  // stop the program for for <sensorValue> milliseconds:
 // delay(sensorValue);                 
}

心得:
當時在試驗旋鈕調LED燈的閃爍速度時,一開始都旋轉快,一下子就扭到底發現他就會故障,試了幾次都會這樣,當時還一直搞不懂! 後來詢問同學才知道,原來旋鈕轉到極限,會使整個線路"爆掉",所以在旋轉時只要旋轉小小的角度就可以達到我們影片中,路出來的效果囉!!

2012年11月12日 星期一

Midtern

1. 遊戲畫面


遊戲開始畫面點選start布幕會拉開,且會有手槍上膛的聲音


攻擊酒瓶,打中酒瓶能得5分,時限30秒,開槍及打中都會有音效,且有背景音樂


遊戲結束將會計算所得總分。

2.DEMO影片




3.程式碼


/*Var 設定*/
import ddf.minim.*;
Minim minim;
AudioPlayer shoot,glass,shotgun,bgmusic,ccheer;

PImage screenleft,screenright,people,bg;   
boolean ctl=true,ctl2=false;          //control mouse press
int m=1; //control ending music  
int siteX1=0,siteX2=350,siteX3=525;   //Image site
 
PImage gun,star;
PImage [] bottle = new PImage[5];//酒瓶圖
float [] bx = new float [5];//位置
int savedTime,passedTime,gameTime;  //計時器時間
int score=0;//分數

/*首頁畫面*/
void Start()
{
  if(mousePressed&&mouseX<430&&mouseX&rt;270&&mouseY<430&&mouseY&rt;270&&ctl)
    ctl=false;
  if(ctl==false && ctl2==false){
     image(screenleft, siteX1-=3, 0, width/2, height);
     image(screenright,siteX2+=3,0,width/2, height);
     image(people,siteX3+=1,150,width/4, height/1.5);
     if(siteX1<-350&&siteX2&rt;700&&siteX3&rt;700) ctl2=true;
     if(ctl2) ;
  }
  else if(ctl==true && ctl2 == false){
     image(screenleft, siteX1, 0, width/2, height);
     image(screenright,siteX2,0,width/2, height);
     image(people,siteX3,150,width/4, height/1.5);
     fill(66,66,255);
     ellipse(350,350, 80,80);
     fill(255,255,0);
     textFont(createFont("Cooper Black", 20));
     text("START",315,358);
  } 
}

void setup() {
  //Size
  size(700,525);
  bg = loadImage("bg.jpg");
  
  //Load Image
  screenleft = loadImage("screen_left.jpg");
  screenright = loadImage("screen_right.jpg");
  people = loadImage("people.png");
  
  //Print Image
  image(screenleft, siteX1, 0, width/2, height);
  image(screenright,siteX2,0,width/2, height);
  image(people,siteX3,150,width/4, height/1.5);
  
  //code
   savedTime = millis();  //儲存遊戲開始的時間(只執行一次)
  
   gun=loadImage("gun.png");
   star=loadImage("star.png");
   for(int i=0;i<5;i++){
      bottle[i]=loadImage("bottle.png");
   }
   minim=new Minim(this);
   bgmusic=minim.loadFile("lion.wav", 2048);
   bgmusic.play();      
}

void draw() {
  background(bg);
  Start();
  //code
  if(siteX1<-350 && siteX2&rt;700 && siteX3&rt;700){
    bottle();    //酒瓶  
    gun();    //槍的準心
    word();    //字
    time();
    End();
  }
  /*結尾的拍手聲*/
  if(m==1 && gameTime<0){
    ccheer=minim.loadFile("ccheer.wav", 2048);
    ccheer.play();
    m--;
  }
}

/*槍的準心設置*/
void gun(){
  image(gun,530,420);
  image(star,mouseX-38,mouseY-35);
}
/*移動酒瓶的設置*/
void bottle(){
   for(int i=0;i<5;i++){
       image(bottle[i],i*50+bx[i],98,50,80);
       bx[i]+=1;
       if(bx[i]&rt;=700){
         bx[i]=0;
       }
     }
}
/*畫面上的字*/
void word(){
  textFont(createFont("Georgia", 40));
  text("Score:",20,500);
  textFont(createFont("Georgia", 40));//得分數
  text(score,150,500);
}
/*計時器*/
void time(){
  //當滑鼠按下,計時器重新回到60秒
  if(mousePressed&&mouseX<430&&mouseX&rt;270&&mouseY<430&&mouseY&rt;270&&ctl)
    ctl=false;
  if(ctl==false){
    savedTime = millis();
    if(siteX1<-350&&siteX2&rt;700&&siteX3&rt;700) ctl=true;
   }
  passedTime = millis() - savedTime;  //經過的秒數
  gameTime = 60-passedTime/1000;  //剩下的秒數
  textFont(createFont("Georgia", 40));
  text("Time: "+gameTime,250, 500);    

}   

/*槍射擊 & 音效*/
void mouseClicked(){
  minim=new Minim(this);
  shoot=minim.loadFile("BULLET.wav", 2048);
  shotgun=minim.loadFile("Shoutgun198.wav", 2048);
  glass=minim.loadFile("glass.wav",2048);
   
  //start的音效
  if(siteX1<-350 && siteX2&rt;700 && siteX3&rt;700){
    shoot.play();
   }
  for(int i=0;i<5;i++){
    if(mouseY&rt;100 && mouseY<175 && mouseX&rt;i*50+bx[i]+15 && mouseX<i*50+bx[i]+30){
      score+=5;
      shoot.pause();
      glass.play();
      bx[i]=0;
    }
  }
  //槍射擊音效
  if(mouseX<430&&mouseX&rt;270&&mouseY<430&&mouseY&rt;270){
    if(siteX1<-350 && siteX2&rt;700 && siteX3&rt;700){
      shotgun.pause();
    }
    else 
    shotgun.play();
  }
}
/*結尾畫面*/
void End(){
  if(gameTime<0){    
    background(0,0,0);
    fill(255,255,255);
    textFont(createFont("Georgia", 60));
    text("Game Over ",180,200);
    text("Your score:"+score,150,300);
    
    fill(66,66,255);
    ellipse(200,400, 80,80);
    fill(255,255,0);
    textFont(createFont("Cooper Black", 30));
    text("Exit",190,410);
    if(mousePressed && mouseX<280 && mouseX&rt;120 && mouseY<480 && mouseY&rt;320){  
      exit();
    }  
    
  }  
  
}


2012年10月30日 星期二

Week08 , HW08

1. 請寫下以下資料:
1.1. 你之前完成了什麼?
找完素材,想好架構,並尋找可利用的程式

1.2. 你今天計畫要做什麼?
(a)把首頁畫面完成
(b)遊戲畫面裡,酒瓶可以跑出來,準心可以跟著滑鼠移動

1.3. 可能會遇到的問題... (及可能的解決方法)
(a)選單畫面的設置
(b)儲存酒瓶的陣列


2. 請把你目前期中作品的進度貼出來
(a)首頁畫面



(a)把首頁畫面完成


程式碼:
PImage screenleft,screenright,people,bg;  
boolean ctl=true,ctl2=false;          //control mouse press
int siteX1=0,siteX2=350,siteX3=525;   //Image site
//Var
PImage gun,star;
PImage [] bottle = new PImage[5];
float [] bx = new float [5];
//首頁畫面
void Start()
{
  if(mousePressed&&mouseX<430&&mouseX>270&&mouseY<430&&mouseY>270&&ctl)
    ctl=false;
  if(ctl==false && ctl2==false){
     image(screenleft, siteX1-=3, 0, width/2, height);
     image(screenright,siteX2+=3,0,width/2, height);
     image(people,siteX3+=1,150,width/4, height/1.5);
     if(siteX1<-350&&siteX2>700&&siteX3>700) ctl2=true;
     if(ctl2) ;
  }
  else if(ctl==true && ctl2 == false){
     image(screenleft, siteX1, 0, width/2, height);
     image(screenright,siteX2,0,width/2, height);
     image(people,siteX3,150,width/4, height/1.5);
     fill(66,66,255);
     ellipse(350,350, 80,80);
     fill(255,255,0);
     textFont(createFont("Georgia", 20));
     text("START",320,355);
  }
}
void setup() {
  //Size
  size(700,525);
  bg = loadImage("bg.jpg");
 
  //Load Image
  screenleft = loadImage("screen_left.jpg");
  screenright = loadImage("screen_right.jpg");
  people = loadImage("people.png");
 
  //Print Image
  image(screenleft, siteX1, 0, width/2, height);
  image(screenright,siteX2,0,width/2, height);
  image(people,siteX3,150,width/4, height/1.5);
 
  //code
  //textFont(createFont("Georgia", 40));
   gun=loadImage("gun.png");
   star=loadImage("star.png");
   for(int i=0;i<5;i++){
      bottle[i]=loadImage("bottle.png");
    }
}
void draw() {
  background(bg);
  Start();
  //code
  if(siteX1<-350&&siteX2>700&&siteX3>700){
  bottle(); 
  gun();
 
  }
}
void gun(){
  image(gun,530,420);
  image(star,mouseX,mouseY);
  text("Score:",40,500);
}
void bottle(){
   for(int i=0;i<5;i++){
     image(bottle[i],i*50+bx[i],98,50,80);
     bx[i]+=2;
     if(bx[i]==700){
       bx[i]=0;
     }
  }
}




2012年10月23日 星期二

Week07 , HW07

1.期中作品

(a)增加素材

射擊的手槍







瞄準的標靶










2.視訊

執行畫面:















全世界最短視訊程式碼(小葉老師)

import processing.video.*;
Capture video;
void setup(){
  size(640,480,P2D);
  video = new Capture(this, width, height);
  video.start();
  loadPixels();
}
void draw(){
  if(video.available()){
    video.read();
    video.loadPixels();
    for(int i=0;i<640*480;i++){
      pixels[i]=video.pixels[i];     
    }
    updatePixels();
  }
}

2012年10月16日 星期二

Week06 , HW06

1. 寫作品建議
*鍾毅軍
  棒球遊戲很好玩,不過感覺難度就很高
  畢竟投球一定沒有只有一個路線
  所以還要做不同的投球路徑
  但是如果做出來的話一定會很棒
*詹中豪&王靚瑄
  傳統俄羅斯方塊的玩法,但是搭配了視訊系統
  第一次看到這種玩法
  建議可以增加更下一個方塊互換的功能
  這樣可以玩久一點~

2.做期中作品
(a)素材

背景














人物












酒瓶












(b)想流程解詳細的寫下步驟
*
一開始有個開始的畫面,有人物拿著手槍和一個開始的START鍵。
Start 鍵 滑鼠點下後,布幕會向兩側滑開,準備開始!

**
開始遊戲後,時間會開始倒數60秒(預計),
且酒瓶&酒杯會從布幕後面跑出來。

***
酒瓶跟酒杯,射擊到的分數會不同,因此也會有計分的功能。

****
瞄準的準心會跟著槍枝移動,當準心觸及酒瓶並點擊滑鼠後,酒瓶就會消失,並計分。


(c)是code 看想法是否可行

3.心得
這週自己的進度較慢,上星期請公假,想說要把沒學到的地方先補起來
結果上週的大致上補完了,但是這週的就有很多地方寫得有點兒簡略
下週會把他做得更詳細!



2012年10月15日 星期一

Week05 , HW05

1.
花兒會自己旋轉





















程式碼:

 void setup()
{
  size(600,600);
}
  float r=0.01;
void draw()
{
  background(0,0,0);
  translate(300,300);
  rotate(r);
  r+=0.001;
  fill(255,255,0);
  for(int i=0;i<36;i++)
  {
    rotate( PI/6);
    ellipse(100,0,200,55);
    rotate( PI/6);
    ellipse(200,0,200,55);
  }
  fill(100,250,100);
  ellipse(0,0,50,50);
}

2.花會隨滑鼠移動且背景顏色會跟著變化




















程式碼:

 void setup()
{
  size(600,600);
}
  float r=0.01;
void draw()
{
  background(125,mouseX*1/2,mouseY*1/3);
  translate(mouseX,mouseY);
  rotate(r);
  r+=0.001;
  fill(255,255,0);
  for(int i=0;i<36;i++)
  {
    rotate( PI/8);
    ellipse(100,0,200,55);
    rotate( PI/8);
    ellipse(200,0,200,55);
  }
  fill(100,250,100);
  ellipse(0,0,50,50);
}

3. 期末想做的小遊戲  & 邱垂傑


射擊酒瓶的遊戲!!
酒瓶要會移動~
且要增加計分&時間倒數的功能!!


2012年10月2日 星期二

Week04 , HW04

1.  小畫家
執行畫面




 

















儲存畫面




2.程式碼

void setup(){
  size(500,400);
  background(255,255,255);
  fill(255,0,0);
  rect(0,0,50,50);//Red
  fill(0,255,0);
  rect(0,50,50,50);//Green
  fill(0,0,255);
  rect(0,100,50,50);//Blue
  fill(255,255,255);
  rect(0,150,50,50);//eraser
  fill(0,0,0);
  text("eraser",6,180);
  fill(255,255,255);
  rect(0,200,50,50);//save
  fill(0,0,0);
  text("save",10,230);
  fill(255,255,255);
  rect(450,0,50,50);
  ellipse(475, 25, 2,2);//samllpen
  rect(450,50,50,50);
  ellipse(475, 75, 6, 6);//midpen
  rect(450,100,50,50);
  ellipse(475, 125, 10,10);//largepen
}
void draw(){
  if(mousePressed && mouseX<50 && mouseY <50) stroke(255,0,0);
  else if(mousePressed && mouseX<50 && mouseY <100) stroke(0,255,0);
  else if(mousePressed && mouseX<50 && mouseY <150) stroke(0,0,255);
  else if(mousePressed && mouseX<50 && mouseY <200) stroke(255,255,255);
  else if(mousePressed && mouseX<50 && mouseY <250) save("QQQ.png");
   else if(mousePressed && mouseX>450 && mouseY <50) strokeWeight(2);
    else if(mousePressed && mouseX>450 && mouseY <100) strokeWeight(6);
     else if(mousePressed && mouseX>450 && mouseY <150) strokeWeight(10);
  if(mousePressed) line(mouseX,mouseY,pmouseX,pmouseY);
}

3. 心得
小畫家的原理很好理解
區塊滑鼠點到就換色
不過如果顏色要設多一點,像電腦的小畫家一樣
這樣程式碼不就必須要寫很長@@??

現在光做簡易版就有點眼花了
不知道有沒有辦法簡化一點

2012年9月25日 星期二

Week03, HW03

1. 東西跟著滑鼠動(簡易版)

程式碼 :

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

void draw(){
  fill(255,0,255);
  rect(100,100,100,100);
  rect(400,100,100,100);

  fill(0,255,255);
  ellipse(mouseX,mouseY,100,100);
}





2. 東西追著滑鼠跑(簡易版)

程式碼 :
void setup(){
  size(600,600);
}
float x=100,y=100;
void draw(){
  background(0,0,0);

  fill(255,255,255);
  ellipse(mouseX,mouseY,100,100);

  fill(255,255,0);
  ellipse(x,y,50,50);

  x=x*0.8 + mouseX*0.2;
  y=y*0.8 + mouseY*0.2;
}



3.心得
東西隨著滑鼠跑,突然想到很多小遊戲的應用
都會用到這個程式
感覺期中&期末的作業
會用的到 :)

2012年9月18日 星期二

Week02, HW02

1. 隨機畫50個 rect




















程式碼:

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

2.畫有規則,顏色漸層的正方形



程式碼:

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


3.多個圓


















































程式碼:


size(600,400);
background(0, 0, 0);
for(int i=0;i<60;i++){
  for(int k=0;k<40;k++){
    fill(random(255),random(255),255);
    ellipse(i*100+50,k*100+50,100,100);
    fill(random(255),random(255),255);
    ellipse(i*100+50,k*100+50,100,70);
    fill(255,255,255);
    ellipse(i*100+50,k*100+50,50,70);
  }
}

4. 上課心得

今天的上課內容並沒有很難懂,圖形知道原理後也很好畫,只是要畫好看的圖形要多花一點時間而已~

2012年9月11日 星期二

Week01, HW01


1. Processing 寫出來的作品



2. Processing 練習

size (500,500);
PImage kitty;
kitty=loadImage("http://www.wahouse.com.tw/blog/images/upimages/y1w3e2f8j2j003d8p876.jpg");
image(kitty, 5,50);



3. Processing 畫圖
原圖                        
         









Processing 執行畫面














程式碼:

size(400,350);
background(187,216,255);
/*SUN*/
fill(255,255,0);
ellipse(115, 50, 45, 45);
fill(228,102,37);
triangle(100, 10, 97, 23, 112, 18);
triangle(135, 12, 125, 18, 136, 23);
triangle(142, 32, 148, 45, 155, 32);
triangle(145, 53, 152, 65, 138, 66);
triangle(130, 76, 117, 78, 127, 86);
triangle(92, 75, 105, 78, 93, 86);
triangle(82, 53, 85, 65, 72, 63);
triangle(75, 31, 87, 30, 83, 43);
/*Doll*/
noFill();
ellipse(200 ,130 , 15, 15);//circle
ellipse(200 ,80 , 15, 100);
fill(255,255,255);//body
triangle(198, 200, 225, 320, 130, 300);
fill(255,255,255);//Head
ellipse(200, 185, 120, 95);
fill(0,0,0);
ellipse(170, 185, 10, 10);//eyes
ellipse(230, 190, 10, 10);
noFill();//mouse
beginShape();
curveVertex(155,  200);
curveVertex(155,  200);
curveVertex(195,  220);
curveVertex(235, 210);
curveVertex(235, 210);
endShape();




4.
題 :學了什麼? 有什麼不懂?

今天學到了 Processing 最基本的一些語法
老師還告訴我們一個網站,讓我們可以直接在網路上查詢語法。
剛開始第一堂課,目前都還聽得懂,而且 Processing 的程式語言
感覺還蠻人性化的,所以很好理解:)