顯示具有 07160281_王韻蘅 標籤的文章。 顯示所有文章
顯示具有 07160281_王韻蘅 標籤的文章。 顯示所有文章

2021年1月17日 星期日

FINAL!!!






 process

import processing.serial.*;////

Serial myPort;////

int count=1800;//60*30

PImage candy;

PImage car;

PImage bg;

PImage die;

PImage heart;

PImage win;

float [] candyX=new float[10];

float [] candyY=new float[10];

float carX=235, carY=450;

int score=150;

int h=0;

void setup() {

  size(513, 615);

  myPort = new Serial(this, "COM5", 9600);////

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

    candyX[i] = random(70, 295);

    candyY[i] = -i*100;

  }

  candy = loadImage("candy.png");///糖果

  car = loadImage("car.png");

  bg = loadImage("bg.jpg");

  die =loadImage("die.png");

  win =loadImage("win.png");

}

float vx=0;

//float vy=0;

void draw() {

  if (h==0) {

     

    image(bg, 0, 0, 513, 615);

    //background(255);

    //carX=mouseX-47;

    while (myPort.available()>=1)

    {

      int x = myPort.read();

      ///int y = myPort.read();

      //int sw = myPort.read();

      vx= (x-128)/32;

      // vy=(y-128)/32;

      println(vx);

      //carY=y;

    }

    carX += vx;

    // carY += vy;

    image(car, carX, carY, 50, 100);

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

      image(candy, candyX[i], candyY[i], 60, 60);

      candyY[i]+=2;

      if (candyY[i]>615)

      {

        candyY[i]=-300;  //-183

        candyX[i]=random(70, 295);///糖果重生

      }

      if (candyY[i]+60>carY) {

        if (carX<candyX[i]+58 && candyX[i]<carX+48) //2cm

        {///車碰到糖果

          score+=10;

          candyY[i]=-150;

        }

      }

    }

    if (count<0) {

      background(0, 0, 0);

      h=1;

    } else {

      count--;

    }

    textSize(50);

    fill(25, 25, 250, 250);

    text("Time: "+int(count/60), 250, 50);

    textSize(50);

    text(score, 50, 100);

  }

  if (count<0 && score<600)

   {

    h=1;

    image(die, -35, 100, 600, 350);

   }

   if (count<0 && score>=600)//超過六百分才贏

   {

    h=1;

    image(win, -35, 100, 600, 350);

   }

}


void keyPressed() {

  //count=1800;

  if (keyCode == ENTER)

  {

    h=0;

    score=150;

  }

}

arduino

void setup()

{

  pinMode(2, INPUT_PULLUP);//拉高的Input

  Serial.begin(9600);//開始設定USB的傳輸速度

}

void loop() {//1000Hz (1000 fps)

  int x = analogRead(A0);//0...1023

  //int y = analogRead(A1);//0...1023

 // int sw= digitalRead(2);//HIGH(放開)

  Serial.write (x/4);//第1個byte

  //Serial.write(y/4);//第2個byte

  //Serial.write (sw); //第3個byte

  delay(20);//1000ms/20ms => 50fps,變慢了

}

2020年12月28日 星期一

final

process 

import processing.serial.*;////

Serial myPort;////

PImage pic;

PImage car;

PImage bg;

PImage die;

PImage heart;

float [] picX=new float[10];


float [] picY=new float[10];

float carX=235, carY=450;

int score=50;

int h=0;


void setup() {

  size(513, 615);


  myPort = new Serial(this, "COM5",9600);////

  

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

    picX[i] = random(70, 295);

    picY[i] = -i*100;

  }

  pic = loadImage("pic.png");///三角椎

  car = loadImage("car.png");

  bg = loadImage("bg.png");

  die =loadImage("die.png");

}

float vx=0;

//float vy=0;

void draw() {

  if (h==0) {

    image(bg, 0, 0, 513, 615);

    //background(255);

    //carX=mouseX-47;   

 while(myPort.available()>=1)

     {

       int x = myPort.read();

       ///int y = myPort.read();

      //int sw = myPort.read();

       vx= (x-128)/32;

      // vy=(y-128)/32;

       println(vx);

       //carY=y;

     }

     carX += vx;

    // carY += vy;

    image(car, carX, carY, 50, 100);


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

      image(pic, picX[i], picY[i], 60, 60);

      picY[i]+=2;

      if (picY[i]>615)

      {

        picY[i]=-183;  

        picX[i]=random(70, 295);///三角錐重生

      }

      if (picY[i]+60>carY) {

        if (carX<picX[i]+58 && picX[i]<carX+48) //2cm

        {///車碰到三角錐

          score-=10;

         picY[i]=-150;

        }

      }

    }

    textSize(50);

    text(score,50, 100);

  }

  if (score==0)

  {

    h=1;

    image(die, -35, 100, 600, 350);

  }

}

void keyPressed() {

  if (keyCode == ENTER)

  {

    h=0;

    score=50;

  }

}

arduino

void setup()

{

  pinMode(2, INPUT_PULLUP);//拉高的Input

  Serial.begin(9600);//開始設定USB的傳輸速度

}

void loop() {//1000Hz (1000 fps)

  int x = analogRead(A0);//0...1023

  //int y = analogRead(A1);//0...1023

 // int sw= digitalRead(2);//HIGH(放開)

  Serial.write (x/4);//第1個byte

  //Serial.write(y/4);//第2個byte

  //Serial.write (sw); //第3個byte

  delay(20);//1000ms/20ms => 50fps,變慢了

}












__________________________________________________________________








processing

 import processing.serial.*;////

Serial myPort;////

int count=1800;

PImage candy;

PImage monster;

PImage bg;

PImage die;

PImage heart;

float [] candyX=new float[10];

float [] candyY=new float[10];

float monsterX=235, monsterY=450;

int score=150;

int h=0;

void setup() {

  size(513, 615);

  myPort = new Serial(this, "COM3", 9600);////

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

    candyX[i] = random(70, 295);

    candyY[i] = -i*100;

  }

  candy = loadImage("candy.png");///三角椎

  monster = loadImage("monster.png");

  bg = loadImage("bg.jpg");

  die =loadImage("die.png");

}

float vx=0;

//float vy=0;

void draw() {

  if (h==0) {

    image(bg, 0, 0, 513, 615);

    //background(255);

    //monsterX=mouseX-47;

    while (myPort.available()>=1)

    {

      int x = myPort.read();

      ///int y = myPort.read();

      //int sw = myPort.read();

      vx= (x-128)/32;

      // vy=(y-128)/32;

      println(vx);

      //monsterY=y;

    }

    monsterX += vx;

    // monsterY += vy;

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

      image(candy, candyX[i], candyY[i], 60, 60);

      candyY[i]+=2;

      if (candyY[i]>615)

      {

        candyY[i]=-300;  //-183

        candyX[i]=random(70, 295);///三角錐重生

      }

      if (candyY[i]+60>monsterY) {

        if (monsterX<candyX[i]+58 && candyX[i]<monsterX+48) //2cm

        {///車碰到三角錐

          score+=10;

          candyY[i]=-150;

        }

      }

    }

    if (count<0) {

      background(0, 0, 0);

      h=1;

    } else {

      count--;

    }

    textSize(50);

    fill(25, 25, 250, 250);

    text("Time: "+int(count/60), 250, 50);

    textSize(50);

    text(score, 50, 100);

  }

  if (count<0 || score<1000)

  {

    h=1;

    image(die, -35, 100, 600, 350);

  }

}

void keyPressed() {

  count=1800;

  if (keyCode == ENTER)

  {

    h=0;

    score=150;

  }

}


arduino

void setup()

{

  pinMode(2, INPUT_PULLUP);//拉高的Input

  Serial.begin(9600);//開始設定USB的傳輸速度

}

void loop() {//1000Hz (1000 fps)

  int x = analogRead(A0);//0...1023

  //int y = analogRead(A1);//0...1023

 // int sw= digitalRead(2);//HIGH(放開)

  Serial.write (x/4);//第1個byte

  //Serial.write(y/4);//第2個byte

  //Serial.write (sw); //第3個byte

  delay(20);//1000ms/20ms => 50fps,變慢了

}

2020年12月21日 星期一

🗿week15


 

圖片

//int a=10

size(600,600);

PImage img=loadImage("img.jpg");

PVector pt=new ector(10 , 20, 0);

image(img ,0 ,0);

println(pt.x);5

//以前要用的時候

float userX=10,userY=20,userZ=0;

float user2X=30,user2Y=40,user2Z=0;

//現在可以用的物件,來讓他有條理

PVector user=new PVector(10,20,0);

PVector user2=new PVector(10,20,0);

_______________________________________________________________________

arduino

void setup() {

  // put your setup code here, to run once:

  pinMode(2,INPUT_PULLUP);

  Serial.begin(9600);

}


void loop() {

  // put your main code here, to run repeatedly:

  int x=analogRead(A0);

  int y=analogRead(A1);

  int sw=digitalRead(2);


  Serial.write(x/4);

  Serial.write(y/4);

  Serial.write(sw);

  delay(20);  

}

processing

PVector user;

PVector Y,v=null;

void setup(){

    size(600,600);

    user = new PVector(100,300.);

    Y=new PVector(100,300);

}

void draw(){

  background(255);

  line(user.x,user.y,Y.x,Y.y);

  textSize(40);

  fill(255,0,0); text("Y",Y.x,Y.y);

  fill(255); ellipse(user.x, user.y,20,20);

  if(v!=null) user.add(v);

}

void mouseReleased(){

  PVector diff = PVector.sub(Y,user);

  v = diff.div(10);

}___________________________________________________



processing

import processing.serial.*;

Serial myPort;

void setup(){

size(256,256);

myPort = new Serial(this, "COM6",9600);

}

int bal1X=0,bal1Y=0;

void draw()

{

 if(myPort.available()>=3)

 {

   int x = myPort.read();

   int y = myPort.read();

   int sw = myPort.read();

   bal1X=x;

   bal1Y=y;

 }

 ellipse(bal1X,bal1Y,10,10);

}


Arduino程式碼

void setup()

{

  pinMode(2, INPUT_PULLUP);//拉高的Input

  Serial.begin(9600);//開始設定USB的傳輸速度

}

void loop() {//1000Hz (1000 fps)

  int x = analogRead(A0);//0...1023

  int y = analogRead(A1);//0...1023

  int sw= digitalRead(2);//HIGH(放開)

  

  Serial.write (x/4);//第1個byte

  Serial.write(y/4);//第2個byte

  Serial.write (sw); //第3個byte

  delay(20);//1000ms/20ms => 50fps,變慢了

}


2020年12月14日 星期一

🗿Week14


 
搖桿調聲音

void setup() {

  pinMode(2,OUTPUT); //等一下

  pinMode(8,OUTPUT);

  }


void loop() {

  int now = analogRead(A0);

  tone(8,now);

}

中間接A0

左邊接地

右邊接5V


gnd接gnd

5v 5v

vrx a0

vry a1

sw 2

搖桿調燈光

void setup() {
  for(int i=2;i<=13;i++)
  {
   pinMode(8,OUTPUT);
  }
}
void loop() {
  int now = analogRead(A0);
  int level = now/(512/13);
  for(int i=2;i<=13;i++)
  {
      if(i<level)digitalWrite(i,HIGH);
      else digitalWrite(i,LOW);
  }
  }

搖桿調色塊填滿值


ARDUINO

void setup() {
  for(int i=2;i<=13;i++)
  {
   pinMode(8,OUTPUT);
  }
  Serial.begin(9600);
}
void loop() {
  int now = analogRead(A0);
  int level = now/(512/13);
  for(int i=2;i<=13;i++)
  {
      if(i<level)digitalWrite(i,HIGH);
      else digitalWrite(i,LOW);
  }
  Serial.write(('A'+level));
  delay(20);
  }


---------------------------------------------------------------------------------

void setup() {
  for(int i=2;i<=13;i++)
  {
   pinMode(8,OUTPUT);
  }
  Serial.begin(9600);
}
void loop() {
  int now = analogRead(A0);
  //int level = now/(512/13);
  int level = now/4;
  for(int i=2;i<=13;i++)
  {
      if(i<level)digitalWrite(i,HIGH);
      else digitalWrite(i,LOW);
  }
  Serial.write(level);
  delay(20);
  }

PROCESSING

import processing.serial.*;

Serial myPort;

void setup(){

    size(765,100);

    myPort=new Serial(this,"COM6",9600);

}

int level=0;

void draw(){

    background(255);

    fill(255,0,0);

    rect(0,0,level*3,100);

    if(myPort.available()>0)

    {

      int now = myPort.read();

     level=now;

    }
}

🗿Week13


 

2020年11月30日 星期一

🗿 Week12 ( piano )


makeruno github 

MakerUno_DefaultSketch 複製預設程式碼


 #define Do 523
 #define Mi 659
 #define So 784

void setup() {
  pinMode(2,INPUT_PULLUP); //button
  pinMode(8,OUTPUT);
  tone(8,Do); //buzzer一直發出聲音
  delay(1000); //1秒
  tone(8,Mi);
  delay(1000); 
  tone(8,So);
  delay(1000); 
  noTone(8); //靜音
  }

void loop() {
  if (digitalRead(2)==LOW)  tone(8,Mi,100); //button
}



資料傳輸


Arduino(軟體)
 #define Do 523
#define Re 587
#define Mi 659
#define Fa 698
#define So 784
#define La 880
#define Si 988
#define Do2 1047

void setup() {
 
Serial.begin(9600); //USB傳輸的速度(A<=>P要一樣)
  
  pinMode(2,INPUT_PULLUP); //button
  pinMode(8,OUTPUT);
  tone(8,Do); //buzzer一直發出聲音
  delay(1000); //1秒
  tone(8,Re);
  delay(1000);  
  tone(8,Mi);
  delay(1000);
  tone(8,Fa);
  delay(1000);
  tone(8,So);
  delay(1000);
  tone(8,La);
  delay(1000);
  tone(8,Si);
  delay(1000);
  tone(8,Do2);
  delay(1000);
  noTone(8); //靜音
  }

void loop() {
  while( Serial.available()>0){ ///有資料可收送!
    int now = Serial.read();
    if( now=='1') tone(8,Do,100);
    if( now=='2') tone(8,Re,100);
    if( now=='3') tone(8,Mi,100);
    if( now=='4') tone(8,Fa,100);
    if( now=='5') tone(8,So,100);
    if( now=='6') tone(8,La,100);
    if( now=='7') tone(8,Si,100);
    if( now=='8') tone(8,Do2,100);
   }
}

Process (硬體)

import processing.serial.*;
Serial myPort;
void setup() 
{
  size(200, 200);
  myPort = new Serial(this, "COM5", 9600);
}
void draw() {
} 
void keyPressed(){
  if(key=='1') myPort.write("1");
  if(key=='2') myPort.write("2");
  if(key=='3') myPort.write("3");
  if(key=='4') myPort.write("4");
  if(key=='5') myPort.write("5");
  if(key=='6') myPort.write("6");
  if(key=='7') myPort.write("7");
  if(key=='8') myPort.write("8");
}
  
void mousePressed(){
 
myPort.write("1");
}

2020年11月24日 星期二

🗿Week11 ( Maker Uno )




maker uno driver 下載

Maker Uno


 #define Do 523
#define Re 587
#define Mi 659
#define Fa 698
#define So 784

#define BUTTON 2
#define BUZZER 8

int melody[] = {Do,Mi,So,Mi,Do};

int noteDurations[] = {
  10, 10, 10, 10, 10, 10, 10, 10, 10
};

int pin;
int ledArrayHigh;
int ledArrayLow;
boolean mode = false;
boolean buttonPressed = false;

void setup()
{
  delay(1000);
  pinMode(8,OUTPUT);
  for(int i=0; i<5 ; i++)
  {
    tone(8, melody[i] , 100);
    delay(130);
  }
}

void loop()
{

}

2020年11月2日 星期一

🗿Week8




 //pixels[i]可以得到畫面中的每個pixels

PImage img;

void setup()

{

   size(300,200);

   img=loadImage("cloud.png");

}

void draw()

{

   image(img,0,0);

}

void mouseMoved()

{

   loadPixels(); //(1)取得畫布

   for(int i=0;i<width*height; i++)//(2)迴圈

   {

     pixels[i] //(3)取得pixels

   }

}


2020年10月28日 星期三

🗿Week07 (期中作業)



用畫出圓點



size(500,500);
for(int angle=0;angle<360;angle+=30){
  float angle2 = radians(angle); ///弧度
  float x = 100+cos(angle2)*50;
  float y = 100+sin(angle2)*50;
  ellipse(x,y,2,2); //劃出點 大小(2,2)
} 



利用三角函數畫三角形


程式碼:
size(500,500);
beginShape();
for(int angle=0;angle<360;angle+=120){ ///加120度為三角形
  float angle2 = radians(angle);
  float x = 100+cos(angle2)*50;
  float y = 100+sin(angle2)*50;
  vertex(x,y); ///點
}
endShape(CLOSE);


滑鼠旋轉游標,三角形跟著轉


程式碼:
void setup(){
  size(500,500);
}
void draw(){
  //background(255);//清畫面
  beginShape();
  for(int angle=0;angle<360;angle+=120){
    float angle2 = radians(angle+mouseX);
    float x = 100+cos(angle2)*50;
    float y = 100+sin(angle2)*50;
    vertex(x,y);
  }
  endShape(CLOSE);
}


三角形跟著滑鼠移動


程式碼:
void setup(){
  size(500,500);
}
void draw(){
  ///background(255);//清畫面
  beginShape();
  for(int angle=0;angle<360;angle+=120){
    float angle2 = radians(angle+mouseX);
    float x = mouseX+cos(angle2)*50;
    float y = mouseY+sin(angle2)*50;
    vertex(x,y);
  }
  endShape(CLOSE);
}


三角形自己旋轉,滑鼠可以移動它


*1sec = 60frame
程式碼:
void setup(){
  size(500,500);
}
void draw(){
  ///background(255);//清畫面
  beginShape();
  for(int angle=0;angle<360;angle+=120){
    float angle2 = radians(angle+frameCount); ///frameCount=螢幕每秒會跑60次
    float x = mouseX+cos(angle2)*100;
    float y = mouseY+sin(angle2)*100;
    vertex(x,y);
  }
  endShape(CLOSE);
}


接水果遊戲


程式碼:
float [] fruitX=new float[10];
float [] fruitY=new float[10];
float kidX=150,kidY=450;
int score=0;
void setup(){
  size(500,500);
  for(int i=0;i<10;i++){
    fruitX[i] = random(50,450);
    fruitY[i] = -i*100;
   }
}
void draw(){
  background(255);
  rect(kidX,kidY,80,80);
  kidX=mouseX;
  for(int i=0;i<10;i++){
    ellipse(fruitX[i],fruitY[i],60,80);
    fruitY[i]++;
    if(fruitY[i]>kidY){///水果掉夠低
      if(kidX<fruitX[i] && fruitX[i]<kidX+80){///接到水果
        score+=10;///接住了就加分
        fruitY[i]=0;  fruitX[i]=random(50,450);///水果重生
      }else{
        fruitY[i]=0; fruitX[i]=random(50,450);///沒接住,水果重生
      }
    }
  }
}

_______________________________________________________________________

PImage pic;
PImage car;
PImage bg;
PImage die;
float [] picX=new float[10];
float [] picY=new float[10];
float carX=150, carY=450;
int score=0;

void setup() {
  size(513, 615);
  for (int i=0; i<10; i++) {
    picX[i] = random(70, 295);
    picY[i] = -i*100;
    picY[i]--;
  }
  pic = loadImage("pic.png");///三角椎
  car = loadImage("car.png");
  bg = loadImage("bg.png");
  die =loadImage("die.png");
}

void draw() {
  image(bg, 0, 0, 513, 615);
  //background(255);
  image(car, carX, carY, 100, 100);
  carX=mouseX;

  for (int i=0; i<7; i++) {
    image(pic, picX[i], picY[i], 150, 170);
    picY[i]+=1;
    /*if(picY[i]>carY){///三角錐掉夠低
     if(carX<picX[i] && picX[i]<carX+80){///接到三角錐
     score+=10;///接住了就扣分
     picY[i]=0;  picX[i]=random(70,455);///三角錐重生
     }else{
     picY[i]=0; picX[i]=random(70,455);///沒接住,三角錐重生
     }
     }
     */
    if (picY[i]>615)
    {
      picY[i]=-183;  
      picX[i]=random(70, 295);///三角錐重生
    }
    if (picY[i]>carY) {
      if (carX<picX[i] && picX[i]<carX+100) {///車碰到三角錐
        image(die, 0, 0, 513, 615);
      }
    }
  }
}














PImage pic;
PImage car;
PImage bg;
PImage die;
PImage heart;
float [] picX=new float[10];
float [] picY=new float[10];
float carX=150, carY=450;
int score=50;
int h=0;

void setup() {

  size(513, 615);
  for (int i=0; i<10; i++) {
    picX[i] = random(70, 295);
    picY[i] = -i*100;
  }
  pic = loadImage("pic.png");///三角椎
  car = loadImage("car.png");
  bg = loadImage("bg.png");
  die =loadImage("die.png");
}

void draw() {
  if (h==0) {
    image(bg, 0, 0, 513, 615);
    //background(255);
    carX=mouseX-47;
    image(car, carX, carY, 50, 100);



    for (int i=0; i<7; i++) {
      image(pic, picX[i], picY[i], 60, 60);
      picY[i]+=2;
      if (picY[i]>615)
      {
        picY[i]=-183;  
        picX[i]=random(70, 295);///三角錐重生
      }
      if (picY[i]+60>carY) {
        if (carX<picX[i]+58 && picX[i]<carX+48) //2cm
        {///車碰到三角錐
          score-=10;
         picY[i]=-150;
        }
      }
    }
    textSize(50);
    text(score,50, 100);
  }
  if (score==0)
  {
    h=1;
    image(die, -35, 100, 600, 350);
  }
}
void keyPressed() {
  if (keyCode == ENTER)
  {
    h=0;
    score=50;
  }
}

______________________________________________