顯示具有 05160992_劉沛潔 標籤的文章。 顯示所有文章
顯示具有 05160992_劉沛潔 標籤的文章。 顯示所有文章

2018年12月27日 星期四

WEEK16_劉沛潔

我們這組期末作品是要做鼓,但是在我們開始做的時候發現好難,網路上找資料都太專業了,就想說改作鋼琴好了,結果跟老師說我們想改的時候,老師說希望我們可以完成,而且也要幫助我們完成,於是我們今天早上八點就來跟老師一起解決我們的問題,讓我們原本落後的進度幾乎快要完成了。
但是我們還有一個瓶頸,就是焊接焊不成功,焊了很久之後先焊到手才知道,因為我們的錫箔太光滑了,所以才焊不上去,要先用砂紙把它磨平,才可以成功焊上去,但是我們現在也沒有砂紙,只好先在我們的錫箔碗上面戳兩個洞,把線先纏幾圈,改天再焊上去吧QQ

2018年12月20日 星期四

week14 劉沛潔


打開範例檔案


點擊程式碼中的網址


void setup()
{
    pinMode(13,OUTPUT); //設定Led為output
}

void loop()
{
    int value=analogRead(A0);
    digitalWrite(13,HIGH); //LED 閃爍
    delay(value);
    digitalWrite(13,LOW); 
    delay(value);
}

week12 劉沛潔

今天在台北車站的一個巷子的四樓還是五樓做光劍

首先先拿100個led燈

然後把他們的腳掰開

再把他們的腳掰回去

讓兩隻腳的間距根燈一樣寬

然後開始焊接

長的腳跟長的腳焊在一起

把全部焊完之後確定會不會亮

焊了很久

非常非常之久

我覺得是因為焊槍不太夠

大家要等

一拿到焊槍就會想趕快多焊幾個

導致很容易焊錯

就要一直解焊重新再焊

焊的心很累

焊到12點還沒焊完

大家都留下來繼續焊

放棄下午的機率與統計

焊完全部都確定會亮之後

他給我們一個電池

也要跟led焊在一起

焊完之後放到光劍裡面

沒有焊好就要把電池敲出來

很難用超難用

塞電池要很有技術

塞好就成功了

再自己裝握把

裝完終於大功告成

聽說最晚的做完回到學校已經五六點了

真辛苦

但是很有意義欸

小葉真棒

讚嘆小葉

資傳最好的老師就是小葉老師了

2018年11月22日 星期四

week11劉沛潔

這個是光劍的程式碼
可以讓13個LED都變亮

void setup(){
  for(int i=2; i<=13; i++){
    pinMode(i, OUTPUT);
    }
  }
  void loop(){
    for(int i=2; i<=13; i++){
      digitalWrite(i, HIGH);
      delay(300);
      }
      for(int i=2; i<=13; i++){
        digitalWrite(i, LOW);
        }
    }

第二節課做跟上禮拜一樣的小星星

老師會轉魔術方塊


以下是 可以卡歌、換歌的程式碼
/*
This example shows how to change melody with push button using only a Maker UNO.
Tutorial page:
  http://makeruno.com.my/changing-melody-with-push-button-using-only-maker-uno/

Original written by:
  26/01/18  Asyraf (Intern), Cytron Technologies
*/

int piezoPin = 8;
int button = 2;
int lengths = 26;
char jbnotes[] = "eeeeeeegcde fffffeeeeddedg";
int jbbeats[] = { 1, 1, 2, 1, 1, 2, 1, 1, 1, 1, 4, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 2, 2};
int length = 15;
char ttlsnotes[] = "ccggaag ffeeddc ggffeed ggffeed ccggaag ffeeddc ";
int ttlsbeats[] = { 1, 1, 1, 1, 1, 1, 2, 1, 1, 1, 1, 1, 1, 2, 4 };
int tempo = 300;

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

void playNote(char note, int duration)
{
  int LED[]={3,4,5,6,7,9,10,11};
  char names[] = { 'c', 'd', 'e', 'f', 'g', 'a', 'b', 'C' };
  int tones[] = { 1915, 1700, 1519, 1432, 1275, 1136, 1014, 956 };
  for (int i = 0; i < 8; i++)
  {
    if (names[i] == note)
    {
      digitalWrite(LED[i], HIGH);
      playTone(tones[i], duration);
      digitalWrite(LED[i], LOW);
    }
  }
}

void setup()
{
  //pinMode(piezoPin, OUTPUT);
  for(int i=3; i<=13; i++)pinMode(i, OUTPUT);
  pinMode(2, INPUT_PULLUP);
}

void loop()
{
  int sensorVal = digitalRead(button);
  if (sensorVal == HIGH)
  {
    for (int i = 0; i < length; i++)
    {
      if (ttlsnotes[i] == ' ')
      {
        delay(ttlsbeats[i] * tempo);
      }
      else
        playNote(ttlsnotes[i], ttlsbeats[i] * tempo);
        if(digitalRead(button)==LOW)break;
      delay(tempo / 2);
    }
  }
  else
  {
    for (int i = 0; i < lengths; i++)
    {
      if (jbnotes[i] == ' ')
      {
        delay(jbbeats[i] * tempo);
      }
      else
        playNote(jbnotes[i], jbbeats[i] * tempo);
      delay(tempo / 2);
    }
  }
}

2018年11月15日 星期四

week10劉沛潔

/*
This example shows how to change melody with push button using only a Maker UNO.
Tutorial page:
http://makeruno.com.my/changing-melody-with-push-button-using-only-maker-uno/
Original written by:
26/01/18 Asyraf (Intern), Cytron Technologies
*/
int piezoPin = 8;
int button = 2;
int lengths = 26;
char jbnotes[] = "eeeeeeegcde fffffeeeeddedg";
int jbbeats[] = { 1, 1, 2, 1, 1, 2, 1, 1, 1, 1, 4, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 2, 2};
int length = 15;
char ttlsnotes[] = "ccggaag ffeeddc ggffeed ggffeed ccggaag ffeeddc ";
int ttlsbeats[] = { 1, 1, 1, 1, 1, 1, 2, 1, 1, 1, 1, 1, 1, 2, 4 };
int tempo = 300;
void playTone(int tone, int duration)
{
for (long i = 0; i < duration * 1000L; i += tone * 2)
{
digitalWrite(piezoPin, HIGH);
delayMicroseconds(tone);
digitalWrite(piezoPin, 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 };
for (int i = 0; i < 8; i++)
{
if (names[i] == note)
{
playTone(tones[i], duration);
}
}
}
void setup()
{
pinMode(piezoPin, OUTPUT);
pinMode(button, INPUT_PULLUP);
}
void loop()
{
int sensorVal = digitalRead(button);
if (sensorVal == HIGH)
{
for (int i = 0; i < length; i++)
{
if (ttlsnotes[i] == ' ')
{
delay(ttlsbeats[i] * tempo);
}
else
playNote(ttlsnotes[i], ttlsbeats[i] * tempo);
delay(tempo / 2);
}
}
else
{
for (int i = 0; i < lengths; i++)
{
if (jbnotes[i] == ' ')
{
delay(jbbeats[i] * tempo);
}
else
playNote(jbnotes[i], jbbeats[i] * tempo);
delay(tempo / 2);
}
}
} 這是讓uno可以發出很吵聲音的程式碼

2018年11月1日 星期四

Week8其中作業 鄭昕恬劉沛潔

期中作品



操作模式:
進到遊戲畫面後,點'1'開始遊戲,利用滑鼠控制忍者左右移動,
並按滑鼠左右鍵向惡鬼射出刀子,右下有個魔力條,當魔力用光
就輸了遊戲,而當殺鬼的分數到達設定值時,即遊戲勝利。

遊戲賣點:
利用可愛的忍者角色,結合最近的萬聖節,組合成一個有趣的組合
在符合氣氛的背景還有音效下,玩著此遊戲很符合過節的氣氛,雖
然遊戲名"砍殺惡鬼"聽起來帶有恐怖的感覺,但事實上卻是個可愛
趣味的遊戲。

程式碼:
import ddf.minim.*;
Minim minim;
AudioPlayer player;
PImage img;
PImage ninja;
PImage ninja01;
PImage ninja02;
PImage background02;
PImage background01;
PImage bullet;
PImage[] imgN=new PImage[10];
PImage monster;
int[]monsterlife=new int[100];
float[]bulletX =new float[100];
float[]bulletY =new float[100];
boolean []bulletAlive =new boolean[100];
float [] monsterX = new float[100];
float [] monsterY = new float[100];
boolean[] monsterDie= new boolean[100];
boolean win =false;
boolean lose = false;
int life=100;
float[]lineY=new float[1];
int state=0;
void setup() {
  minim= new Minim(this);
  player=minim.loadFile("music.mp3");
  player.play();
  player.loop();
  size(800, 600);
  for (int i=0; i<=9; i++) imgN[i] = loadImage(i+".png");
  background01=loadImage("background.jpg");
  background02=loadImage("background01.png");
  ninja=loadImage("ninja.png");
  ninja01=loadImage("ninja01.png");
  ninja02=loadImage("ninja02.png");
  bullet=loadImage("bullet.png");
  img=loadImage("soldier.png");
  monster=loadImage("monster.png");
  for (int i=0; i<100; i++) {
    monsterX[i]=random(0, 600);
    monsterY[i]=random(-1000, 2);
    monsterlife[i]=1;
    monsterDie[i]=false;
  }
}
void draw() {
  if(state==0){
    drawOP();
    if(key=='1')state=1;
    }
    else if(state==1){
      drawPlayer();
  }
 }
boolean flying=false;
int score=0;
void drawPlayer(){
  background(255);
  image(background01, 0, 0, 800, 600);
  fill(255);rect(630,480,100,20);
  fill(0,0,255);rect(630,480,life*1,20);
  //fill(255);rect(0,450,900,1);
  stroke(255);
  fill(255);
  image(img, mouseX-10, 450, 100, 150);
  for (int i=0; i<100; i++) {
    if (monsterDie[i])continue;
    image(monster, monsterX[i], monsterY[i], 90, 100);
    monsterY[i]+=1;
   // if (monsterY[i]>700) monsterY[i]=-2000+600;
  // if(monsterY[i]<lineY)life--;
 
  }

  for (int b=0; b<100; b++) {
    if (bulletAlive[b]) {
      fill(255, 255, 0);
      image(bullet, bulletX[b], bulletY[b], 60, 60);
      bulletY[b]-=7;
      for (int i=0; i<100; i++) {
        if (monsterX[i]<bulletX[b]&&bulletX[b]<monsterX[i]+40 && abs(bulletY[b]-monsterY[i])<30) {
          monsterlife[i]=0;
          score+=100;
          bulletAlive[b]=false;
          monsterDie[i]=true;
       
        }
        //fill(255);rect(630,480,100,20);
          //fill(255,0,0);rect(630,480,life,20);
          //if(monsterY[i]>500)life--;
      }
    }
  }

  int now=score;
  for (int i=0; i<5; i++) {
    image(imgN[(now%10)], 720-i*30, 520, 40, 40);
    now/=10;
  }
  //int now=blood;

  if (win) {
    background(255, 255, 255);
    image(background02, 0, 0, 800, 600);
    image(ninja, 100, 100, 300, 300);
    textSize(80);
    fill(255, 0, 0);
    text("YOU WIN!", 300, 300);
  }
  if (lose) {
    background(255, 255, 255);
    image(background02, 0, 0, 800, 600);
    image(ninja01, 100, 100, 300, 300);
    textSize(80);
    fill(255, 0, 0);
    text("YOU LOSE!", 300, 300);
  }
}
void drawOP(){
  background(255);
  image(background01, 0, 0, 800, 600);
  image(ninja02, 300, 150, 200, 300);
  text("you can press 1 to play...",170,240);
  textSize(40);
  fill(#8E7366);
}
void mousePressed() {
  life-=3;
  if (score>2000)win=true;
   if(life<0)lose=true;
  for (int now=0; now<100; now++) {
    if (bulletAlive[now] ==false) {
      bulletX[now]=mouseX;
      bulletY[now]=450;
      bulletAlive[now]=true;
      break;
    }
  }
}

遭遇困難:
我想最大的困難就是從無到有吧,從一開始沒什麼想法,到參考老師
的各種影片,把影片中的一些重點與自己的遊戲互相配合,從每個教學
影片都學到不同技巧,不管是有關場景還是遊戲中的偵測等等,寫出一個
遊戲真不是那麼容易,但也不像想像中那麼難,除了要一直創新和除錯
也要與共同的組員相互討論,還好最後還是靠著老師的影片、同學的發問
,在這之中了解了許多要點,才因此寫出屬於自己的遊戲。

2018年10月18日 星期四

WEEK06_劉沛潔

11/29校外教學在台北車站


有背景音樂的程式碼
import ddf.minim.*;
Minim minim;
AudioPlayer player;
void setup(){
   minim = new Minim(this);
   player=minim.loadFile("groove.mp3");
   player.play();
}
void draw(){

}

要記得把音樂拉進去

--
畫一個圈圈讓他像水果忍者一樣的跳

float fX, fY, fVX, fVY;
void setup(){
  size(800, 600);
  fX=30; fVX=3; fY=700; fVY=-35;
}
void draw(){
  background(0);
  ellipse(fX, fY, 100, 100);
  fX+=fVX;
  fY+=fVY;
  fVY+=0.98;
}



--
多一點
float[]fX=new float[20];
float[]fY=new float[20];
float[]fVX=new float[20];
float[]fVY=new float[20];
void setup(){
  size(800, 600);
  for(int i=0; i<20; i++){
    fX[i]=random(800); fVX[i]=3;
    fY[i]=700; fVY[i]=-35;
  }
}
void draw(){
  background(0);
  for(int i=0; i<20; i++){
    ellipse(fX[i], fY[i], 100, 100);
    fX[i]+=fVX[i];
    fY[i]+=fVY[i];
    fVY[i]+=0.98;
  }
}

2018年10月11日 星期四

week5_劉沛潔

校園參訪在台北車站水源街

接雞蛋
float[]eggX=new float[100];
float[]eggY=new float[100];
boolean[]eggDie=new boolean[100];
void setup(){
  size(800, 600);
  for(int i=0; i<100; i++){
    eggX[i]=random(100,700);
    eggY[i]=-random(2000);
    eggDie[i]=false;
  }
}
void draw(){
  background(255);
  rect(mouseX-50, mouseY-25, 100, 50);
  for(int i=0; i<100; i++){
    if(eggDie[i])continue;
    ellipse(eggX[i], eggY[i], 80, 100);
    eggY[i]+=5;
    if(eggY[i]>700)eggY[i]=-2000+600;
    if(dist(mouseX-50, mouseY-25, eggX[i], eggY[i])<50){
      eggDie[i]=true;
    }
  }
}


加分數
int score=0;
void draw(){
  background(255);
  fill(255);rect(mouseX-50, mouseY-25, 100, 50);
  for(int i=0; i<100; i++){
    if(eggDie[i])continue;
    ellipse(eggX[i], eggY[i], 80, 100);
    eggY[i]+=5;
    if(eggY[i]>700)eggY[i]=-2000+600;
    if(dist(mouseX-50, mouseY-25, eggX[i], eggY[i])<50){
      eggDie[i]=true;
      score+=100;
    }
  }
  fill(255, 0, 0);textSize(80);text("Score:"+score, 100, 100);
}


水果忍者


PImage[]img=new PImage[8];
float[]cherryX= new float[8];
float[]cherryY= new float[8];
float[]cherryVX= new float[8];
float[]cherryVY= new float[8];
void cherryReborn(int i){
  cherryX[i]=random(800);
  cherryY[i]=700;
  cherryVX[i]=random(8)-4;
  cherryVY[i]=-40;
}
void setup(){
  size(800, 600);
  for(int i=0; i<8; i++)img[i]=loadImage("pie.png");
  for(int i=0; i<8; i++)cherryReborn(i);
  for(int i=0; i<10; i++)sword[i]=new PVector();
}
PVector[] sword=new PVector[10];
void draw(){
  background(255);
  for(int i=0; i<8; i++){
    image(img[i], cherryX[i], cherryY[i], 100, 150);
    cherryX[i]+=cherryVX[i];
    cherryY[i]+=cherryVY[i];
    cherryVY[i]+=0.98;
  }
  for(int i=9; i<0; i--){
    sword[i].x=sword[i-1].x;sword[i].y=sword[i-1].y;
  }
  sword[0].x=mouseX; sword[0].y=mouseY;
  for(int i=1;i<10; i++){
    line(sword[i].x, sword[i].y, sword[i-1].x, sword[i-1].y);
  }
}

2018年10月4日 星期四

WEEK04_劉沛潔

先寫出文字
void setup(){
  size(800, 600);
}
void draw(){
  text("Start!", 100, 100);
}


畫一個正方形
rect(0,0,200,200);


把正方型塗顏色再寫字
void draw(){
  fill(100, 145, 189);rect(100,100,100,100);
  fill(120,110,70);text("Start!", 100, 100);
}


把字變大
textSize(100);


跟著滑鼠動
{
  fill(100, 145, 189);rect(mouseX, mouseY, 100,100);textSize(100);
  fill(120,110,70);text("Start!", mouseX, mouseY);
}


沒有殘影
background(255);



多畫個圓
void draw(){
  background(255);
  fill(100, 145, 189);rect(100,100, 100,100);
  ellipse(bulletX, bulletY, 50, 50);
}
float bulletX=100, bulletY=100;
void keyPressed(){

 }



發射圈圈
void draw(){
  background(255);
  fill(100, 145, 189);rect(100,100, 100,100);
  if(bulletFlying){
    ellipse(bulletX, bulletY, 50, 50);
    bulletX+=3;
  }
}
float bulletX=100, bulletY=100;
boolean bulletFlying=false;
void keyPressed(){
  bulletFlying=true;
 }


連續發射圈圈
void draw(){
  background(255);
  fill(100, 145, 189);rect(100,100, 100,100);
  for(int i=0; i<bulletN; i++){
    if(bulletFlying[i]){
      ellipse(bulletX[i], bulletY[i], 50, 50);
      bulletX[i]+=3;
    }
  }
}
float []bulletX=new float[100];
float []bulletY=new float[100];
int bulletN=0;
boolean []bulletFlying=new boolean[100];
void keyPressed(){
  bulletFlying[bulletN]=true;
  bulletX[bulletN]=100;bulletY[bulletN]=100;
  bulletN++;//有++才不會當機
 }

===




2018年9月27日 星期四

week03-劉沛潔

第三周

先畫一個視窗
void setup(){
  size(500, 500);
}
再畫一個圓
void draw(){
  ellipse(250, 250, 480, 480);
}



再畫一個三角形

}
void draw(){
  ellipse(250, 250, 480, 480);
  triangle(250, 250, 250, 10, 80, 150);
}



但是三角形的座標是無理數,沒辦法準確的找到三角形的位置
所以用cos sin的座標
再用for迴圈完成一個大的
void draw(){
  ellipse(250, 250, 480, 480);
  for(float angle=0; angle<PI*2; angle+=PI/3){
    triangle(250, 250, 250+240*cos(angle), 250+240*sin(angle),
                       250+240*cos(angle+PI/3), 250+240*sin(angle+PI/3));
  }
}



再多畫一點
void draw(){
  ellipse(250, 250, 480, 480);
  for(float angle=0; angle<PI*2; angle+=PI/3){
    for(int R=0; R<=240; R+=10){
      noFill();
    triangle(250, 250, 250+R*cos(angle), 250+R*sin(angle),
                       250+R*cos(angle+PI/3), 250+R*sin(angle+PI/3));
    }
  }
}




葉正聖分享了 1 段直播視訊

最後一堂課
馬力歐
但是我不想用馬力歐
PImage imgMario;
float marioX=0, marioY=0;
void setup(){
  size(400, 600);
  imgMario=loadImage("pop.png");
}
void draw(){
  background(255);
  image(imgMario, marioX, marioY, 100, 150);
}
void keyPressed(){
  if(keyCode==UP){marioY-=5;}
  if(keyCode==DOWN){marioY+=5;}
  if(keyCode==LEFT){marioX-=5;}
  if(keyCode==RIGHT){marioX+=5;}
}

讓大便可以掉下去
PImage imgMario;
float marioX=0, marioY=0, marioVX=2, marioVY=0, marioAX=0, marioAY=0.1;
void setup(){
  size(400, 600);
  imgMario=loadImage("pop.png");
}
void draw(){
  //background(255);
  image(imgMario, marioX, marioY, 100, 150);
  marioX+=marioVX; marioY+=marioVY; marioVX+=marioAX; marioVY+=marioAY;
}
void keyPressed(){
  if(keyCode==UP){marioY-=5;}
  if(keyCode==DOWN){marioY+=5;}
  if(keyCode==LEFT){marioX-=5;}
  if(keyCode==RIGHT){marioX+=5;}
}

讓大便可以自己跳
PImage imgMario;
float marioX=0, marioY=0, marioVX=2, marioVY=0, marioAX=0, marioAY=0.1;
void setup(){
  size(400, 600);
  imgMario=loadImage("pop.png");
}
void draw(){
  //background(255);
  image(imgMario, marioX, marioY, 100, 150);
  marioX+=marioVX; marioY+=marioVY; marioVX+=marioAX; marioVY+=0.9;
  if(marioY>600-150) marioVY*=-0.9;
  if(marioX>400-100) marioVX*=-1;
  if(marioY<0)       marioVY*=-0.9;
  if(marioX<0)       marioVX*=-1;
}
void keyPressed(){
  if(keyCode==UP){marioY-=5;}
  if(keyCode==DOWN){marioY+=5;}
  if(keyCode==LEFT){marioX-=5;}
  if(keyCode==RIGHT){marioX+=5;}
}

最後
憤怒鳥