顯示具有 00160715黃于洲 標籤的文章。 顯示所有文章
顯示具有 00160715黃于洲 標籤的文章。 顯示所有文章

2014年1月12日 星期日

week19 期末作業:瘋狂吉他手








整個系統工作情況:
左邊的4個按鈕就像吉他左手按玹 ,右手類似播玹,只是我改成按鍵而已。當左手按住某個按鈕時,右手也要跟著按,該鈕顯示的打擊方塊才會亮起,這時只要有韻律方塊也在該位置附近,這樣才能形成有效打擊,Score會加分數,也會有combo顯現。
遊戲執行時,視窗的左邊會有背景影片出現和分數,右邊則是
遊戲進行的畫面,4條通道和1條血條,有有效打擊會有combo出現還會加血,沒有的話漏掉方塊的話則會扣血。血量歸0,遊戲則結束並且有失敗畫面。不然就是等到背景影片播完,即勝利,會有勝利圖片然後計算總分。

心得:
一開始接線的時候,按鈕都沒接電阻,就一直短路,也不知道為啥。接了電阻就好了,不知道是不是因為沒電阻電壓太大,arduino的板子,就直接掛給你看。
然後起初當然是卡在processing如何和arduino做配合~
之後配合processing裡面的函示庫,很多問題都迎刃而解,
不過兩者的配合有一定程度上的lag,這時候就一直在嘗試改arduino的delay()值。
之後又卡在,如何讓方塊跟著音樂有節奏~~
還有方塊與方塊間,避免他們連在一起。
血條用兩張圖片做配合~~沒有意外。
只是悲劇的是processing的版本好像跟學校的不合
影片展示時就顯得很亂~~Q.Q

以下是所使用程式
arduino;


int switchStateRed = 0;
int switchStateBlue = 0;

void setup(){
   pinMode(2 , INPUT);
  pinMode(3, INPUT);
  Serial.begin(9600);
  }

  int a=0,b=0;

  void loop(){
    switchStateRed = digitalRead(2);
   switchStateBlue = digitalRead(3);

  if(switchStateRed == LOW) a=0;
 if(switchStateRed == HIGH && a==0){Serial.write('a');a=1;}
   if(switchStateRed == LOW) b=0;
 if(switchStateRed == HIGH && b==0){Serial.write('b');b=1;}

 
 
  }


processing



import ddf.minim.*;
import processing.video.*; //導入 video 程式庫

import processing.serial.*;


Minim minim;
AudioPlayer in;
Serial serial;
Movie movie; //宣告 Movie 物件
int hand,handX;
PImage rback,lb,blood,bblood,rbb,blue,red,green,yellow,push,bg,die,win;
int score,blo,plo;
int a,i,j,dieo,winn,sum,com;

float []msX=new float[200],msY=new float[200];//x,y
float []msVX=new float[200],msVY=new float[200];
float []bl=new float[200];
int []thing = new int[200];



void setup() {
com=0;

dieo=1;
winn=0;
  size(1300, 600);
score=0;
sum=0;
a=0;
j=0;
blo=0;
plo=565;
   movie = new Movie(this, "aaa.mov");
   minim=new Minim(this);
  rback=loadImage("rback.jpg");
   lb=loadImage("lb.jpg");
    blood=loadImage("blood.jpg");
     rbb=loadImage("rbb.jpg");
      bblood=loadImage("bblood.jpg");
       red=loadImage("red.jpg");
    blue=loadImage("blue.jpg");
     yellow=loadImage("yellow.jpg");
      push=loadImage("yellow.jpg");
      green=loadImage("green.jpg");
      bg=loadImage("bg.jpg");
       die=loadImage("die.jpg");
       win=loadImage("winn.jpg");
  // 開啟 Serial port,通訊速率為 9600 bps

  // 注意! 如果你 Arduino 不是接在 COM4,請做適當調整

  serial = new Serial(this, "COM4", 9600);
   movie.play();
 
   for (int i=0;i<200;i++) {
    newms(i);
    thing[i]=0;
    bl[i]=0;
  }

}
void movieEvent(Movie movie){
//讓 quicktime movie 通知 Processing 有一個畫格已經準備好可以被播放
  movie.read();
/* 由 Movie 類別中呼叫 read() 函數,以便讀入當前畫格資料至 Movie 類別中,準備呈像 */
}


void draw() {

  if(dieo==0)
  {
 
    movie.stop();
   last(0);
   stop();
 
  }

  else if(sum>1500)
  {
     movie.stop();
   last(1);
   stop();
 
  }
  else
  {

  image(lb,0, 0,900,522);
   image(movie, 40, 30);
     image(bblood, 0,522,900, 100);
     image(rbb, 900, 0,405, 605);
    image(rback, 920, 15,360, 570);
    image(blood,1200, 15,72,565 );
     image(bg,1200, 15,72, blo );
    textSize(32);
    text("Score:", 0, 572);
    text(score,100, 572);
    fill(255, 255, 255);
 
    if(com!=0)
    {
    textSize(60);
    text("COMBO", 928, 100);
    text(com,1028, 150);
    fill(0, 255, 0);
    }
 
    handX = 0;
    hand = 0;
   /*
    image(blue, 928, 15,60, 20);
    image(yellow, 996, 15,60, 20);
    image(green, 1064,15,60, 20);
    image(red,1132, 15,60,20 );*/
 
    for ( i=0;i<a;i++) {
    if (msX[i]==928.0)                                                    
      image(blue, msX[i], msY[i], 60, 20);
    else if (msX[i]==996.0)                                              
      image(yellow, msX[i], msY[i], 60, 20);
    else if (msX[i]==1064.0)                                                    
      image(green, msX[i], msY[i], 60, 20);
    else if (msX[i]==1132.0)                                              
      image(red, msX[i], msY[i], 60, 20);
    if(msY[i]<610)
    {
 
    msY[i]+=10;
 
    }
    }

   
   
 
  if ( serial.available() > 0) {

    // 讀取從 Serial Port 傳進來的 Sensor 讀值

    hand = serial.read();
 
 
 
 
 
 
    if(hand=='A'){
  handX = 928;
  image(push, handX, 450.0, 60, 20);


 
   for ( i=0;i<a;i++)       //有效打擊範圍+combo+分數+血量
   {
     if(msY[i]<471 && msY[i]>439)
     {
       if(msX[i]==928)
       {
         if ((461.0 > msY[i]) && (447.0 < msY[i]));
         {
         score=score+100;
        msY[i]=610;
        com=com+1;
         if(plo<=535)
         plo=plo+30;
         }
       }
     }
   
 
   }
  }






   else if(hand=='B'){
    handX=996;
    image(push, handX, 450, 60, 20);
 
   for ( i=0;i<a;i++)
   {
   
     if(msY[i]<471 && msY[i]>439)
     {
       if(msX[i]==996)
       {
         if ((461.0 > msY[i]) && (447.0 < msY[i]));
         {
         score=score+100;
          msY[i]=610;
          com=com+1;
          if(plo<=535)
         plo=plo+30;
         }
       }
     }
   }
  }






   else if(hand=='C'){
  handX = 1064;
  image(push, handX, 450.0, 60, 20);

   for ( i=0;i<a;i++)
   {
   
   
       if(msY[i]<471 && msY[i]>439)
     {
       if(msX[i]==1064)
       {
         if ((461.0 > msY[i]) && (447.0 < msY[i]));
         {
         score=score+100;
          msY[i]=610;
          com=com+1;
          if(plo<=535)
         plo=plo+30;
         }
       }
     }
   }
  }







  else if(hand=='D'){
    handX=1132;
    image(push, handX, 450.0, 60, 20);
 
    for ( i=0;i<a;i++)
    {
      if(msY[i]<471 && msY[i]>439)
     {
       if(msX[i]==1132)
       {
         if ((461.0 > msY[i]) && (447.0 < msY[i]));
         {
         score=score+100;
          msY[i]=610;
          com=com+1;
          if(plo<=535)
         plo=plo+30;
         }
       }
     }
    }
  }
/*
  if(sensorValue0=='Z'){
   sensorValue0=1000;

  }*/





  }

   if(com!=0)                          //combo累計
    {
    textSize(60);
    text("COMBO", 928, 100);
    text(com,1028, 150);
    fill(0, 255, 0);
    }



   for(int u=0;u<a;u++)   //損寫機制+combo歸0+失敗檢測
  {
   if(msY[u] >600 && bl[u]==0 )
   {
     if(blo<570)
     {
   blo=blo+3;
   image(bg,1200, 15,72, blo );
    bl[u]=1;
    com=0;
     }
     else
    dieo=0;
   }
  }



  if(i<200 && j%10==0)

   ++a;
    ++j;

 sum++;
 println(com);

}
}
void newms(int i) {

  //float angle=random(2*PI);
  if(i%3==0 && i<196)         //方塊速度
  {
  msVY[i]=8;
  msVY[i+1]=8;
  msVY[i+2]=8;
  }
  int dir=int(random(4));    //隨機在4個通道產生方塊
  if (dir==0) {
    msX[i]=928.0;
    msY[i]=0.0;
 
 
  }
  else if (dir==1) {
    msX[i]=996.0;
    msY[i]=0.0;
  }
  else if (dir==2) {
    msY[i]=0.0;
    msX[i]=1064.0;
  }
  else if (dir==3) {
    msY[i]=0.0;
    msX[i]=1132.0;
  }
}

void last(int i){                    //失敗畫面和勝利畫面
  if(i==0)
  {
  image(die, 0,0,1200, 600);
   in=minim.loadFile("hdie.mp3");
    in.play();
     textSize(50);
    text("Score:", 100, 422);
    text(score,300, 422);
    fill(255, 255, 255);
  }
  else if(i==1)
  {
 
    image(win, 0,0,1200, 600);
   in=minim.loadFile("hwin.mp3");
    in.play();
     textSize(50);
    text("Score:", 800, 272);
    text(score,980, 272);
    fill(255, 0, 0);
 
  }
}






2013年12月1日 星期日

week13

 lesson 5:
#include <servo .h="">
Servo myServo;

int const potPin = A0;
int potValue;
int angle;



void setup () {
  myServo.attach(9);
  Serial.begin(9600);
}

void loop () {

  potValue = analogRead(potPin);

  Serial.print("Potentiometer Value: ");
  Serial.print(potValue);
// potValue = constrain(potValue,0,1000);
  angle= map(potValue, 0, 1023, 0, 179);

  Serial.print("\t \t Motor Angle: ");
  Serial.println(angle);

  myServo.write(angle);
  delay(5);
}




lesson 6:

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

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

week12

lesson 03:
const int sensorPin = A0;
const float baselineTemp = 25.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); 







  
}


lesson 04:

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);
  int greenValue = map(greenSensorValue,greenSensorLow,greenSensorHigh,0,Brightness);
  greenValue = constrain(greenValue,0,255);
  int blueValue = map(blueSensorValue,blueSensorLow,blueSensorHigh,0,Brightness);
  blueValue = constrain(blueValue,0,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日 星期日

week11

1. 練習第一個範例 File-Examples-Basic-Blink
有規律的亮燈
void setup() {               
  pinMode(11, OUTPUT);
  pinMode(12, OUTPUT);
  pinMode(13, OUTPUT); 
}

void loop() {
  digitalWrite(13, HIGH); 
  delay(2000);
  digitalWrite(13, LOW);

  digitalWrite(12, HIGH);
  delay(200);       
  digitalWrite(12, LOW); 
  delay(100);
  digitalWrite(12, HIGH);
  delay(200);             
  digitalWrite(12, LOW);
  delay(100);
  digitalWrite(12, HIGH); 
  delay(200);             
  digitalWrite(12, LOW); 
  delay(100);
  digitalWrite(12, HIGH);
  delay(200);             
  digitalWrite(12, LOW);

  digitalWrite(11, HIGH);
  delay(1000);
  digitalWrite(11, LOW);
  delay(200);
}

2013年10月27日 星期日

第8週上課


1.
   吃掉小老鼠
   會有壞老鼠出來
2.
   被壞老鼠碰到~就死掉
3.
   小老鼠碰到牆壁會反彈


float [] msX=new float[5], msY=new float[5];
float []msVX=new float[5], msVY=new float[5];
int []scolor=new int[5];

int top=0, catX=mouseX, catY=mouseY, S=100;
PImage ms, cat, badms;
void setup() {
  size(600, 600);
  ms=loadImage("http://scitech.people.com.cn/mediafile/200807/07/F200807070850442343926401.jpg");
  cat=loadImage("http://max218.com/wp-content/uploads/2013/02/%E8%B2%93.jpg");
  badms=loadImage("http://www.icoou.com/uploadfile_20091016/2010/12/28/20101228125512809.jpg");
  for (int i=0;i<5;i++) {
    newms(i);
    scolor[i]=0;
  }
}
int bad=0;
void draw() {

  if (bad==1) {
    background(255, 0, 0);
    for (int i=0;i<5;i++) {
      msVX[i]=0;
      msVY[i]=0;
    }
  }
  else background(0);
  image(cat, mouseX-50, mouseY-50, 100, 100);
  for (int i=0;i<5;i++) {
    if (scolor[i]==0)                                                       // the ms image
      image(ms, msX[i], msY[i], 50, 50);
    else if (scolor[i]==1)                                                 // the ms image to the bad ms image
      image(badms, msX[i], msY[i], 100, 100);
    msX[i]+=msVX[i];
    msY[i]+=msVY[i];
    if (msX[i]<0 || msX[i]>600 ||msY[i]<0 || msY[i]>600)     //change the direction
    {
      if (msX[i]<0)
      {
        msVX[i]=-msVX[i];
      }
      if (msY[i]<0)
      {
        msVY[i]=-msVY[i];
      }
      if (msX[i]>600)
      {
        msVX[i]=-msVX[i];
      }
      if (msY[i]>600)
      {
        msVY[i]=-msVY[i];
      }

      //newms(i); //call new one
    }
    if (dist(msX[i], msY[i], catX-30, catY-30)<S)     //cat eat the ms and ms become badms
    {
      if (scolor[i]==1)
      {
        bad=1;
      }
      else
        scolor[i]=1;      
      newms(i);
      msVX[i]=-msVX[i];
      msVY[i]=-msVY[i];
    }
    //bad=1;
  }
}
void newms(int i) {

  float angle=random(2*PI);
  msVX[i]=cos(angle);
  msVY[i]=sin(angle);
  int dir=int(random(4));
  if (dir==0) {
    msX[i]=random(600);
    msY[i]=0;
  }
  else if (dir==1) {
    msX[i]=random(600);
    msY[i]=600;
  }
  else if (dir==2) {
    msY[i]=random(600);
    msX[i]=0;
  }
  else if (dir==3) {
    msY[i]=random(600);
    msX[i]=600;
  }
}
void mouseMoved() {
  catX=mouseX;
  catY=mouseY;
}

2013年10月20日 星期日

第7週上課內容

1. 請列出你今天三個小時,要完成的事
用prcessing掉垃圾~

2. 你在期中作品要做到什麼程度

可以執行~
3. Why? 你為什麼要做它

如何運用processing做小遊戲


1.
int N=4;
float []thingX= new float[4], thingY= new float[4],thingType= new float[4];
void setup(){
size(400,600);
for(int i=0 ;i<N ;i++){
newThing(i);
}
}

void draw(){
background(255);
for(int i=0;i<N;i++){
  if(thingType[i]==1) drawGood(i);
  else if(thingType[i]==2) drawBad(i);
  else if(thingType[i]==3) drawTrash(i);
  thingY[i]+=4;
  if(thingY[i]>600) newThing(i);
  }
}

void newThing(int i){
 thingY[i]=-random(200);
thingX[i]=random(400);
thingType[i]=int (random(3)+1);
  }
  
  void drawGood(int i){  fill(255,0,0);   ellipse(thingX[i],thingY[i],40,60);  }
  
  void drawBad(int i){  fill(0);   ellipse(thingX[i],thingY[i],40,60); }


  void drawTrash(int i){  fill(#FF6803);  rect(thingX[i],thingY[i],60,60); }


 加入倒數器

  int countDown=10*30;
  void draw() {
  if(countDown>0){
  background(255,0,0);
  countDown--;
  text("Count Down"+countDown/30,100,100);
  return;

  }



加入鍵盤互動

void keyPressed(){
 if(keyCode==UP) ManY-=10; 
  if(keyCode==DOWN) ManY+=10; 
   if(keyCode==RIGHT) ManX+=10; 
    if(keyCode==LEFT) ManX-=10; 
  

}




2013年10月14日 星期一

第六週上課


老鼠碰到貓會跑回去~~

float [] msX=new float[10], msY=new float[10];
float []msVX=new float[10], msVY=new float[10];
int top=0,catX=300,catY=300,S=100;
PImage ms,cat;
void setup() {
  size(600, 600);
  ms=loadImage("http://scitech.people.com.cn/mediafile/200807/07/F200807070850442343926401.jpg");
  cat=loadImage("1.jpeg");
  for (int i=0;i<10;i++) {
    newms(i);
  }
}
int bad=0;
void draw() {

if(bad==1){
  background(255,0,0);
  for(int i=0;i<10;i++){msVX[i]=0;msVY[i]=0;}
  }
  else background(0);
   image(cat,mouseX-50,mouseY-50,100,100);
  for (int i=0;i<10;i++) {
    image(ms, msX[i], msY[i], 50, 50);
    msX[i]+=msVX[i];
      msY[i]+=msVY[i];
      if(msX[i]<0 || msX[i]>600 ||msY[i]<0 || msY[i]>600) newms(i);
      if(dist(msX[i],msY[i],catX-30,catY-30)<S)                                    //老鼠碰到貓會跑回去~~
      {msVX[i]=-msVX[i];
     msVY[i]=-msVY[i];}
      //bad=1;  
  }
  }
  void newms(int i) {
    float angle=random(2*PI);
    msVX[i]=cos(angle);
    msVY[i]=sin(angle);
    int dir=int(random(4));
      if(dir==0){msX[i]=random(600);msY[i]=0;}
   else if(dir==1){msX[i]=random(600);msY[i]=600;}
    else if(dir==2){msY[i]=random(600);msX[i]=0;}
     else if(dir==3){msY[i]=random(600);msX[i]=600;}
  }
void mouseMoved(){
catX=mouseX;
catY=mouseY;

}

殭屍遊戲


int []sequence = new int[1000];
PImage imgZombie;
void setup(){
 size(300,500);
imgZombie=loadImage("go.png");
for(int i=0; i<1000; i++){
 sequence[i] = int(random(3));
}

}
int nov=0;
void draw(){
 background(0);
for(int i=nov;i<nov+5;i++){
 image(imgZombie,sequence[i]*100,400-(i-nov)*100);
}
}
void keyPressed(){
 if(key==sequence[nov]+'0') nov++;
else {}
}



按鍵加音效


import ddf.minim.*;
Minim m;
AudioPlayer player;
AudioPlayer [] tone = new AudioPlayer[2];

void setup(){
 m=new Minim(this);
player = m.loadFile("2.mp3");

tone[0]=m.loadFile("1.mp3");
tone[1]=m.loadFile("2.mp3");
 
}
void draw(){
  }
void keyPressed(){
 if(key=='1') {tone[0].rewind(); tone[0].play();}
if(key=='2') {tone[1].rewind(); tone[1].play();}
}

2013年10月6日 星期日

第5週課堂

1.

size(640,480);

translate(300,200);

rotate(PI/3*1);

ellipse(0,0,20,100);

rotate(PI/3*1);

ellipse(0,0,20,100);

rotate(PI/3*1);

ellipse(0,0,20,100);


2.

void setup() {
  size(640, 480);
}

void draw() {
  translate(300, 200);

  for (int i=0;i<10;i++) {

    rotate(PI/10*1);

    ellipse(0, 0, 30, 200);
  }
}


3.

void setup() {
  size(640, 480);
  colorMode(HSB,480);
}
int flowerBan=5;
void draw() {
  translate(mouseX, mouseY);
fill(mouseX,mouseY,480);
  for (int i=0;i<flowerBan;i++) {

    rotate(PI/flowerBan);

    ellipse(0, 0, 30, 100);
  }
}
void mouseClicked(){
 flowerBan++;
}


4.

void setup() {
  size(640, 480);
  colorMode(HSB,480);  //多顏色
}
float angle = 0;    //旋轉
int flowerBan=5;
void draw() {
  background(#B9B8B8);    //過去的痕跡消除
  angle+=0.004;         //旋轉
  translate(mouseX, mouseY);//花跟著滑鼠走
  rotate(angle);          //旋轉
fill(mouseX,mouseY,480);
  for (int i=0;i<flowerBan;i++) {

    rotate(PI/flowerBan);

    ellipse(0, 0, 30, 100);
  }
fill(mouseX,mouseY,240);
  for (int i=0;i<flowerBan;i++) {

    rotate(PI/flowerBan);
    ellipse(0,0,30,30);
  }
}
void mouseClicked(){  //點擊讓花瓣數增加
 flowerBan++;
}



5.點擊增加花朵 , 花朵會墮落

int[] X=new int[100];
int[] Y=new int[100];
int N=0;
void setup(){
 size(640,480);
   colorMode(HSB,480);
}

float angle = 0;    //旋轉


void draw() {
  background(#B9B8B8);  
  angle+=0.04;        
 for(int i=0;i<N;i++) myFlower(X[i],Y[i]++);
  myFlower(mouseX,mouseY);
 
}
void myFlower(int x,int y){
  pushMatrix();
  translate(x, y);
  rotate(angle);        
fill(x,y,480);
  for (int i=0;i<8;i++) {

    rotate(PI/8);

    ellipse(0, 0, 30, 100);
  }
fill(#FCF33B);
  for (int i=0;i<8;i++) {

    rotate(PI/8);
    ellipse(0,0,30,30);
  }
  popMatrix();
}
void mousePressed(){
X[N]=mouseX;
  Y[N]=mouseY;
 N++;
 if(N>=100) N=0;
 
}
void mouseClicked(){

}





今天心得 : 會動的花
期末作業 : 想做類似小鱷魚互動的益智遊戲或是做會跟人互動的圖畫 ,
                   原本靜止的圖畫~或是有些許動作的圖畫 , 點擊之後 , 會產生新的動作
                   點擊圖畫的花 , 他會動 , 典籍圖畫中的狗 , 他會突然跑掉之類的  

2013年9月29日 星期日

第4週

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

}

void draw(){

}

void mouseDragged(){
 line(mouseX,mouseY,pmouseX,pmouseY);
stroke(100,155,255);
}

pmouseX   前一個
stroke( )        筆觸顏色


void setup( )  {  size(400,400);  background(255);   }
void draw(){
  fill(255,0,0);
  rect(0,0,100,100);
  fill(0,255,0);
  rect(0,100,100,100);
}
void mouseDragged(){
 line(mouseX,mouseY,pmouseX,pmouseY);  }

  void mouseClicked(){
  if(mouseX<100  &&  mouseY<100)  stroke(255,0,0);
 else if(mouseX<100  &&  mouseY<200)  stroke(0,255,0);
 }
void mousePressed(){}
void mouseReleased(){}


mouseClicked() 點一下


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);
    }
  }
}
void draw() {
}
void mouseDragged() {
  line(mouseX, mouseY, pmouseX, pmouseY);
  //strokeWeight(10);
}
void mousePressed() {
}
void mouseReleased() {
  if (mouseX<100  &&  mouseY<100)  stroke(mouseX, mouseY, 100);
}



void setup( ) {
  size(400, 400);
  background(255);
  noStroke();
  colorMode(RGB,255);
  fill(143,245,232);
  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);
  //strokeWeight(10);
}
void mousePressed() {
}
void mouseReleased() {
  if (mouseX<100  &&  mouseY<100)
  {
    colorMode(HSB,100);
  stroke(mouseX, mouseY, 100);
  }
  else if(mouseX<100 && mouseY<200){
  stroke(#8FF5E8);
  }
}

 colorMode(HSB, 100);
 stroke(#8FF5E8);


void setup( ) {  
  size(500, 500);  
  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() {
 if(mouseX > 100 && mouseX<390) line(mouseX, mouseY, pmouseX, pmouseY); 
  //strokeWeight(10);
}
void mousePressed() {
    if (mouseX<100  &&  mouseY<100)  
  {
    colorMode(HSB,100);
  stroke(mouseX, mouseY, 100);
  }
  else if(mouseX<100 && mouseY<200){
  stroke(#8FF5E8);
  }
}







課堂作業: (1) 做出你的小畫家,做得越好,分數越高 (老師沒有教到的功能你去找出來,分數更高)


void setup( ) {  
  size(500, 500);  
  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);
  

  strokeWeight(0);
  fill(255);
  rect(400,100,100,100);
  strokeWeight(10);
  stroke(#000000);
  point(450,150);
}
void draw(){}
void mouseDragged() {
 if(mouseX > 100 && mouseX<390) line(mouseX, mouseY, pmouseX, pmouseY); 
  //strokeWeight(10);
}
void mousePressed() {
    if (mouseX<100  &&  mouseY<100)  
  {
    colorMode(HSB,100);
  stroke(mouseX, mouseY, 100);
  }
  else if(mouseX<100 && mouseY<200){
  stroke(#8FF5E8);
  }
  
  if(mouseX>400 && mouseY<100)
  {
   strokeWeight(30); 
  }
  else if(mouseX >400 && mouseY<200)
  {
   strokeWeight(10); 
  }
}



課堂作業: (2) 目前的心得,請分享 (不要講太難)

還ok阿~




2013年9月22日 星期日

第3週

1. 今天目標: 畫出一個五子棋
1.1. 使用 Tool- Color Selector, 挑出你要的顏色, 可用 R,G,B 來描述,也可用 #0B33FF 之類的數字來用





1.2. 要畫外框,可以用 rect()來畫, 要修改填充的顏色可以用fill(), 要讓畫的內部不要填充, 可以查看 Help-Reference 後,在 fill()樓上樓下相關的地方找到你要的功能 (ex. noFill() )
1.3. 使用 stroke() 來調畫線stroke的顏色, 在 Help-Reference 裡面可以找 stroke 相關的功能,像是比較粗的 stroke 可以用 strokeWeight() 來設定權重粗細


1.4. 想要畫裡面的細黑線,可以用 line() 來畫,配上不同的 strokeWeight() 粗細





int nowX, nowY;
int[][] array=new int[8][8];
void setup()
{  size(800, 800);   }

void draw() {
  background(232, 191, 101);
  noFill();
  strokeWeight(6);
  rect(50, 50, 700, 700);
  strokeWeight(1);
  for (int i=0;i<8;i++) {
    line(50, 50+i*87, 750, 50+i*87);
    line(50+i*87, 50, 50+i*87, 750);
  }
  fill(255, 0, 0);
  rect(nowX*87+50, nowY*87+50, 87, 87);
  fill(0);
  for (int i=0;i<8;i++) {
    for (int j=0;j<8;j++) {
      if (array[i][j]==1)  rect(i*87+50, j*87+50, 87, 87);
    } } }
    
void mousePressed() 
{  array[nowX][nowY]=1;  }

void mouseMoved() {
  nowX = (mouseX-90)/80;
  nowY = (mouseY-90)/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(232, 191, 101);
  noFill();
  strokeWeight(6);
  rect(50, 50, 700, 700);
  strokeWeight(1);
  for (int i=0;i<8;i++) {
    line(50, 50+i*87, 750, 50+i*87);
    line(50+i*87, 50, 50+i*87, 750);
  }
  fill(255, 0, 0);
  ellipse(nowX*87+50, nowY*87+50, 87, 87);                  //ellipse
  fill(0);
  for (int i=0;i<8;i++) {
    for (int j=0;j<8;j++) {
      if (array[i][j]==1)  ellipse(i*87+50, j*87+50, 87, 87);       //ellipse
    } } }
    
void mousePressed() 
{  array[nowX][nowY]=1;  }

void mouseMoved() {
  nowX = (mouseX-50)/80;
  nowY = (mouseY-50)/80;
  println(" mouseX: "+mouseX+" mouseY: "+ mouseY+" nowX: "+nowX+" nowY:"+nowY);
}







貼你覺得有意思的影片, 使用youtube 的分享, Blogger 分享, 兩邊都改成 HTML, 貼上 HTML