顯示具有 04162673_劉紫萱 標籤的文章。 顯示所有文章
顯示具有 04162673_劉紫萱 標籤的文章。 顯示所有文章

2018年1月22日 星期一

Week17

week17 程式碼還沒加arduino

 主程式碼:

import processing.serial.*;
import ddf.minim.*;
Minim minim;
AudioPlayer player1;
Serial myPort;
int val;
PImage []img = new PImage[10];
PImage[] air = new PImage[7];
PImage target;
PImage target1;
PImage back;
float []airx = new float [3];
float []airy = new float [3];
float px[] = new float [10];
float py[] = new float [10];

int count=0;
int timer=3051;
float movex=0, movey=0;
float speedx=5,speedy=5;
float movex1=700, movey1=0;
float speedx1=10,speedy1=10;

boolean air0xy = true;
boolean air1xy = true;
boolean air2xy = true;

boolean pig0 = true;
boolean pig1 = true;
boolean pig2 = true;
boolean pig3 = true;
boolean pig4 = true;

boolean t = true;
void setup()
{
  size(700,500);
  minim = new Minim(this);
  player1 = minim.loadFile("sound.mp3");
 
    target = loadImage("target.png");
    target1 = loadImage("target2.png");
    air[0] = loadImage("5.png");
    air[1] = loadImage("5.png"); 
    air[2] = loadImage("5.png");
    img[0] = loadImage("1.png");
    img[1] = loadImage("2.png");
    img[2] = loadImage("3.png");
    img[3] = loadImage("4.png");
    img[4] = loadImage("4.png");
    back = loadImage("a.jpg");
    px[0] = 200;
    px[1] = 300;
    px[2] = 250;
    px[3] = 250;
    px[4] = 250;
    py[0] = 250;
    py[1] = 320;
    py[2] = 400;
    py[3] = 450;
    py[4] = 250;
     
    airx[0] = 500;
    airy[0] = 150;
    airx[1] = 700;
    airy[1] = 70;
    airx[2] = 550;
    airy[2] = 100;
    //myPort = new Serial(this,"COM6",115200);
}

void draw()
{
  if(timer>10)
  {
  // player1.play();
   timer-=2.5;
   background(220);
   image(back,350,250,width,height);
   imageMode(CENTER);
   textSize(32);
   fill(#AA0202);
   text("Count:"+int(count),450,50);
   text("Time:"+int(timer/60),40,50);
   textSize(25);
   fill(#AA0202);
   airxy();
   pig();
   move();
   image(target,movex,movey,60,60);
   image(target1,movex1,movey1,40,40);
  }
  else end();
}

void move()
{
  movex = movex+speedx;
  movey = movey+speedy;
  movex1 = movex1+speedx1;
  movey1 = movey1+speedy1;
  if(dist(movex,movey,movex1,movey1)<51){
    speedx = speedx*-1;
    speedy = speedy*-1;
    speedx1 = speedx1*-1;
    speedy1 = speedy1*-1;
  }
 
  if(movex>640){
    speedx = -15;
  }
  if(movex<40){
    speedx = 15;
  }
  if(movey>440){
    speedy = -15;
  }
  if(movey<40){
    speedy = 15;
  }
   if(movex1>660){
    speedx1 = -10;
  }
  if(movex1<40){
    speedx1 = 10;
  }
  if(movey1>460){
    speedy1 = -10;
  }
  if(movey1<40){
    speedy1 = 10;
  }
}

void end()
{
  background(0);

   textSize(100);
   fill(255);
   text("Score  "+int(count),50,50);


   fill(255,50,100);
   textSize(100);
   text("END",0,500);

}

void keyPressed(){
  timer=3051;
  count=0;
}

void airxy()
{
     if(air0xy)
  {
      airx[0]-=20;
      image(air[0],airx[0],airy[0],180,180);
  }
 
     if(air1xy)
  {
      airx[1]-=15;
      image(air[1],airx[1],airy[1],150,150);
  }
 
     if(air2xy)
  {
      airx[2]-=10;
      image(air[2],airx[2],airy[2],120,120);
  }
 
  if(airx[0]<-150){
    airx[0]=700;
  }
  if(airx[1]<-150){
    airx[1]=1000;
  }
  if(airx[2]<-200){
    airx[2]=750;
  }
  if(myPort.available()>0){
    int pin2 = myPort.read();
    println(pin2);
  if(dist(movex,movey,airx[0],airy[0])<30 && mousePressed){
   air0xy=false;
  }
  if(dist(movex,movey,airx[1],airy[1])<30 && mousePressed){
   air1xy=false;
  }
  if(dist(movex,movey,airx[2],airy[2])<30 && mousePressed){
   air2xy=false;
  }
 
   if(dist(movex1,movey1,airx[0],airy[0])<30 && mousePressed){
   air0xy=false;
  }
  if(dist(movex1,movey1,airx[1],airy[1])<30 && mousePressed){
   air1xy=false;
  }
  if(dist(movex1,movey1,airx[2],airy[2])<30 && mousePressed){
   air2xy=false;
  }
    if(pin2>0 && air0xy==false)
  {
    air0xy=true;
    airx[0] = 1000;
    airy[0] = 150;
    count++;
  }
   if(pin2>0 && air1xy==false)
  {
    air1xy=true;
    airx[1] = 1000;
    airy[1] = 70;
    count++;
  }
   if(pin2>0 && air2xy==false)
  {
    air2xy=true;
    airx[2] = 1000;
    airy[2] = 100;
    count++;
    }
  }
 

 
}

void pig()
{
    if(pig0)
  {
    image(img[0],px[0],py[0],100,100);
  }
  if(pig1)
  {
    image(img[1],px[1],py[1],80,80);
  }
  if(pig2)
  {
    image(img[2],px[2],py[2],150,150);
  }
  if(pig3)
  {
    image(img[3],px[3],py[3],150,150);
  }
  if(pig4)
  {
    image(img[4],px[4],py[4],150,150);
  }
  if(myPort.available()>0){
    int pin2 = myPort.read();
  if(dist(movex,movey,px[0],py[0])<50 && mousePressed){
    pig0 = false;
  }
  if(dist(movex,movey,px[1],py[1])<50 && mousePressed{
    pig1 = false;
  }
  if(dist(movex,movey,px[2],py[2])<50 && mousePressed){
    pig2 = false;
  }
  if(dist(movex,movey,px[3],py[3])<50 && mousePressed){
    pig3 = false;
  }
  if(dist(movex,movey,px[4],py[4])<50 && mousePressed){
    pig4 = false;
  }
 
   if(dist(movex1,movey1,px[0],py[0])<50 && mousePressed){
    pig0 = false;
  }
  if(dist(movex1,movey1,px[1],py[1])<50 && mousePressed){
    pig1 = false;
  }
  if(dist(movex1,movey1,px[2],py[2])<50 && mousePressed){
    pig2 = false;
  }
  if(dist(movex1,movey1,px[3],py[3])<50 && mousePressed){
    pig3 = false;
  }
  if(dist(movex1,movey1,px[4],py[4])<50 &&mousePressed{
    pig4 = false;
  }
 
  if(pig0==false&&mousePressed)
  {
    pig0=true;
    px[0] = random(40,650);
    py[0] = random(250,300);
    count++;
  }
    if(pig1==false&&mousePressed)
  {
    pig1=true;
    px[1] = random(40,650);
    py[1] = random(300,350);
    count++;
  }
    if(pig2==false&&mousePressed)
  {
    pig2=true;
    px[2] = random(40,650);
    py[2] = random(350,400);
    count++;
  }
   if(pig3==false&&mousePressed)
  {
    pig3=true;
    px[3] = random(75,625);
    py[3] = random(400,425);
    count++;
  }
   if(pig4==false&&mousePressed)
  {
    pig4=true;
    px[4] = random(75,625);
    py[4] = random(400,425);
    count++;
    }
  }
 
}

Week18

processing : 完成品 打靶
youtube:打靶


import processing.serial.*;
import ddf.minim.*;
Minim minim;
AudioPlayer player1;
Serial myPort;
int val;
PImage []img = new PImage[10];
PImage[] air = new PImage[7];
PImage target;
PImage target1;
PImage back;
float []airx = new float [3];
float []airy = new float [3];
float px[] = new float [10];
float py[] = new float [10];

int count=0;
int timer=3051;
float movex=0, movey=0;
float speedx=5,speedy=5;
float movex1=700, movey1=0;
float speedx1=10,speedy1=10;

boolean air0xy = true;
boolean air1xy = true;
boolean air2xy = true;

boolean pig0 = true;
boolean pig1 = true;
boolean pig2 = true;
boolean pig3 = true;
boolean pig4 = true;

boolean t = true;
void setup()
{
  size(700,500);
  minim = new Minim(this);
  player1 = minim.loadFile("sound.mp3");

    target = loadImage("target.png");
    target1 = loadImage("target2.png");
    air[0] = loadImage("5.png");
    air[1] = loadImage("5.png");
    air[2] = loadImage("5.png");
    img[0] = loadImage("1.png");
    img[1] = loadImage("2.png");
    img[2] = loadImage("3.png");
    img[3] = loadImage("4.png");
    img[4] = loadImage("4.png");
    back = loadImage("a.jpg");
    px[0] = 200;
    px[1] = 300;
    px[2] = 250;
    px[3] = 250;
    px[4] = 250;
    py[0] = 250;
    py[1] = 320;
    py[2] = 400;
    py[3] = 450;
    py[4] = 250;
     
    airx[0] = 500;
    airy[0] = 150;
    airx[1] = 700;
    airy[1] = 70;
    airx[2] = 550;
    airy[2] = 100;
    myPort = new Serial(this,"COM6",115200);
}

void draw()
{
  if(timer>10)
  {
   player1.play();
   timer-=2.5;
   background(220);
   image(back,350,250,width,height);
   imageMode(CENTER);
   textSize(32);
   fill(#AA0202);
   text("Count:"+int(count),450,50);
   text("Time:"+int(timer/60),40,50);
   textSize(25);
   fill(#AA0202);
   airxy();
   pig();
   move();
   image(target,movex,movey,60,60);
   image(target1,movex1,movey1,40,40);
  }
  else end();
}

void move()
{
  movex = movex+speedx;
  movey = movey+speedy;
  movex1 = movex1+speedx1;
  movey1 = movey1+speedy1;
  if(dist(movex,movey,movex1,movey1)<51){
    speedx = speedx*-1;
    speedy = speedy*-1;
    speedx1 = speedx1*-1;
    speedy1 = speedy1*-1;
  }

  if(movex>640){
    speedx = -15;
  }
  if(movex<40){
    speedx = 15;
  }
  if(movey>440){
    speedy = -15;
  }
  if(movey<40){
    speedy = 15;
  }
   if(movex1>660){
    speedx1 = -10;
  }
  if(movex1<40){
    speedx1 = 10;
  }
  if(movey1>460){
    speedy1 = -10;
  }
  if(movey1<40){
    speedy1 = 10;
  }
}

void end()
{
  background(0);

   textSize(100);
   fill(255);
   text("Score  "+int(count),50,50);


   fill(255,50,100);
   textSize(100);
   text("END",0,500);

}

void keyPressed(){
  timer=3051;
  count=0;
}

airplane:
void airxy()
{
     if(air0xy)
  {
      airx[0]-=20;
      image(air[0],airx[0],airy[0],180,180);
  }

     if(air1xy)
  {
      airx[1]-=15;
      image(air[1],airx[1],airy[1],150,150);
  }

     if(air2xy)
  {
      airx[2]-=10;
      image(air[2],airx[2],airy[2],120,120);
  }

  if(airx[0]<-150){
    airx[0]=700;
  }
  if(airx[1]<-150){
    airx[1]=1000;
  }
  if(airx[2]<-200){
    airx[2]=750;
  }
  if(myPort.available()>0){
    int pin2 = myPort.read();
    println(pin2);
  if(dist(movex,movey,airx[0],airy[0])<30 && pin2>0){
   air0xy=false;
  }
  if(dist(movex,movey,airx[1],airy[1])<30 && pin2>0){
   air1xy=false;
  }
  if(dist(movex,movey,airx[2],airy[2])<30 && pin2>0){
   air2xy=false;
  }

   if(dist(movex1,movey1,airx[0],airy[0])<30 && pin2>0){
   air0xy=false;
  }
  if(dist(movex1,movey1,airx[1],airy[1])<30 && pin2>0){
   air1xy=false;
  }
  if(dist(movex1,movey1,airx[2],airy[2])<30 && pin2>0){
   air2xy=false;
  }
    if(pin2>0 && air0xy==false)
  {
    air0xy=true;
    airx[0] = 1000;
    airy[0] = 150;
    count++;
  }
   if(pin2>0 && air1xy==false)
  {
    air1xy=true;
    airx[1] = 1000;
    airy[1] = 70;
    count++;
  }
   if(pin2>0 && air2xy==false)
  {
    air2xy=true;
    airx[2] = 1000;
    airy[2] = 100;
    count++;
    }
  }



}

pig:

void pig()
{
    if(pig0)
  {
    image(img[0],px[0],py[0],100,100);
  }
  if(pig1)
  {
    image(img[1],px[1],py[1],80,80);
  }
  if(pig2)
  {
    image(img[2],px[2],py[2],150,150);
  }
  if(pig3)
  {
    image(img[3],px[3],py[3],150,150);
  }
  if(pig4)
  {
    image(img[4],px[4],py[4],150,150);
  }
  if(myPort.available()>0){
    int pin2 = myPort.read();
  if(dist(movex,movey,px[0],py[0])<50 && pin2>0){
    pig0 = false;
  }
  if(dist(movex,movey,px[1],py[1])<50 && pin2>0){
    pig1 = false;
  }
  if(dist(movex,movey,px[2],py[2])<50 && pin2>0){
    pig2 = false;
  }
  if(dist(movex,movey,px[3],py[3])<50 && pin2>0){
    pig3 = false;
  }
  if(dist(movex,movey,px[4],py[4])<50 && pin2>0){
    pig4 = false;
  }

   if(dist(movex1,movey1,px[0],py[0])<50 && pin2>0){
    pig0 = false;
  }
  if(dist(movex1,movey1,px[1],py[1])<50 && pin2>0){
    pig1 = false;
  }
  if(dist(movex1,movey1,px[2],py[2])<50 && pin2>0){
    pig2 = false;
  }
  if(dist(movex1,movey1,px[3],py[3])<50 && pin2>0){
    pig3 = false;
  }
  if(dist(movex1,movey1,px[4],py[4])<50 && pin2>0){
    pig4 = false;
  }

  if(pig0==false&&pin2>0)
  {
    pig0=true;
    px[0] = random(40,650);
    py[0] = random(250,300);
    count++;
  }
    if(pig1==false&&pin2>0)
  {
    pig1=true;
    px[1] = random(40,650);
    py[1] = random(300,350);
    count++;
  }
    if(pig2==false&&pin2>0)
  {
    pig2=true;
    px[2] = random(40,650);
    py[2] = random(350,400);
    count++;
  }
   if(pig3==false&&pin2>0)
  {
    pig3=true;
    px[3] = random(75,625);
    py[3] = random(400,425);
    count++;
  }
   if(pig4==false&&pin2>0)
  {
    pig4=true;
    px[4] = random(75,625);
    py[4] = random(400,425);
    count++;
    }
  }

}

arduino:
static int ledStatus;
static unsigned long lastDebounceTime;
#define DEBOUNCE_DELAY 200

void setup(){
  Serial.begin(115200);
  pinMode(2, INPUT);
  pinMode(13, OUTPUT);

  ledStatus = LOW;
  digitalWrite(13, ledStatus);
}

void updateLed(){
  unsigned long currentTime = millis();
  if((currentTime - lastDebounceTime) > DEBOUNCE_DELAY){
    lastDebounceTime = currentTime;
 
    ledStatus = ledStatus == HIGH ? LOW : HIGH;
    digitalWrite(13, ledStatus);
    Serial.println(ledStatus);
  }
}

void loop(){
  int switchStatus = digitalRead(2);

  if(switchStatus == HIGH){
    updateLed();
  }
}

2017年11月21日 星期二

week02-


mspaint code:

void setup(){
  size(800,600);
  rect(width-100,0,width,height);
  rect(0,0,100,height);
  colorMode(HSB,100);
}
void draw(){
  if(mousePressed) line(mouseX,mouseY,pmouseX,pmouseY);
}
void mouseDragged(){
  if(mouseX<100){///strokeWeight()
    strokeWeight(mouseY/50);
  }
  if(mouseX>width-100){///stroke()
    stroke(mouseY/6.0,100,100);
  }
}



void setup() {
  size(720,720);
}
void draw(){
  
}
void mouseDragged(){
  ellipse(mouseX, mouseY, 100,100);
} 





week04

用array 宣告豬

PImage img1,img2;
float mmx=400,mmy=300;
float mmvx=0,mmvy=0;
float mmax=0, mmay=0;

float [][]mm2x=new float [5][4];
float [][]mm2y=new float [5][4];
boolean [][]mm2alive=new boolean[5][4];
void setup()
{
  size(800,600);
  img1 = loadImage("earth.png");
  img2 = loadImage("wall3.jpg");
  imageMode(CENTER);
  for(int i=0;i<5 ;i++)
  {
    for(int j=0;j<4;j++)
    {
      mm2x[i][j]=700-i*100;
      mm2y[i][j]=100+j*100;
      mm2alive[i][j]=true;
    }
   }
}
音樂

在processing libaray download sound package
search "sound" 
import ddf.minim.*;
Minim minim; 
AudioPlayer player; 
void setup(){ 
Minim = new Minim(this); 
player = minim.loadFile;
; player.loop(); 
}




week08

期中作業製作

加入3D sphere  texture
還有球彈跳 跟反彈限制



背景貼圖 營造出空間感




PImage earth;
PShape go;

float ballvx = 0;
float ballvy = 0;
float ballvz= 0;
float ballx = 0;
float bally = 0;
float ballz = 1;

PImage floor;
PImage front;
PImage ceil;
PImage left;
PImage right;
PImage stop;
boolean fly=true;

int z=1;
int angle=0;

void setup()
{
  size(500,500,P3D);
  earth = loadImage("earth.png");
  floor = loadImage("floor.jpg");
  front = loadImage("front.jpg");
  left = loadImage("left.jpg");
  right = loadImage("right.jpg");
  ceil = loadImage("ceil4.jpg");
  stop = loadImage("us2.png");
  noStroke();
  go = createShape(SPHERE,50);
  go.setTexture(earth);
  background(255);
  smooth();
}

void draw()
{
   background(255,255,255);
   background();

   pushMatrix();
  lights();
  shapeMode(CENTER);
  translate(ballx,bally,-ballz);
  shape(go);
  popMatrix();

  if(fly)
  {
      ballvy +=1;
      ballvx *=0.9975;
      ballx += ballvx;
      bally += ballvy;
      ballz += (ballvz*z);

  }

  if (ballx > width-10)
  {
    ballx=width-10;
    ballvx=-ballvx;
  }

// changing directions after hitting the left wall
  if (ballx<80)
  {
    ballx=80; 
    ballvx=-ballvx;
  }

// loosing height after each bounce
  if (bally > height-20)
  {
    bally=height-5;
    ballvy = -ballvy*0.98;
  }

// slow the ball down faster when it is rolling.
  if (bally > height-19)
  {
    ballvx *=0.5;
  }

  if(ballz>300 )
  {
    z*=-1;
    ballvz-=0.5;
 
  }
  if(ballz<0)
  {
    ballz=0;
  }

   // zPosition=300;
   //
   // print(zPosition+"\n");



}

// re-throw the ball
void mouseDragged()
{
 // xPosition = mouseX;
 //yPosition = mouseY;
  ballvx += (mouseX - pmouseX)/8;
  ballvy += (mouseY - pmouseY)/8;

}

void mouseReleased()
{
 ballvz+=1;
}

背景部分程式碼:


void background()
{

 pushMatrix();
  beginShape();
      texture(front);
      vertex(0, 0, -300,0, 0);
      vertex(500, 0, -300,618, 0);
      vertex(500, 500,-300, 618, 258);
      vertex(0, 500, -300,0, 258);
  endShape();
 popMatrix();

 pushMatrix();
      beginShape();
      texture(stop);
      vertex(140, 5, -295,0, 0);
      vertex(370, 5, -295,800, 0);
      vertex(370, 155,-295, 800, 800);
      vertex(140, 155, -295,0, 800);
      endShape();
 popMatrix();


 pushMatrix();
  beginShape();
   texture(left);//left
  vertex(0, 0, 0,0, 0);
  vertex(0, 0, -300,618, 0);
  vertex(0, 500, -300,618, 258);
  vertex(0, 500,0, 0, 258);
  endShape();
 popMatrix();

 pushMatrix();
  beginShape();
    texture(right); //right
    vertex(500, 0,   0, 0, 0);
    vertex(500, 0, -300,618, 0);
    vertex(500, 500, -300,618, 258);
    vertex(500, 500,0, 0, 258);
  endShape();
 popMatrix();

 pushMatrix();
  beginShape(); //ceil
    texture(ceil);
    vertex(0, 0, 0,532, 0);
    vertex(500, 0, 0,0, 0);
    vertex(500, 0, -300,0, 214);
    vertex(0, 0,-300, 532, 214);
 
 
 
  endShape();
 popMatrix();

 pushMatrix();
  beginShape();
    texture(floor);//floor
    vertex(500, 500,0, 618, 0);
    vertex(500, 500, -300,618, 258);
    vertex(0, 500, -300,0, 258);
    vertex(0, 500, 0,0,0);
  endShape();
 popMatrix();

 pushMatrix();
    beginShape();
    translate(328, 115,-270);
    scale(1.85,1.8,2);
    endShape();
 popMatrix();


}



week7

開始製作 3D投籃球

float ballx=0,bally=0,ballz=0;
float ballvx=0, ballvy=0,ballvz=0;
boolean ballfly=false;
void setup()
{
  size(500,500,P3D);
}

void draw()
{
 background(255);
 translate(width/2,height/2);
lights();
pushMartix();
translate(ballx,bally,ballz);
noStroke(); shpere(100);
popMartix();
if(ballyfly)
{
ballx+=ballvx;  bally+=ballvy;ballz+=ballvz; ballvy=0.98;
}
}

void mouseDragged()
{
ballvx+= mouseX-pmouseX;
ballvy+=mouseY-pmouseY;
}
void mouseReleased()
{
  ballfly=true;
  ballvz-=30;
}


Week10-期中作業

04162673 劉紫萱

期中作品:投籃球






Youtube:https://youtu.be/fhjtv52q26Q

遊戲規則: 倒數60秒 看能投進幾顆

2017年10月23日 星期一

Week06-爆爆王

爆爆王

void setup()
{
  size(850,500);
}
int userJ=9 , userI=5;
float userX, userY;
int waterN=0;
int []waterJ= new int[100];
int []waterI= new int[100];
void draw()
{
  background(#92AD28);
  noStroke();
  for(int i=0;i<10;i++)
  {
    for(int j=0;j<17;j++){
      if((j-i)%2==0) fill(#7E9819);
      else fill(#92AD28);
      rect(j*50,i*50,50,50);
    }
  }
 
  fill(#F20736); ellipse(userJ*50+25,userI*50+25,50,50);
 
  for(int i=0;i<waterN;i++){
    fill(#07ECF2); ellipse(waterJ[i]*50+25,waterI[i]*50+25,30,30);
  }
}

void keyPressed()
{
  if(keyCode==LEFT) userJ--;
  if(keyCode==RIGHT) userJ++;
  if(keyCode==UP)userI--;
  if(keyCode==DOWN)userI++;
  if(keyCode==' '){
    waterI[waterN]=userI; waterJ[waterN]=userJ;waterN++;
  }
 
}




鱷魚


2017年10月16日 星期一

Week05- xeyes

Xeyes:

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

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

}




抱抱龍射擊遊戲
//只能發射一顆而且會跟著mouse moving
void setup()
{
  size (400,800);
}
float ballX=200,ballY=600;
float ballVX=0, ballVY=0;
float angle=0;

void draw()
{
  background(128);
  fill(#FA9703);
  ellipse (200,600,100,100);
  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(128);
  fill(#FA9703);
  ellipse (200,600,100,100);
  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月2日 星期一

Week03-angry bird

1. 重力加速度
angry bird code:

PImage imgBird, imgPig;
void setup(){
  size(800,600);
  imgBird=loadImage("bird.png");
  imgPig=loadImage("ppig.png");
  imageMode(CENTER);  //將小鳥圖放到滑鼠正中央
}
float birdX = 400, birdY = 300; //小鳥位置
float birdVX = 0, birdVY = 0; //小鳥初速度
float birdAX =0, birdAY = 0; //小鳥加速度
void draw(){
  background(255); //將殘影刪除
  image(imgPig, 400, 300, 100, 100); //(圖片, X位置, Y位置, 寬, 長)
  image(imgBird, birdX, birdY, 100, 100);
  line(birdX, birdY, 400,300); //劃線
  birdX += birdVX; //給小鳥速度
  birdY += birdVY; //給小鳥速度
  birdVX += birdAX;//給小鳥加速度
  birdVY += birdAY;//給小鳥加速度
}
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;//Y值的重力加速度
}


2017年9月18日 星期一

week01-mspaint

小畫家製作
step1:開視窗 畫線


step2:畫正方形


step3:use mouseX,mouseY.pmouseX.pmouseY and void setup() ;void draw()

void setup() 只跑一次
line(mouseX.mouseY,pmouseX,pmouseY);
跟著滑鼠畫線,不會停下來...



step4: 更改線顏色,線的粗細



看openprocesssing



Processing for android
教學範例 手機螢光棒