顯示具有 04160720_陳享翊 標籤的文章。 顯示所有文章
顯示具有 04160720_陳享翊 標籤的文章。 顯示所有文章

2018年1月22日 星期一

Week19 期末作品展示

影片Demo網址:
https://www.youtube.com/watch?v=1FxdWV-X5fI&feature=youtu.be



互動裝置截圖:
左方為藍鼓,右方為紅鼓
















程式碼:

Arduino中
void setup()
{
  Serial.begin(9600);
  pinMode (2,INPUT_PULLUP);
  pinMode (3,INPUT_PULLUP);
}
 
void loop()
{
int a = digitalRead(2);
int b = digitalRead(3);
//Serial.println(digitalRead(3));
//Serial.println(digitalRead(4));
Serial.write(digitalRead(2));
Serial.write(digitalRead(3));
delay(220);
}


於Processing中
import processing.video.*; 
Movie movie;
import ddf.minim.*;
Minim minim;
import processing.serial.*;
Serial myPort;
AudioPlayer song;
PImage A;
PImage Q;
PImage z;
PImage x;
PImage red;
PImage summer;
PImage center;
PImage End;
float rx=800, ry=160;
int bx=800, by=160;
PVector v1, v2;
float []array=new float [560];
PVector []newarray=new PVector[560];
float []array2=new float [560];
byte[] drum3=new byte[560];
byte[] bluedrum=new byte[560];
int []dy=new int [100];
int Score=0;
int shift=200;
int state=0;
int sta=0;
int rs=0;
int bs=0;
PImage home;
PImage good;
PImage setting;
PImage drum;
PImage blue;
PImage song1;
PImage mm;
PImage nn;
PImage bluebird;
int user=120;

void setup()
{
  size(1200, 900);
  A=loadImage("A.png");
  home= loadImage("home.png");
  setting=loadImage("setting.png");
  summer=loadImage("summer2.png");
  drum=loadImage("drum.png");
  Q=loadImage("Q.jpg");
  song1=loadImage("song1.png"); 
  good=loadImage("good.png");
  center=loadImage("center.png"); 
  red=loadImage("red.png");
  blue=loadImage("blue.png");
  mm=loadImage("mm.png");
  nn=loadImage("nn.png");
  z=loadImage("z.png");
  x=loadImage("x.png");
  bluebird=loadImage("bluebird.png");
  drum3=loadBytes("drum.bin");
  bluedrum=loadBytes("bluedrum.bin");
  movie = new Movie(this, "123.mp4");
  movie.loop();
  myPort=new Serial(this, "COM3", 9600);
}
int k, f, g;
void movieEvent(Movie movie)
{
  movie.read();
int bgShift=0;
void draw()
{
  int rs=0;
  int bs=0;
  bgShift+=15;

  if (state==0)
  {
    image(home, 0, 0, 1200, 900);
    fill(255, 255, 255);
    rect(355, 803, 487, 80);
    fill(255, 0, 0);
    textSize(80);
    text("Press:P", 454, 870);
  }
  if (state==4)
  {
    image(bluebird, 100, 100, 1000, 200);
    image(mm, 600, 100, 1000, 200);
    image(song1, 100, 400, 1000, 200);
    image(nn, 600, 400, 1000, 200);
    image(z, 100, 600, 1000, 200);
    image(x, 600, 600, 1000, 200);
  }
  if (state==1) 
  {      
    image(A, 0, 0, 1200, 900);
    image(movie, 0, 498, 1200, 400);
    image(center, 470, 370, 240, 180);
    image(Q, 0, 415, 300, 80);
    fill(255, 0, 0);
    rect(690, 153, 510, 58);
    noStroke();
    textSize(50);
    fill(255);
    text(Score*100, 800, 200);

    for (int i=0; i<array.length; i++)
    {  
      if (drum3[i]!=0)
      { 
        array[i]=i*100+600-bgShift;
        if (array[i]>shift)
        {  
          image(red, array[i], 253, 80, 80);
        }
      }
      if (bluedrum[i]!=0)
      { 
        array2[i]=i*100+600-bgShift;
        if (array2[i]>shift)
        {  
          image(blue, array2[i], 253, 80, 80);
        }
      }   
      {  
        if (myPort.available()>0) {
          int pin2=myPort.read();
          if (pin2==1) rs=1;
          println(pin2);
        }
        if (myPort.available()>0) {
          int pin3=myPort.read();
          if (pin3==1) bs=1;
          println(pin3);
        }
        if (abs(array[i]-shift-25)<20 && array[i]!=0&&rs==1)
        {   
          fill(255, 0, 0, 200);
          ellipse(110, 285, 140, 110);
          Score++;
          textSize(30);
          fill(255, 227, 132);
          text("GOOD", 250, 222);
          noFill();

          song=minim.loadFile("r.mp3", 2048);     
          song.play();
          rs=0;
        }
        if (abs(array2[i]-shift-25)<20 && array2[i]!=0&&bs==1)
        {

          ellipseMode(RADIUS);
          fill(0, 0, 255, 200);
          ellipse(110, 285, 95, 80);
          ellipseMode(CENTER);
          fill(255, 255, 255, 200);
          ellipse(110, 285, 140, 110);
          Score++;
          textSize(30);
          fill(255, 227, 132);


          song=minim.loadFile("b.mp3", 2048);     
          song.play();
          bs=0;
          text("GOOD", 250, 222);
          noFill();
        }
      }
    }
    k=Score*2;
    f=30;
    g=440;
    rect(g, 58, k, f, 255); 

    if (sta==0)
    {
      fill(255, 0, 0);
      textSize(80);
      text(Score, 85, 310);
    }
  }
  if (state==2) 
  {    
    image(A, 0, 0, 1200, 900);
    image(Q, 0, 415, 300, 80);
    fill(0);
    rect(695, 454, 470, 36);
    image(movie, 0, 498, 1200, 400);
    image(summer, 840, 420, 150, 70);
    image(center, 470, 370, 240, 180);
    fill(255, 0, 0);
    rect(690, 153, 510, 58);
    noStroke();
    textSize(50);
    fill(255);
    text(Score*100, 800, 200);

    for (int i=0; i<array.length; i++)
    {  

      if (drum3[i]!=0)
      { 
        array[i]=i*100+600-bgShift;
        if (array[i]>shift)
        {  

          image(red, array[i], 253, 80, 80);
        }
      }
      if (bluedrum[i]!=0)
      { 
        array2[i]=i*100+600-bgShift;
        if (array2[i]>shift)
        {  

          image(blue, array2[i], 253, 80, 80);
        }
      }   


      {  
        if (myPort.available()>0) {
          int pin2=myPort.read();
          if (pin2==1) rs=1;
          println(pin2);
        }

        if (myPort.available()>0) {
          int pin3=myPort.read();
          if (pin3==1) bs=1;
          println(pin3);
        }
        if (abs(array[i]-shift-25)<20 && array[i]!=0&&rs==1)
        {   


          fill(255, 0, 0, 200);
          ellipse(110, 285, 140, 110);
          Score++;
          textSize(30);
          fill(255, 227, 132);
          text("GOOD", 250, 222);
          noFill();

          song=minim.loadFile("r.mp3", 2048);     
          song.play();
          rs=0;
        }


        if (abs(array2[i]-shift-25)<20 && array2[i]!=0&&bs==1)
        {

          ellipseMode(RADIUS);
          fill(0, 0, 255, 200);
          ellipse(110, 285, 95, 80);
          ellipseMode(CENTER);
          fill(255, 255, 255, 200);
          ellipse(110, 285, 140, 110);
          Score++;
          textSize(30);
          fill(255, 227, 132);


          song=minim.loadFile("b.mp3", 2048);     
          song.play();
          bs=0;
          text("GOOD", 250, 222);
          noFill();
        }
      }

      if (sta==0)
      {
        fill(255, 0, 0);
        textSize(80);
        text(Score, 85, 310);
      }
    }
    k=Score*2;
    f=30;
    g=440;
    fill(255, 0, 0);
    rect(g, 58, k, f, 255); 

    if (key=='q'||key=='Q')
    {
      sta=1;

      fill(255, 255, 255);
      rect(218, 208, 1000, 200);
      textSize(100);
      fill(255, 0, 0);
      text("Score:"+Score*100, 300, 310);
      song.close();
      minim.stop();
      super.stop();
    }
  }
}
void keyReleased()
{

  if (key=='p'||key=='P')
  {
    state=4;
  }
  if (key=='m'||key=='M')
  {
    state=1; 
    minim=new Minim(this);
    song=minim.loadFile("blue bird.mp3", 2048);     
    song.play();
  }
  if (key=='n'||key=='N')
  {
    state=2; 
    minim=new Minim(this);
    song=minim.loadFile("summer.mp3", 2048);     
    song.play();
  }
  if (state==4)
  {
    background(#FFE153);
  }
}



2017年11月20日 星期一

Week 10 期中作品展示

https://www.youtube.com/watch?v=RrgpUTqgJTc&feature=youtu.be

Week05 享翊的上課筆記

Xeyes 跟著滑鼠轉動眼珠
void setup()
{
  size(800,800);
}
void draw()
  {
   background(128);
   strokeWeight(20);
   ellipse(100,200,180,360);
   ellipse(300,200,180,360);
 
   float angle1=atan2((mouseY-200)/2,mouseX-300);
   float newX1=300+100*cos(angle1)/2;
   float newY1=200+200*sin(angle1)/2;
   ellipse(newX1,newY1,10,10);
   float angle2=atan2((mouseY-200)/2,mouseX-100);
   float newX2=100+ 100*cos(angle2)/2;
   float newY2=200+ 200*sin(angle2)/2;
   ellipse(newX2,newY2,10,10);
 
  }



砲塔打泡泡

void setup()
{
  size(400,800);
}
float ballX=200,ballY=600;
float ballVX=0,ballVY=0;
float angle=0;
void draw()
{
  background(100,120,100);
  ellipse(200,600,100,100);fill(#FA9703);
  line(mouseX,mouseY,200,600);
  fill(#F9FA03); ellipse(ballX,ballY,30,30);
  angle=atan2(mouseY-600,mouseX-200);

  ballX+=ballVX;
  ballY+=ballVY; 
}
void mouseMoved()
{
  ballX=200+50*cos(angle);
  ballY=600+50*sin(angle);
}
void mousePressed()
{
  ballVX=cos(angle);
  ballVY=sin(angle);
}


利用陣列排列 10個陣列
void setup()
{
  size(400,800);
}
float [] ballX=new float [10];
float [] ballY=new float [10];
float [] ballVX=new float [10];
float [] ballVY=new float [10];

float []angle=new float[10];
int now=0;

void draw()
{
  background(100,120,100);
  ellipse(200,600,100,100);fill(#FA9703);
  for(int i=0;i<10;i++)
  {
    fill(#F9FA03); ellipse(ballX[i],ballY[i],30,30);
    ballX[i]+=ballVX[i];
    ballY[i]+=ballVY[i];
  }
  angle[now] =atan2(mouseY-600,mouseX-200);

}
void mouseMoved()
{
  ballX[now]=200+50*cos(angle[now]);
  ballY[now]=600+50*sin(angle[now]);
}
void mousePressed()
{
  ballVX[now]=cos(angle[now]);
  ballVY[now]=sin(angle[now]);
  now++;

}





2017年10月23日 星期一

Week06 享翊的上課筆記




今天在學校做了 期中作業的封面,遊戲內容之前在家裡有做一些了,回去之後combine
一起

2017年10月16日 星期一

Week04 享翊的上課筆記

優化憤怒鳥
程式碼:
PImage imgBird, imgPig;
float birdAX=0,birdAY=0;
float [][]pigx=new float[5][4];
float [][]pigy=new float[5][4];
boolean [][]pigAlive=new boolean[5][4];
void setup(){
  size(800,600);
  imgBird=loadImage("bird.png");
  imgPig=loadImage("pig.png");
  imageMode(CENTER);
  for(int i=0;i<5;i++)
  {
    for(int j=0;j<4;j++)
  {
    pigx[i][j]=700-i*100;pigy[i][j]=100+j*100;pigAlive[i][j]=true;
  }
}
}
float birdX = 400, birdY = 300;
float birdVX = 0, birdVY = 0;

void draw(){
  background(255);
  for(int i=0;i<5;i++)
  {
    for(int j=0;j<4;j++)
  {
    if(dist(pigx[i][j],pigy[i][j],birdX,birdY)<100)
    {
      pigAlive[i][j]=false;
  }
  if(pigAlive[i][j]) image(imgPig,pigx[i][j],pigy[i][j],100,100);
  }
}
image(imgBird, birdX, birdY, 100, 100);

  line(birdX, birdY, 400,300);
  birdX += birdVX;
  birdY += birdVY;

  if(birdX<50){birdX=50; birdVX = -birdVX;}
  if(birdX>width-50){birdX=width-50; birdVX= -birdVX;}
  if(birdY<50){birdY=50; birdVY = -birdVY;}
  if(birdY>height-50){birdY=height-50; birdVY= -birdVY;}


  birdVX += birdAX;
  birdVY += birdAY;
  birdVX *= 0.995;
  birdVY *= 0.995;
}

void mouseDragged(){
  birdX=mouseX;
  birdY=mouseY;
  birdVX=birdVY=birdAX=birdAY=0;

}
void mouseReleased(){
  birdVX = (400-mouseX)/10.0;
  birdVY = (300-mouseY)/10.0;
  birdAY = 0.98;
}


老師第二次解釋矩陣排列圓圈
float birdX=100,birdY=400;
float [][]pigx=new float[5][4];
float [][]pigy=new float[5][4];
boolean [][]pigAlive=new boolean[5][4];
void setup(){
  size(800,600);
  for(int i=0;i<5;i++)
  {
    for(int j=0;j<4;j++)
  {
    pigx[i][j]=700-i*100;pigy[i][j]=100+j*100;pigAlive[i][j]=true;
  }
 }
}

void draw()
{
  
  for(int i=0;i<5;i++)
  {
    for(int j=0;j<4;j++)
  {
    fill(255);ellipse(pigx[i][j],pigy[i][j],100,100);
  }
  }
  fill(0);ellipse(birdX,birdY,100,100);
}



播放音樂
新增 sound資料庫
最簡單的播放音樂
import processing.sound.*;
SoundFile sound;
void setup()
{
  
 size(800,600);

 sound=new SoundFile(this,"Boss.mp3");
 sound.play();
 sound.loop();
 }


2017年9月30日 星期六

Week03 陳享翊的上課筆記

先找好憤怒鳥的圖片







拋物線
mouseReleasd()
{
}


加入重力加速度





新增碰撞豬消失



新增 邊界反彈



小朋友下樓梯關鍵 往下++ 遇到樓梯停下來 沒有則繼續往下

Week02 陳享翊的上課筆記



利用滑鼠作出小畫家,用按鍵調顏色跟粗細。
畫圈圈準備做出毛毛蟲的範例
讀圖片


2017年9月18日 星期一

Week01 陳享翊的上課筆記

從線跟四邊形開始

開始讓線條可以停止加顏色



第三堂
https://www.openprocessing.org/


他原本是個條碼,利用與滑鼠的互動產生波浪。