顯示具有 01160296_黃俞華 標籤的文章。 顯示所有文章
顯示具有 01160296_黃俞華 標籤的文章。 顯示所有文章

2015年6月8日 星期一

week16

week16

boolean jump=false;
int pos=2;
float posY=400, VY=0;
void setup(){
  size(400,600);
}
void draw(){
  background(255);
  ellipse(pos*100, posY, 50, 100);
  if(jump){VY=-20; jump=false;}
  posY+=VY; VY+=0.98;
  if(posY>=400) posY=400;
}


void keyPressed(){
  if(key=='1') {pos=1;}
  if(key=='2') {pos=2;}
  if(key=='3') {pos=3;}
  if(key=='5') {jump=true;}
}

boolean jump=false;
int pos=2;
float posY=400, VY=0, distZ=0;
int road[][] = new int[100][3];
void setup(){
  size(400,600,P3D);
  restRoad();
}
void draw(){
  background(255);
    pushMatrix();
    translate(pos*100, posY-20);
    sphere(10);
  popMatrix();
//  ellipse(pos*100, posY, 50, 100);
  if(jump){VY=-20; jump=false;}
  posY+=VY; VY+=0.98;
  if(posY>=400) posY=400;
  translate(0, 400, distZ);
  for(int i=0;i<100;i++){
    for(int j=0;j<3;j++){
      pushMatrix();
        translate(100*j+100,-road[i][j]*0, -i*100);
        scale(1,0.2,1);
        box(100);
      popMatrix();
    }
  }
  distZ+=5;
}


void keyPressed(){
  if(key=='1') {pos=1;}
  if(key=='2') {pos=2;}
  if(key=='3') {pos=3;}
  if(key=='5') {jump=true;}
}
void restRoad(){
  for(int i=0;i<100;i++){
    for(int j=0;j<3;j++){
      road[i][j]=0;
      if(random(10)<1) road[i][j]=-1;
      if(random(8)<1) road[i][j]=2;
      if(random(8)<1) road[i][j]=3;
    }
  }
}

2015年6月1日 星期一

期末構想

改良期中作業
增加刺激感,從控制鳥變控制打擊物

WEEK14




賽車遊戲













PImage imgCar;

float angle =0,dx=0,dy=0,vel=1;
void setup(){
  size(800,600,P3D);
  imgCar = loadImage("car.png");
}
void draw(){
  background(255);
  for(int i =-1;i<=8;i++){
    for(int j=-1;j<=6;j++){
      rect(i*100+dx%100,j*100+dy%100,100,100);
    }
  }
  pushMatrix();
    translate(width/2, height/2);
    rotateZ(angle);
    image(imgCar, -100,-100,200,200);
  popMatrix();
  dx=-vel*cos(angle);
  dy=-vel*sin(angle);
}
void mouseMoved(){
  int x=mouseX-pmouseX;
  int y=mouseY-pmouseY;
  if(x>0) angle+=1/40.0;
  if(x<0) angle-=1/40.0;
}
void keyPressed(){
  if(key=='l')angle++;
  if(key=='r')angle--;
  if(keyCode==UP)vel*=1.1;
  if(keyCode==DOWN)vel*=0.9;
}

2015年5月18日 星期一

import de.voidplus.leapmotion.*;
LeapMotion leap;
void setup(){
  size(600,600,P3D);
  leap = new LeapMotion(this);
}
void draw(){
  background(255);
  for(Hand hand: leap.getHands()){
    hand.draw();
    float angle = hand.getYaw();
    PVector pos = hand.getPosition();
    translate(pos.x, pos.y, pos.z);
    rotateY(-radians(angle));//角度轉徑度
    fill(128); stroke(0); box(100);
  }
}

===

import de.voidplus.leapmotion.*;
LeapMotion leap;
void setup(){
  size(600,600,P3D);
  leap = new LeapMotion(this);
}
float groundDir=0; //ground direction地板的方向
void draw(){
  background(255);
  for(int i=-10; i<=10; i++){
    for(int j=-10;j<=10;j++){
      pushMatrix();
        translate(300, 300);
        rotateX(radians(70));
        rotateZ(radians(groundDir));
        translate(i*30, j*30);
        box(30);
      popMatrix();
    }
  }
  for(Hand hand: leap.getHands()){
    hand.draw();
    float angle = hand.getYaw();
    PVector pos = hand.getPosition();
    translate(pos.x, pos.y, pos.z);
    rotateY(-radians(angle));
    fill(128); stroke(0); box(100);
    groundDir= -angle;
  }
}
import de.voidplus.leapmotion.*;
LeapMotion leap;
void setup(){
  size(600,600,P3D);
  leap=new LeapMotion(this);
}
void draw(){
  background(255);
  for(Hand hand: leap.getHands()){
    hand.draw();
    myDraw(hand.getPosition());//手掌
    myDraw(hand.getThumb().getPosition());//拇指
    myDraw(hand.getIndexFinger().getPosition());//食指
    myDraw(hand.getMiddleFinger().getPosition());//中指
    myDraw(hand.getRingFinger().getPosition());//無名指
    myDraw(hand.getPinkyFinger().getPosition());//小指
    /*用函式代替下面的東西*/
    /*PVector pos=hand.getPosition();
    translate(pos.x,pos.y);
    fill(255,0,0); box(100);*/
    }
}
void myDraw(PVector pos){//設一個函式把動作包起來
  pushMatrix();
    translate(pos.x,pos.y);
    fill(255,0,0); sphere(20);//畫一顆球
  popMatrix();//跟圖學一樣用push、pop保護起來
}
import SimpleOpenNI.*; SimpleOpenNI openni; PImage imgBG; PGraphics imgMask; void setup() { size(1366, 737); openni = new SimpleOpenNI(this); openni.enableRGB(); openni.enableDepth(); openni.enableUser(); imgBG=loadImage("cute.jpg"); imgBG.resize(1366,737); imgMask=createGraphics(1366, 737); imgMask.beginDraw(); imgMask.background(0); imgMask.endDraw(); //imgMask.loadPixels(); /*for(int i=0;i<1366*737;i++) { imgMask.pixels[i]=color(0,0,255,80); } imgMask.updatePixels();*/ } void draw() { imgBG.mask(imgMask); image(imgBG,0,0); println(frameCount); openni.update(); image(openni.userImage(), 0, 0, 128,96); //image(imgMask,0,0); int[] userList = openni.getUsers(); imgMask.beginDraw(); imgMask.noStroke(); imgMask.fill(255); for(int i = 0;i<userList.length;i++) { if(openni.isTrackingSkeleton(userList[i])){ PVector pos = new PVector(); openni.getJointPositionSkeleton(userList[i],SimpleOpenNI.SKEL_RIGHT_HAND, pos); imgMask.ellipse(320+pos.x/3, 240-pos.y/3, 50,50); } } imgMask.endDraw(); } void onNewUser(SimpleOpenNI curContext, int userId) { curContext.startTrackingSkeleton(userId); }
碰撞測試



import de.voidplus.leapmotion.*;
LeapMotion leap; PVector pos[]=new PVector[10]; void setup(){ size(600,600, P3D); leap = new LeapMotion(this); for(int i=0;i<10;i++) pos[i] = new PVector(60*i,-random(600)); } int grade=0; float grabX=0, grabY=0; void draw(){ background(128); for(int i=0;i<10;i++){ ellipse(pos[i].x,pos[i].y,50,50); pos[i].y+=3; if(pos[i].y>600) pos[i].y=-random(300); if(dist(grabX,grabY,pos[i].x,pos[i].y)<100) {fill(255,0,0);pos[i].y=-random(300);grade+=1000;} else fill(255); } for(Hand hand : leap.getHands()){ if(hand.isRight()){ grabX=hand.getPosition().x; grabY=hand.getPosition().y; } } rect(grabX,grabY,100,100); textSize(60);fill(255,0,0); text("Score:"+grade,100,100); }
import SimpleOpenNI.*;
SimpleOpenNI openni;
class Fruit{
  float X,Y,VX,VY;
  Fruit(float x, float y, float vx, float vy){
    X=x; Y=y; VX=vx; VY=vy;
  }
  void draw(){
    ellipse(X,Y,50,50);
  }
  void update(){
    X+=VX; Y+=VY; VY+=1.98;
    if(X<-100 || X>740 || Y<-100 || Y>580){
      X=random(640); Y=random(240); VX=random(30)-15; VY=-random(30);
    }
  }
}

Fruit fruit[]= new Fruit[20];
void setup(){
  size(640,480);
  openni = new SimpleOpenNI(this);
  openni.enableDepth();
  openni.enableUser();
  for(int i=0; i<20; i++)
    fruit[i] = new Fruit(random(640), random(240), random(30)-15, -random(30));
}

void draw(){
  openni.update();
  image(openni.userImage(),0,0);
  for(int i=0; i<20; i++){
    fruit[i].draw();
    fruit[i].update();
  }
}

水果

水果

import SimpleOpenNI.*;

SimpleOpenNI openni;

float X, Y, VX, VY;

class Fruit{

Fruit(float x, float y,float vx, float vy){

boolean dead = false;

X=x; Y=x; VX=vx; VY=vy; dead=false;

}

void draw(){

if(dead) fill(255,0,0);

void update(){

else fill(255);

ellipse(X, Y, 50, 50);
}
X=random(640); Y=random(240); VX=random(10)-5; VY=-random(10); dead=false;

X+=VX; Y+=VY; VY+=0.68;

if(X<-100||X>740||Y<-100||Y>580){
}
if(X>0 && X<640 && Y>0 && Y<480 && openni.userImage().pixels[int(X)+int(Y)*640]==color(0,0,255)) dead=true;

if(dist(X,Y,mouseX,mouseY)<50) dead=true;
} } void mouseMoved(){
Fruit fruit[] = new Fruit[20];

strokeWeight(30);stroke(255,0,0);line(mouseX,mouseY,pmouseX, pmouseY);
strokeWeight(1);stroke(0); } void setup(){ size(640,480);
fruit[i] = new Fruit(random(640),random(240),random(30)-15,-random(30));

openni = new SimpleOpenNI(this);
openni.enableDepth();
for(int i=0;i<20;i++)
openni.enableUser(); } void draw(){
}
openni.update(); image(openni.userImage(),0,0);
fruit[i].draw();
for(int i=0;i<20;i++){ fruit[i].update();
}

2015年5月4日 星期一

WEEK11

新的機器
距離太近無法準確偵測
距離遠一點即可準確偵測
以3D方式呈現,用方向鍵可控制方向

2015年4月26日 星期日

取物模型

這段指令,即可用按鍵抓取物模型~

float x1=350,y1=500,x2=350,y2=410,x3=260,y3=500,x4=260,y4=410,x5=160,y5=500;

if (keyPressed == true) {
     if(key == 'z'){
       if( abs(pos.x-x1)<=20 && abs(pos.y-y1)<=20 )
         {
           x1=pos.x;
           y1=pos.y;
           if( abs(x1-r1_x)<=5 && abs(y1-r1_y)<=5)
           {
             need=need-1;
           }
         }
        else if(abs(pos.x-x2)<=20 && abs(pos.y-y2)<=20)
        {
          x2=pos.x;
          y2=pos.y;
          if( abs(x2-r2_x)<=5 && abs(y2-r2_y)<=5)
           {
             need=need-1;
           }
        }
        else if(abs(pos.x-x3)<=20 && abs(pos.y-y3)<=20)
        {
          x3=pos.x;
          y3=pos.y;
          if( abs(x3-r3_x)<=5 && abs(y3-r3_y)<=5)
           {
             need=need-1;
           }
        }
        else if(abs(pos.x-x4)<=20 && abs(pos.y-y4)<=20)
        {
          x4=pos.x;
          y4=pos.y;
          if( abs(x4-r4_x)<=5 && abs(y4-r4_y)<=5)
           {
             need=need-1;
             text(need,20,30);
           }
        }
        else if(abs(pos.x-x5)<=20 && abs(pos.y-y5)<=20)
        {
          x5=pos.x;
          y5=pos.y;
          if( abs(x5-r5_x)<=5 && abs(y5-r5_y)<=5)
           {
             need=need-1;
           }
        }
       }
      }