顯示具有 00160423鄭羽婷 標籤的文章。 顯示所有文章
顯示具有 00160423鄭羽婷 標籤的文章。 顯示所有文章

2014年1月12日 星期日

期末作品 神奇小筆

神奇小筆

三種顏色的筆
紅色鋪路,藍色檔烏龜,綠色擋香菇
60秒會碰到公主及過關







<arduino>

int switchStateRed = 0;
int switchStateBlue = 0;
int switchStateGreen = 0;


void setup(){
  pinMode(2,INPUT);
  pinMode(3,INPUT);
  pinMode(4,INPUT);

  Serial.begin(9600);
}

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

  if(switchStateRed == HIGH) {
    //Serial.write(3);
    Serial.print(3);
  }
  if(switchStateGreen == HIGH) {
    //Serial.write(2);
    Serial.print(2);
  }
  if(switchStateBlue== HIGH) {
    //Serial.write(1);
    Serial.print(1);
  }

  delay(100);
}

<processing>


import processing.serial.*;
Serial serial;

import ddf.minim.*;
Minim minim;
AudioPlayer star;

PImage imgBG, imgGreen, imgBlue, imgRed, cloudA, cloudB;
PImage man, man1, man2, man3, man4, wife;
PImage mon1, mon2, winImage,paint;
int index;
boolean Game=false;
int wifeX=640, wifeY=250;
boolean wifeF=false;
int cloudX[]= {
  640, 800, 900, 1000
};
int cloudY[]= {
  100, 150, 80, 75
};
int cloudType[]= {
  1, 2, 1, 1
};

int[] I = {
  -1282, -1281, -1280, -1279, -1278, 
  -642, -641, -640, -639, -638, 
  -2, -1, 0, 1, 2, 
  638, 639, 640, 641, 642, 
  1279, 1278, 1280, 1281, 1282
};

int[] I2 = {
  -1279, -1278, -1277, -1276, -1275, 
  -639, -638, -637, -636, -635, 
  1, 2, 3, 4, 5, 
  641, 642, 643, 644, 645, 
  1281, 1282, 1283, 1284, 1285
};

int hole=100;
int HTime=300;

void setup() {
  serial=new Serial(this, "COM3", 9600);
  minim = new Minim(this);
  star=minim.loadFile("Mario.mp3");
  music();
  size(640, 480);
  man=loadImage("man.png");
  man1=loadImage("man1.png");
  man2=loadImage("man2.png");
  man3=loadImage("man3.png");
  man4=loadImage("man4.png");
  mon1=loadImage("air.png");
  mon2=loadImage("mon.png");  
  winImage=loadImage("win.jpg");
  wife=loadImage("wife.png");
  cloudA=loadImage("cloud.png");
  cloudB=loadImage("cloudB.png");
  paint=loadImage("pen.png");
  imgBG=createImage(640, 480, RGB);
  imgGreen=createImage(640, 480, RGB);
  imgRed=createImage(640, 480, RGB);
  imgBlue=createImage(640, 480, RGB);

  clBK();
  clPen(imgGreen);
  clPen(imgRed);
  clPen(imgBlue);

  road();
}
int mon1X[]= {
  640, 800
};
int mon1Y[]= {
  210, 250
};
int manX=200, manY=250;
int mon2Y=-100;

int S=0, S2=0;
int Color=0;
boolean death=false;
int dlong=80;//if or not fall
int s, read;
boolean win=false;
boolean lossmousic=false;

void draw() {
  noCursor();
  background(imgBG);
  clBK();

  if (serial.available()>0)
  {
    read=serial.read();
    println(read);
    if (read==49)Color=0;
    if (read==50)Color=1;
    if (read==51)Color=2;
  }

  bkDraw();

  if (Game) {
    if (s==0)s=60;
    int s2 = second();
    if (s-1==s2)wifeF=true;
    if (wifeF) {
      image(wife, wifeX, wifeY, 100, 100);
      wifeX--;
      if (wifeX-manX<50) {
        win=true;
        Game=false;
      }
    }
    for (int i=0;i<4;i++) {
      if (cloudType[i]%2==0)image(cloudA, cloudX[i], cloudY[i], 100, 50);
      else image(cloudB, cloudX[i], cloudY[i], 100, 50);
      cloudX[i]--;
      if (cloudX[i]<0)newcloud(i);
    }

    runman();

    for (int i=0;i<2;i++) {
      image(mon1, mon1X[i], mon1Y[i], 100, 100);
      int I=(mon1Y[i]-1)*640+mon1X[i]-1;
      imgBlue.loadPixels();
      for (int j=0;j<100;j++) {
        if (imgBlue.pixels[I]==color(#1B16D6)) {
          mon1X[i]=640+(int)random(5)*50;
          mon1Y[i]=200+(int)random(100);
          clPen(imgBlue);
          break;
        }
        I+=640;
      }
      imgBlue.updatePixels();
      if (dist(manX, manY, mon1X[i], mon1Y[i])<=95) {
        Game=false;
        death=true;
        lossmousic=true;
      }
      mon1X[i]-=3;
    } //tortoise

    image(mon2, 200, mon2Y, 100, 100);
    int J=(mon2Y+100-1)*640+200-1;
    imgGreen.loadPixels();
    for (int j=0;j<100;j++) {
      if (J<0)break;
      if (imgGreen.pixels[J]==color(#297111)) {
        mon2Y=-(int)random(100)-100;
        clPen(imgGreen);
        break;
      }
      J++;
    }

    imgGreen.updatePixels();
    if (dist(manX, manY, 200, mon2Y)<=95) {
      Game=false;
      death=true;
      lossmousic=true;
    }
    mon2Y++;//mushroom

    back();
    boolean fall=true;
    imgRed.loadPixels();
    for (int i=24;i>=0;i--) {
      if (imgRed.pixels[223659+I2[i]]==color(#FF0000)) {
        manY=(223659+I2[i])/640-100;
        fall=false;
        dlong=80;
      }
    }
    if (fall) {
      dlong--;
      if (dlong==0) {
        manY=400;
        Game=false;
        death=true;
        lossmousic=true;
      }
    }


    imgRed.updatePixels();



    if (Color==0)pen(imgBlue, color(#1B16D6));
    else if (Color==1)pen(imgGreen, color(#297111));  
    else pen(imgRed, color(#FF0000));
  }
  else {
    if (win) {
      image(winImage, 0, 0, 640, 480);
    }
    else {
      s = second();
      if (death) {
        image(man4, manX, manY, 100, 100);
        if (lossmousic) {
          star.close(); 
          star=minim.loadFile("loss.mp3");
          music();
        }
      }
      else image(man, manX, manY, 100, 100);
      lossmousic=false;
    }
  }
  
  image(paint,mouseX-10,mouseY-80,100,100);
}

void runman() {
  if (S%20==0)S2++;
  if (S2%3==0)image(man1, manX, manY, 100, 100);
  else if (S2%3==1)image(man3, manX, manY, 100, 100);
  else image(man2, manX, manY, 100, 100);
  S++;//run
}

void mouseClicked() {
  Game=true;
}

void newcloud(int i) {
  cloudX[i]=640+(int)random(100);
  cloudY[i]=(int)random(100);
  cloudType[i]=(int)random(10);
}


void road() {
  imgRed.loadPixels();
  int RI=350*640;
  for (int i=350*640;i<640*480;i++) {
    if (i<352*640)imgRed.pixels[i]=color(#FF0000);
    else imgRed.pixels[i]=color(#AA5D1D);
  }

  imgRed.updatePixels();
}

void back() {
  if (HTime==0) {
    hole=((int)random(2)+1)*100;
    HTime=((int)random(3)+2)*60;
  }
  if (hole<=0) {
    HTime--;
  }
  imgRed.loadPixels();
  for (int i = 1;i<imgRed.pixels.length-1;i++) {
    if ((i+1)%640==0) {
      imgRed.pixels[i]=color(#000000);
      if (i>=224639&&(i-224639)%640==0) {
        if (hole<0) {
          if (i==224639||i==225279)imgRed.pixels[i]=color(#FF0000);
          else imgRed.pixels[i]=color(#AA5D1D);
        }
      }
      continue;
    }
    imgRed.pixels[i]=imgRed.pixels[i+1];
  }
  hole--;
  imgRed.updatePixels();
}

void bkDraw() {
  imgBG.loadPixels();
  imgRed.loadPixels();
  imgBlue.loadPixels();
  imgGreen.loadPixels();
  for (int i = 1;i<imgRed.pixels.length-1;i++) {
    if (imgRed.pixels[i]!=color(#000000))
      imgBG.pixels[i]=imgRed.pixels[i];
    if (imgBlue.pixels[i]!=color(#000000))
      imgBG.pixels[i]=imgBlue.pixels[i];
    if (imgGreen.pixels[i]!=color(#000000))
      imgBG.pixels[i]=imgGreen.pixels[i];
  }
  imgBG.updatePixels();
  imgRed.updatePixels();
  imgBlue.updatePixels();
  imgGreen.updatePixels();
}

void clBK() {
  imgBG.loadPixels();
  for (int i = 0;i<imgBG.pixels.length;i++) {
    imgBG.pixels[i]=color(#18DBEA);
  }
  imgBG.updatePixels();
}
void clPen(PImage img) {
  img.loadPixels();
  for (int i = 0;i<imgBG.pixels.length;i++) {
    img.pixels[i]=color(#000000);
  }
  img.updatePixels();
}

void pen(PImage img, color c) {
  index=(mouseY-1)*640+mouseX-1;
  img.loadPixels();
  int I2;
  for (int i=0;i<25;i++) {
    I2=index+I[i];
    if (mouseX>=638||mouseY<=2||mouseX<=2||mouseY>=478)break;
    img.pixels[I2]=c;
  }
  img.updatePixels();
}
void music() {
  star.loop();
}
void stop() {
  star.close();
  minim.stop();
  super.stop();
}



2013年12月8日 星期日

第十四週

期末企劃:
電腦版的包飯糰遊戲只能用滑鼠玩,我們做成可以手動版的包飯糰遊戲,
遊戲中可以手動按按鈕加各種料,最後再用幾個按鈕模擬捏飯糰的動作。
在時間內包越多飯糰越高分,速度越快分數也越高。



類似的遊戲:





2013年12月1日 星期日

WEEK13 課堂作業


(CH05) 馬達轉轉

#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.println(angle); myServo.write(angle); myServo.write(angle); delay(15); }


(CH06) 用光發出聲音


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





(CH07) 按鈕聲音


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>=800 && keyVal<=1021){
    tone(8,notes[1]);
  }
  else if(keyVal>=400&& keyVal<=515){
    tone(8,notes[2]);
  }
  else if(keyVal==641){
    tone(8,notes[3]);
  }
  else {
    noTone(8);
  }
}



2013年11月24日 星期日

Week12 鄭羽婷

<HW1 依照溫度亮燈>


const int sensorPin=A0;
const float baselineTemp=22.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(", degree 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);

}


<HW2 LED顏色變換>


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); Serial.print("Raw Sensor Values \t Red: "); Serial.print(redSensorValue); Serial.print("\t Green: "); Serial.print(greenSensorValue); Serial.print("\t Blue: "); Serial.println(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.println(blueValue); analogWrite(redLEDPin, redValue); analogWrite(greenLEDPin, greenValue); analogWrite(blueLEDPin, blueValue); }


2013年11月17日 星期日

week11 鄭羽婷

第一個 Arduino 作品
概念,紅綠燈
綠燈->閃黃燈(連續閃)->紅燈

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年11月10日 星期日

week10 鄭羽婷示範, 期中作品展示

1. 把大家的期中作品準備好, 要在老師的電腦跑展示(廣播並票選)
2. 今天要上傳影片 (自己錄好,上傳youtube, 留下連結) (仿上學期電腦圖學課的期末作品)

=====
3. 發 Arduino Starter Kit (包含各式電子零件,及Arduino UNO板) 及 Arduino Mega 2560板

介紹:
轉珠遊戲!!贏書有兩種結果!!結束後會自動跳回起始畫面!!
不過因為玩的人有點爛!!所以它分成了兩部影片!!哈哈




import ddf.minim.*;
Minim minim;
AudioPlayer star;
int a=1;

int Xmax=7, Ymax=5;
int c[][]=new int [Xmax][Ymax];//chose color index
int Color[]=new int [5];//Chose color
int test=1, t;//read mouse event in first time
int X=-1, Y=-1;//=-1 loop unMousePressed don't do that
int Cx, Cy;//change ball X &Y value
int TC;//record move ball color

int N[][]=new int [Xmax][Ymax];
boolean clear=false;
int n;
boolean MoveBall=true;

int sum[]=new int [5];
boolean attack=false;
boolean Ustop=true;
int Blood=360, MBlood=360;

PImage background, ATTACK, win, lose, P1, P2, P3, P4, P5;
PImage play1, play2;

void setup() {
  minim = new Minim(this);

  background= loadImage("0.jpg");
  ATTACK=loadImage("attack.jpg");
  win=loadImage("win.jpg");
  lose=loadImage("lose.jpg");
  P1=loadImage("a.jpg");
  P2=loadImage("b.jpg");
  P3=loadImage("c.jpg");
  P4=loadImage("d.jpg");
  P5=loadImage("e.jpg");
  play1=loadImage("play.png");
  play2=loadImage("play2.png");
  size(400, 600);
  Color[0]=#E51E1E;
  Color[1]=#201EE5;
  Color[2]=#F6FF00;
  Color[3]=#03FF00;
  Color[4]=#5D1E9D;
  for (int i=0;i<Xmax;i++) {
    for (int j=0;j<Ymax;j++) {
      c[i][j]=(int)random(5);
    }
  }
}

int AT=8;
boolean Win=false;
boolean Loss=false;
boolean stage=false;

int Time=20;

void draw() {

  if (stage) {
    if (Win||Loss) {
      if (Win){image(win, 0, 0);}
      else {image(lose, 0, 0);}
   
      if(a==3){star.close();star=minim.loadFile("c.mp3");music();}
      if(a==4){star.close();star=minim.loadFile("d.mp3");music();}
      a=1;
      if (Time<0) {
        star.close();
        Time=10;
        AT=8;
        Win=false;
        Loss=false;
        stage=false;

        for (int i=0;i<Xmax;i++) {
          for (int j=0;j<Ymax;j++) {
            c[i][j]=(int)random(5);
          }
        }

        Blood=360;
        MBlood=360;
        clear=false;
        MoveBall=true;
        attack=false;
        Ustop=true;
      }
      Time--;
    }

    else {
      if(a==2){star.close();star=minim.loadFile("b.mp3");music();}
      a=3;
      image(background, 0, 0);
      image(P1, 5, 210);
      image(P2, 85, 210);
      image(P3, 165, 210);
      image(P4, 245, 210);
      image(P5, 325, 210);

      stroke(0);
      drawBall();


      strokeCap(ROUND);
      if (attack) {

        if (AT>6) {
          noFill();
          for (int i=0;i<5;i++) {
            stroke(Color[i]);
            strokeWeight(10);
            if (sum[i]!=0)
              bezier(150+i*20, 80, i*80+20, 25, i*80+20, 100, i*80+40, 200);
          }
        }

        else {
          if (AT>4) {
            for (int i=0;i<5;i++) {
              Blood-=sum[i]*2;
              sum[i]=0;
            }

            if (Blood<0) {
              Blood=0;
              Win=true;
            }
          }
          else {
            if (AT>2) {
              image(ATTACK, 50, 5);
            }
            else if (AT>1) {
              MBlood-=(random(20)+40);
              if (MBlood<0) {
                MBlood=0;
                Loss=true;
                a=4;
              }
            }
          }
        }
        AT--;
        if (AT<=0) {
          attack=false;
        }
      }
      strokeWeight(12);
      stroke(#C10A0A);
      strokeCap(PROJECT);
      line(20, 10, 20+Blood, 10);
      line(20, 320, 20+MBlood, 320);

      strokeWeight(5);
      stroke(#52091A);
      fill(#F041B6);
      ellipse(20, 10, 25, 25);
      ellipse(20, 320, 25, 25);


      stroke(0);
      if (Ustop) {
        if (MoveBall==true&&attack==false) {
          frameRate(20);
          if (mousePressed==true) {
            fill(Color[TC]);
            ellipse(mouseX, mouseY, 40, 40);
            Cx=mouseX/10*10/50-1;
            Cy=(mouseY-300)/10*10/50-1;
            if (mouseX%50>=25&&mouseX%50<50)Cx+=1;
            if ((mouseY-300)%50>=25&&(mouseY-300)%50<50)Cy+=1;
            if (mouseX>350)Cx=6;//range
            if (mouseY>550)Cy=4;
            if (mouseX<50)Cx=0;
            if (mouseY<350)Cy=0;
            if (Cx!=X||Cy!=Y) {//not the same region
              c[X][Y]=c[Cx][Cy];
              X=Cx;
              Y=Cy;
            }
          }
        }
        else {
          frameRate(3);
          if (n%3==0)score();
          else if (n%3==1)fallBall();
          else {
            addBall();
            Ustop=false;
          }
          n++;
          test();
        }
      }
      else {
        score();
        Ustop=true;
        test();
        if (MoveBall)attack=true;
      }
    }
  }

  else {
    background(#13D5E5);
    image(play1, 150, 150);
    image(play2, 150, 280);
    if (mousePressed==true) {
      if (abs(mouseX-200)<100&&abs(mouseY-300)<100)
        stage=true;
    }

      if(a==1){star=minim.loadFile("a.mp3");music();}
      a=2;
  }
}

void music(){
  star.loop();

}

void stop() {
  star.close();
  minim.stop();
  super.stop();
}

void mousePressed() {
  if (t==0) {
    X=mouseX/10*10/50-1;
    Y=(mouseY-300)/10*10/50-1;
    if (mouseX%50>=25&&mouseX%50<50)X+=1;
    if ((mouseY-300)%50>=25&&(mouseY-300)%50<50)Y+=1;
    if (mouseX>350)X=6;//range
    if (mouseY>550)Y=4;
    if (mouseX<50)X=0;
    if (mouseY<350)Y=0;
    TC=c[X][Y];
  }
  t=test;//read mosue event on first time
  AT=8;
}
void mouseReleased() {
  c[X][Y]=TC;
  X=-1;
  Y=-1;
  t=0;
  n=0;
  MoveBall=false;
}

void test() {
  MoveBall=true;
  for (int i=0;i<Xmax;i++) {
    for (int j=0;j<Ymax;j++) {
      if (N[i][j]!=0)MoveBall=false;
    }
  }
}

void drawBall() {

  for (int i=0;i<Xmax;i++) {
    for (int j=0;j<Ymax;j++) {
      if (i==X&&j==Y)continue;//mousePressed do
      if (N[i][j]!=0)continue;
      fill(Color[c[i][j]]);
      ellipse((i+1)*50, (j+1)*50+300, 40, 40);
    }
  }
}

void addBall() {
  for (int i=0;i<Xmax;i++) {
    for (int j=0;j<Ymax;j++) {
      if (N[i][j]==6) {
        c[i][j]=(int)random(5);
        N[i][j]=0;
      }
    }
  }
}

void fallBall() {
  for (int i=0;i<Xmax;i++) {
    for (int j=0;j<Ymax;j++) {
      if (N[i][j]!=0) {
        for (int k=j;k>0;k--) {
          c[i][k]=c[i][k-1];
          N[i][k]=N[i][k-1];
        }
        N[i][0]=6;
      }
    }
  }
}

void score() {
  int count=0, count2=0;

  for (int i=0;i<Xmax;i++) {
    for (int j=0;j<Ymax;j++) {

      for (int k=i+1;k<Xmax;k++) {
        if (c[i][j]==c[k][j])count++;
        else break;
      }

      for (int k=j+1;k<Ymax;k++) {
        if (c[i][j]==c[i][k])count2++;
        else break;
      }

      if (count>1) {
        for (int k=i;k<=i+count;k++) {
          N[k][j]=c[i][j]+1;
          sum[c[i][j]]++;
        }
      }

      if (count2>1) {    
        for (int k=j;k<=j+count2;k++) {
          N[i][k]=c[i][j]+1;
          sum[c[i][j]]++;
        }
      }
      count=0;
      count2=0;
    }
  }
}

2013年10月20日 星期日

Week07 鄭羽婷

我們這組要寫接金幣

1. 這禮拜要寫出下雨
2. 寫出接金幣有分數金幣掉到地上會消失
3. 因為這是國民遊戲

int max=10;
float [] rainX=new float [max];
float [] rainY=new float [max];

void setup() {
  size(200, 200);
  for(int i=0;i<10;i++){
    rainX[i]=random(200);        
  }
}

void draw() {
  background(0);
  stroke(#FCE321);
  strokeCap(ROUND);
  strokeWeight(3);
  for(int i=0;i<10;i++){
    rainX[i]-=1.0;
    rainY[i]+=1.0;  
    diagonals(rainX[i],rainY[i]);
    if(rainX[i]+20<0){
      rainX[i]=random(400);
      rainY[i]=0;    
    }
  }
}

void diagonals(float x, float y) {
  line(x, y, x+20, y-20);
}

2013年10月14日 星期一

Week06 鄭羽婷

(類似打地鼠有BUG)
int  [] a=new int [3];
int count=0;
void setup(){
  frameRate(1);
  size(300,300);
  background(0);
  stroke(#BF2828);
  strokeWeight(4);
  for(int i=100;i<300;i+=100){
    line(0,i,300,i);
    line(i,0,i,300);
  }
  a[0]=50;
  a[1]=150;
  a[2]=250;

}
void draw(){
  background(0);
  stroke(#BF2828);
  strokeWeight(4);
  for(int i=100;i<300;i+=100){
    line(0,i,300,i);
    line(i,0,i,300);
  }
  int X=a[(int)random(3)];
  int Y=a[(int)random(3)];
  ellipse(X, Y, 50, 50);
}
void mouseClicked(){
  if(mouseX<X+50&&mouseX>X-50&&mouseY<Y+50&&mouseY>Y-50){
        count++;
   }
   //println(X);
}

(音樂撥放)
按方塊播放 圓形停止


import ddf.minim.*;
Minim minim;
AudioPlayer song;
void setup() {
  size(300,300);
  minim = new Minim(this);
  song = minim.loadFile("JINX.mp3");
}
void draw() {
  background(0);
  rect(10,10,100,100);
  ellipse(150,150,100,100);
}
void mousePressed(){
  if(star()){song = minim.loadFile("JINX.mp3"); song.play();}
  if(Stop())song.close();
 
}

boolean star(){
  if(mouseX>=10 && mouseX<=110 &&
     mouseY>=10 && mouseY<=110)return true;
  else return false;

}
boolean Stop(){

  if (sqrt(sq(mouseX) + sq(mouseY)) > 100) {
    return true;
  } else {
    return false;
  }
 
}

void stop() {
  song.close();
  minim.stop();
  super.stop();
}//release memory space

2013年10月7日 星期一

Week05 鄭羽婷

float angle=0.01;
boolean a=false,b=false;
int X,Y;

void setup(){
  background(#F6F7DC);
  size(640,480);
}

void flower(){
  for(int i=0;i<20;i++){
      fill(X+i*3,Y+i*3,255);
      ellipse(0,50,20,100);
      rotate(PI/10*1);
  }
  fill(#F6FF00);
  ellipse(0,0,30,30);
}

void draw(){
  background(#F6F7DC);
  translate(X,Y);
  if(b){
    //if(mouseX>X)angle+=0.01;
    //else angle-=0.01;
    float delta=(mouseX-pmouseX)/30.0;
    angle += delta;
    rotate(angle);
  }
  if(a)flower();
}

void mouseClicked(){
  X=mouseX;
  Y=mouseY;
  a=true;
  b=false;
}

void mouseMoved() {
  b=true;
}


//期中

接金幣遊戲

2013年9月29日 星期日

Week04 鄭羽婷

Week04-1

void setup(){
  size(500,500);
  background(255);
  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(){
   line(pmouseX, pmouseY, mouseX,mouseY);
}
void mouseClicked(){
  if(mouseX<100 && mouseY<100){
    stroke(mouseX,mouseY,100);
    point(450,50);
  }
}

//加入印章功能
PImage img;
int a=0;
void setup(){
  size(500,500);
  background(255);
  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);

  img=loadImage("1.jpg");

  
}
void draw(){   
   image(img,0,100,100,100);
}
void mouseDragged(){
   if(a==0)line(pmouseX, pmouseY, mouseX,mouseY);
}
void mouseClicked(){
  
  if(mouseX<100 && mouseY<100){
    a=0;
    stroke(mouseX,mouseY,100); 
    point(450,50);  
  }
  else {
    if(a==1)image(img,mouseX-50,mouseY-50,100,100);
    else if(mouseX<100 && mouseY<200){
    a=1;
    }
  }
}  

心得

Processing 做 3D Game 應該會很有趣 

2013年9月22日 星期日

Week03 鄭羽婷

Week03-1

void setup(){
  size(800,800);
}
void draw(){
  background(#F2E490);
  noFill();
  strokeWeight(6);
  rect(50,50,700,700);
  strokeWeight(1);
  for(int i=0;i<8;i++){
    line(50,50+i*87.5,750,50+i*87.5);
    line(50+i*87.5,50,50+i*87.5,750);
  }

}

Week03-2
int nowX,nowY;
void setup(){
  size(800,800);
}
void draw(){
  background(#F2E490);
  noFill();
  strokeWeight(6);
  rect(50,50,700,700);
  strokeWeight(1);
  for(int i=0;i<10;i++){
    line(50,50+i*70,750,50+i*70);
    line(50+i*70,50,50+i*70,750);
  }
  fill(255,0,0);
  rect(nowX*70+50,nowY*70+50,70,70);
}
void mouseMoved(){
  nowX=(mouseX-50)/70;
  nowY=(mouseY-50)/70;
  println("mouseX:"+mouseX+"mouseY:"+mouseY+"nowX:"+nowX+"nowY:"+nowY);
  
}
Week03-3
int nowX,nowY;
int [][] array=new  int [8][8];
void setup(){
  size(800,800);
}
void draw(){
  background(#F2E490);
  noFill();
  strokeWeight(6);
  rect(50,50,700,700);
  strokeWeight(1);
  for(int i=0;i<10;i++){
    line(50,50+i*70,750,50+i*70);
    line(50+i*70,50,50+i*70,750);
  }
  fill(255,0,0);
  rect(nowX*70+50,nowY*70+50,70,70);
  fill(0);
  for(int i=0;i<8;i++){
    for(int j=0;j<8;j++){
      if(array[i][j]==1)rect(i*70+50,j*70+50,70,70);
    }
  }
}
void mousePressed(){
  array[nowX][nowY]=1;
}
void mouseMoved(){
  nowX=(mouseX-50)/70;
  nowY=(mouseY-50)/70;
  println("mouseX:"+mouseX+"mouseY:"+mouseY+"nowX:"+nowX+"nowY:"+nowY);
  
}
int nowX,nowY,Color=1;
int [][] array=new  int [10][10];
void setup(){
  size(800,800);
}
void draw(){
  background(#F2E490);
  noFill();
  strokeWeight(6);
  rect(50,50,700,700);
  strokeWeight(1);
  for(int i=0;i<10;i++){
    line(50,50+i*70,750,50+i*70);
    line(50+i*70,50,50+i*70,750);
  }
  fill(255,0,0,50);
  rect(nowX*70+85,nowY*70+85,70,70);
  for(int i=0;i<10;i++){
    for(int j=0;j<8;j++){
      if(array[i][j]==1){fill(0);ellipse(i*70+120,j*70+120,70,70);}
      if(array[i][j]==2){fill(255);ellipse(i*70+120,j*70+120,70,70);}  
  }
  }
}
void mousePressed(){
  array[nowX][nowY]=Color;
  if(Color==1)Color=2;
  else if(Color==2)Color=1;
}
void mouseMoved(){
  nowX=(mouseX-85)/70;
  nowY=(mouseY-85)/70;
  println("mouseX:"+mouseX+"mouseY:"+mouseY+"nowX:"+nowX+"nowY:"+nowY);
  
}


2013年9月15日 星期日

Week02 鄭羽婷

//Week02-1
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);
    }
  }
}

//Week02-2
void setup(){
  size(600,400);
}
void draw(){
  for(int x=0;x<600;x+=100){
    for(int y=0;y<400;y+=100){
      stroke(0,0,0);
      fill(255, 255, 255);
      rect(x,y,100,100);
      fill(255, 0, 0);
      stroke(255, 0, 0);
      triangle(x, y+80, x+50, y, x+100, y+80);
      triangle(x, y+20, x+50, y+100, x+100, y+20);
    }
  }
}


//Week02-3
void setup(){
  size(600,400);
}
void draw(){
  for(int x=0;x<600;x+=100){
    for(int y=0;y<400;y+=100){
      fill(0,0, 255);
      rect(x,y,100,100);
      fill(255, 0, 0);
      triangle(x, y+80, x+50, y, x+100, y+80);
      triangle(x, y+20, x+50, y+100, x+100, y+20);
      stroke(0, 0, 0);
      noFill();
      triangle(x, y+80, x+50, y, x+100, y+80);
    }
  }

}



//Week02-4
void setup(){
  size(600,400);
}
void draw(){
  for(int x=0;x<600;x+=100){
    for(int y=0;y<400;y+=100){
      fill(0,0, 255);
      rect(x,y,100,100);
      fill(255, 0, 0,dist(x,y,mouseX,mouseY)*2);
      triangle(x, y+80, x+50, y, x+100, y+80);
      triangle(x, y+20, x+50, y+100, x+100, y+20);
      stroke(0, 0, 0);
      noFill();
      triangle(x, y+80, x+50, y, x+100, y+80);
    }
  }
}

//Week02-4-2
void setup(){
  size(600,400);
}
void draw(){
  for(int x=0;x<600;x+=100){
    for(int y=0;y<400;y+=100){
      fill(0,0, 255);
      rect(x,y,100,100);
      fill(255, 0, 0,dist(x,y,mouseX,mouseY)*2);
      triangle(x, y+80, x+50, y, x+100, y+80);
      triangle(x, y+20, x+50, y+100, x+100, y+20);
      stroke(0, 0, 0);
      noFill();
      triangle(x, y+80, x+50, y, x+100, y+80);
    }
  }
}
//Week02-5
color [][] myColor=new color[6][4];
color [][] myColor2=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(256),random(256),random(256));
      myColor2[x/100][y/100]=color(random(256),random(256),random(256));
    }
  }
}
void draw(){
  for(int x=0;x<600;x+=100){
    for(int y=0;y<400;y+=100){
      fill(myColor[x/100][y/100]);
      rect(x,y,100,100);
      fill(myColor2[x/100][y/100],dist(x+50,y+50,mouseX,mouseY)*4);
      //fill(255,0,0,dist(x+50,y+50,mouseX,mouseY)*4);
      triangle(x, y+80, x+50, y, x+100, y+80);
      triangle(x, y+20, x+50, y+100, x+100, y+20);
      stroke(0, 0, 0);
      noFill();
      triangle(x, y+80, x+50, y, x+100, y+80);
    }
  }
}

//Week02-6心得

想寫一個簡單的手機遊戲!!
老師上課速度OK!!回家也可以看影片還好

2013年9月8日 星期日

Week01鄭羽婷


0.1. 加入 課程FB社團
0.2. Google文件 填寫修課資料 (學號姓名,email,電話)
0.3. 加入 Blog, 設定

編交作業方式: tag: 000葉正聖老師, Week01, 00160011葉大明
逗號隔開, 學號姓名間不要有空格



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