顯示具有 00163106_李士昌 標籤的文章。 顯示所有文章
顯示具有 00163106_李士昌 標籤的文章。 顯示所有文章

2015年6月29日 星期一

期末作品

running man



這次期末作品是running man

youtube影片連結:https://www.youtube.com/watch?v=XTSJ1hTV5bM&feature=youtu.be
主要的目的是透過體感互動裝置來讓使用者能夠運動

以手模擬跑步的動作來控制球往前移動
進而達到運動的效果

同時也能靠頭部的移動來控制球的左右
還有身體往前傾就能使球停止,有稍作休息的功能

左手上舉超過頸部 就能夠往前移動
同理右手上舉超過頸部 也就能夠往前移動
希望透過體感裝置達到運動的效果

此圖FAAST


此圖:系統實際畫面

這個為實作影片

2015年6月8日 星期一

Week16

boolean jump=false;
int pos=2;
float posY=300, VY=0,distZ=0;
int road[][]=new int [100][3];
void setup(){
  size(400,600,P3D);
  resetRoad();
}
void draw(){
  background(255);
  pushMatrix();
  translate(pos*100, posY-60);
  sphere(50);
  popMatrix();
  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],-i*100);
  scale(1,0.1,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 resetRoad(){
  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;
    }
  }
}

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日 星期一

期末作品 預想

這次期末作品我們打算

利用跑步的動作來做跑步的遊戲

構想是依據TEMPLE RUM這款遊戲為出發(https://www.youtube.com/watch?v=zHsthLPRtBc)

目標是以判斷膝蓋的移動,來控制角色前進,來達到跑步的效果

以及身體的左右移動,來閃避障礙物,

目前的想法是以頭部的移動來控制左右。

2015年5月25日 星期一

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/180);
    image(imgCar, -100, -50, 200, 100);
  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.02;
  if(keyCode==DOWN) vel*=0.98;
  println("Vel:"+vel);
}

2015年5月18日 星期一

week13



import SimpleOpenNI.*;
SimpleOpenNI openni;
class Fruit {
  float X, Y, VX, VY;
  boolean dead = false;
  Fruit(float x, float y, float vx, float vy) {
    X=x;  Y=y;   VX=vx;   VY=vy; dead=false;
  }
  void draw() {
    if(dead) fill(255,0,0);
    else fill(255);
    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(10)-5;  VY=-random(10);
    }
    if(dist(X,Y, mouseX,mouseY)<50) dead = true;
    if(X>0 && X<640 && Y>0 && Y<480 && openni.userImage().pixels[int(X)+int(Y)*640]==color(0,0,255)) dead = true;
  }
}
void mouseMoved(){
  strokeWeight(30); stroke(255,0,0); line(mouseX, mouseY,pmouseX, pmouseY);
  strokeWeight(1); stroke(0);
}
Fruit fruit[] = new Fruit[20];
void setup() {
  size(640, 480);
  openni = new SimpleOpenNI(this);
  openni.enableRGB();
  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() {
  background(255);
  openni.update();
  image(openni.userImage(), 0, 0);
  for (int i=0; i<20; i++) {
    fruit[i].draw();
    fruit[i].update();
  }
}

2015年5月11日 星期一

week12

import SimpleOpenNI.*;
SimpleOpenNI openni;
void setup(){
  size(640,480);
  openni = new SimpleOpenNI(this);
  openni.enableRGB();
  openni.enableDepth();
  openni.enableUser();
}
void draw(){
  background(255);
  openni.update();
  image(openni.userImage(), 0, 0, 640, 480);
  int[] userList = openni.getUsers();
  int i;
  for(i=0;i<userList.length;i++);
  {
    if(openni.isTrackingSkeleton(userList[i])){
      PVector pos = new PVector();
      openni.getJointPositionSkeleton(userList[i], SimpleOpenNI.SKEL_HEAD,pos);
      println(pos);fill(255);ellipse(320+pos.x/3,240-pos.y/3, 50, 50);
    }
  }
}
void onNewUser(SimpleOpenNI curContext, int userId)
{
  curContext.startTrackingSkeleton(userId);
}

 PImage imgBG;
PGraphics imgMask;
void setup(){
  size(640,480);
  imgBG=loadImage("123.jpg");
  imgBG.resize(640,480); imgMask = createGraphics(640,480);
  imgMask.beginDraw();
  imgMask.background(0);
  imgMask.endDraw();
}

void draw(){
  imgBG.mask(imgMask);
  image(imgBG,0,0);
}

void mouseDragged(){
  imgMask.beginDraw();
  imgMask.fill(255);
  imgMask.ellipse(mouseX,mouseY,100,100);
  imgMask.endDraw();
}


import SimpleOpenNI.*;
SimpleOpenNI openni;
PImage imgBG;
PGraphics imgMask;
void setup(){
  size(640,480,P3D);
  openni = new SimpleOpenNI(this);
  openni.enableRGB();
  openni.enableDepth();
  openni.enableUser();
  imgBG=loadImage("123.jpg");
  imgBG.resize(640,480); imgMask = createGraphics(640,480);
  imgMask=createGraphics(640,480);
  imgMask.beginDraw();
  imgMask.background(0);
  imgMask.endDraw();
}
void draw(){
  imgBG.mask(imgMask);
  image(imgBG,0,0);
  println(frameCount);
  openni.update();
  image(openni.userImage(), 0, 0, 64, 48);
  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_HEAD,pos);
      println(pos);ellipse(320+pos.x/3,240-pos.y/3, 50, 50);
    }
  }
  imgMask.endDraw();
}
void onNewUser(SimpleOpenNI curContext, int userId)
{
  curContext.startTrackingSkeleton(userId);
}

2015年4月13日 星期一

week08

import de.voidplus.leapmotion.*;
LeapMotion leap;
PImage imgAcc;
PImage imgBG;
void setup()
{
  size(800,600, P3D);
  imgBG = loadImage("bg.jpg");
  imgBG.resize(800,600);

  imgAcc = loadImage("accurate.png");
  leap = new LeapMotion(this);
}
int countDown = 30;

void draw()
{
  background(imgBG);
  if(countDown==0) background(255,0,0);
  fill(0);textSize(30);text("Time:"+countDown,600,50);
  if(frameCount%60==0 && countDown>0) countDown--;
  for(Hand hand : leap.getHands() ){
    hand.draw();
    myDraw(hand.getIndexFinger().getPosition());
  }
}
void myDraw(PVector pos){
  pushMatrix();
//  fill(255,0,0); sphere(20);
  image(imgAcc,pos.x-50,pos.y-50,100,100);
  popMatrix();
}

2015年3月30日 星期一

week06

import de.voidplus.leapmotion.*;
LeapMotion leap;
PImage imgAcc;
PImage imgBG;
void setup()
{
  size(800,600, P3D);
  imgBG = loadImage("bg.jpg");
  imgBG.resize(800,600);
 
  imgAcc = loadImage("accurate.png");
  leap = new LeapMotion(this);
}

void draw()
{
  background(imgBG);
  for(Hand hand : leap.getHands() ){
    hand.draw();
    myDraw(hand.getIndexFinger().getPosition());
  }
}
void myDraw(PVector pos){
  pushMatrix();
//  fill(255,0,0); sphere(20);
  image(imgAcc,pos.x-50,pos.y-50,100,100);
  popMatrix();
}



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));
}
float grabX=0,grabY=0;
int grade = 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);
}

2015年3月23日 星期一

week05


期中作品

 射擊遊戲
利用LeapMotion做射擊遊戲,食指當作槍的槍口,當感應不到食指的時候就當作開槍的動作,偵測到5隻手指時當作裝子彈的動作,

遊戲時間60秒,根據時間出現標把,擊中可獲得分數,會有特殊的標靶分數比較高, 彈數10發。

2015年3月9日 星期一

week3

import de.voidplus.leapmotion.*;
LeapMotion leap;
void setup(){
  size(800,600,P3D);
  leap = new LeapMotion(this);
}

void draw(){
  background(255);
  for(Hand hand : leap.getHands()){
    //println("yaw:"+hand.getYaw());
    println("pitch:"+hand.getPitch());
    //println("Roll:"+hand.getRoll());   
   
    pushMatrix();
    translate(hand.getPosition().x,hand.getPosition().y);
    rotateZ(radians(hand.getPitch()));
    rotateY(-radians(hand.getYaw()));
    stroke(0); fill(255); box(100);
    popMatrix();
   
    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());
  }
}
void myDraw(PVector pos){
    pushMatrix();
    translate(pos.x, pos.y);
    fill(255,0,255); sphere(20);
    popMatrix();
}