顯示具有 40471205H_李昱勳 標籤的文章。 顯示所有文章
顯示具有 40471205H_李昱勳 標籤的文章。 顯示所有文章

2018年1月10日 星期三

abcqq week14

Rasterization

1.畫三角形:
程式碼:
size(600,600,P3D);
background(255);
beginShape(TRIANGLE);
  stroke(255,0,0);vertex(300,100);
  stroke(255,255,0);vertex(500,500);
  stroke(0,0,255);vertex(100,500);
endShape();















2.填滿:
程式碼:
size(600,600,P3D);
background(255);
beginShape(TRIANGLE);
  fill(255,0,0);vertex(300,100);
  fill(255,255,0);vertex(500,500);
  fill(0,0,255);vertex(100,500);
endShape();



abcqq week13

week 13

1.VR體驗:

GoPro 運動攝影機



專業GoPro  可拍攝360度視角(10萬)


Ricoh theta 拍攝360度VR影像


2.色彩系統:

RGB色彩:
程式碼:
size(500,500);
beginShape();
for(int x=0;x<500;x++)
{
  for(int y=0;y<500;y++)
  {
    stroke(x,y,100);
    point(x,y);
  }
}














HSB 色彩系統:(色階 飽和度 亮度)

程式碼:
size(500,500);
colorMode(HSB,500);
for(int x=0;x<500;x++)
{
  for(int y=0;y<500;y++)
  {
    stroke(x,y,100);
    point(x,y);
  }
}

abcqq week12

week 12

1. 下載 myGL_Frustrum 221_MultiView
2.開glut並複製程式碼執行














2.安裝Collada在P語言














打開範例viewer 2D













3.執行老師的程式碼:(小竹竿人移動)

abcqq week11

1.在程式中加入音檔:
限wav檔:因為直接紀錄波行沒有壓縮

程式碼:
include<mmsystem.h>
PlaySoundA("123.wav",NULL,SND_ASYNC); //不同步撥放



2.在程式裡撥放mp3音檔:
程式碼:(老師提供)
1.匯入CMP3_MCI.h
2.下載一個mp3音樂放入bin

3.在P語言放mp3檔

程式碼:
import ddf.minim.*;
Minim minim;//int a;
AudioPlayer player;
void setup(){
  minim = new Minim(this);
  player = minim.loadFile("123.mp3");
  player.loop();
  player.play();
}
void draw(){
  
}






abcqq week10

專題介紹

abcqq week9

1.Bump mapping
網址:https://www.openprocessing.org/sketch/24945 





























這是 javascript 用P語言寫的


2.在P語言中加入圖片:
程式碼:
PImage img=loadImage("123.jpg");
size(600,600);
image(img,0,0,600,600);


記得要有拖曳的動作,把圖檔拖進去視窗













3.讓圖片可以被滑鼠移動
程式碼:
PImage img;

void setup()
{
   img=loadImage("123.jpg");
   size(600,600);
}

void draw()
{
image(img,mouseX,mouseY);

}


4.馬力歐
PImage imgMario, imgMarioJump, imgBrick;
double marioX=200, marioY=100;
double marioVX=0, marioVY=0;
boolean marioOnFloor = false;
int [][]map = {{0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0},
               {0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0},
               {0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0},
               {0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0},
               {0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0},
               {0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0},
               {0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0},
               {0,0,0,0,0,0,0,0,0,1,1,1,1,1,0,0},
               {0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0},
               {0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0},
               {0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0},
               {1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1}};

void setup(){
  size(800,600);
  imgMario = loadImage("mario.jpg");
  imgMarioJump = loadImage("mariojump.png");
  imgBrick = loadImage("brick.png");
}
void draw(){
  background(255);
  if (map[(int)(marioY/50)][(int)(marioX/50)] != 0){
    marioOnFloor = true;
  }
  if (marioOnFloor == false){
    marioVY += 0.98;
  }
  else if (marioOnFloor == true){
    marioVY = 0;
  }  
  for (int x=0; x<16; x++){
    for (int y=0; y<12; y++){
      if (map[y][x] == 1)
        image(imgBrick, x*50, y*50, 50, 50);
    }
  }
  
  marioX += marioVX;
  marioY += marioVY;
  image(imgBrick, marioX, marioY, 50, 50);
  //image(imgMario, marioX, marioY, 100,100);
}

void keyPressed(){
  if (keyCode == UP)
      marioVY = -15;
  if (keyCode == LEFT)
      marioVX = -5;
  if (keyCode == RIGHT)
      marioVX = 5;
}
void keyReleased(){
  if (keyCode == LEFT || keyCode == RIGHT)
      marioVX = 0;
}

2018年1月2日 星期二

abcqq week07

1.打光程式碼

GLfloat light_position[] = { 2.0f, 5.0f, 5.0f, 0.0f }; //const刪掉加入


void motion(int x,int y) //跟拖曳很像
{
    light_position[0]=(x-150)/150.0*2;
    light_position[1]=-(y-150)/150.0*2;
    glLightfv(GL_LIGHT0, GL_POSITION, light_position);
    glutPostRedisplay();
}
glutMotionFunc(motion);

從左邊打光


從右邊打光

abcqq week 06

1.打光

相關程式碼:

glutCreateWindow(...); //開視窗

glEnable(GL_DEPTH_TEST);
glEnable(GL_LIGHTING); //打光程式1
glEnable(GL_LIGHT0); //打光程式2
glLightfv(GL_LIGHT0, GPOSITION, pos); 


keyboard 副程式

void keyboard(unsigned char key, int x, int y)
{
    printf("now: %c (%d %d)\n", key, x,y);
    if(key=='1') rotateX++;
    if(key=='2') rotateY++;
    if(key=='3') rotateZ++;
    glutPostRedisplay(); //畫面重新 re-display
}

滑鼠控制  

void mouse(int button, int state, int x, int y)
{   printf("button:%d state:%d (%d %d)\n", button, state, x, y);
    
    if(state==GLUT_DOWN) 
    {
        oldX=x; oldY=y;
    }
}

滑鼠拖曳
void motion(int x, int y)
{
    rotateY +=   -(x-oldX);
    rotateX +=   -(y-oldY);
    oldX=x; oldY=y;
    glutPostRedisplay();
}


2017年11月7日 星期二

abcqq week05

1.編譯程式

1.1
下載素材程式


修改freeglut資料夾所在位置
C:\Users\oscar\Desktop\freeglut\include
C:\Users\oscar\Desktop\freeglut\lib
\
按F9執行
2.打光

打開transformation.c Ctrl+f 搜尋 light
glEnable(GL_LIGHTING);
glEnable(GL_LIGHTING0);
GLfloat pos[] = { 0.0, 0.0, 1.0, 0.0 };//全域變數




2017年10月10日 星期二

abcqq week02

Week 2
1.抓取main的程式碼

相關程式碼說明
int main(int argc, char *argv[])  //( argc參數的數量 argv[]參數存為字串)

 glutInit(&argc,argv);  //初始化GLUT
   

  glutCreateWindow("window_name");  //建立視窗
   

 
 glutMainLoop(); //主要迴圈(會一直重複的畫下去.....)
    

void display()
{
    glClearColor(1,0,0,0);  //設定背景的顏色(R,G,B,透明度)
   
   glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT);  //清理背景
  
   glColor3f(1,0,1);  //設定物件的顏色 (R,G,B)
    

    
glutSolidTeapot(1); //畫茶壺(size)   
    

    glutSwapBuffers();  //
交換前、後緩衝區(避免畫面閃爍)
}
    
glutDisplayFunc(display);  //顯示函式 加在MainLoop


2.瞄點畫圖
所需程式碼:
glBegin(GL_POLYGON);  //開始畫圖
glVertex3f(1,1,0);  //點的座標(x,y,z)
glEnd();  //結束畫圖

for example:

  glBegin(GL_POLYGON);

    glColor3f(1,0,0); //set color

    glVertex3f(1,1,0);

    glVertex3f(-1,1,0);

    glVertex3f(0,-1,0);

    glEnd();






3.漸層色彩:

glBegin(GL_POLYGON);
glColor3f(0,0,1);
glVertex3f(1,1,0);

glColor3f(1,0,0);
glVertex3f(-1,1,0);

glColor3f(0,1,0);
glVertex3f(0,-1,0);
glEnd();