顯示具有 08160226_李華燿 標籤的文章。 顯示所有文章
顯示具有 08160226_李華燿 標籤的文章。 顯示所有文章

2021年3月10日 星期三

2021年3月3日 星期三

week02 3/3 電腦圖學

 今日主題:點 線 面


使用Glut寫出可愛的茶壺*>)))
變成紅色了~~~

#include <GL/glut.h>
static void display(void)
{
    glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT);

    glColor3f(1,0,0);
    glutSolidTeapot(0.3);
    glutSwapBuffers();
}

int main(int argc, char *argv[])
{
    glutInit(&argc, argv);
    glutInitDisplayMode(GLUT_RGB | GLUT_DOUBLE | GLUT_DEPTH);
    glutCreateWindow("GLUT Shapes");
    glutDisplayFunc(display);
    glutMainLoop();
}


進階的來囉
增加點花樣
#include <GL/glut.h>
static void display(void)
{
    glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT);

    glBegin(GL_TRIANGLES);

        glColor3f(1.0f,0.0f,0.0f);  glVertex2f(0.0f,  1.0f);
        glColor3f(0.0f,1.0f,0.0f);  glVertex2f(0.87f, -0.5f);
        glColor3f(0.0f,0.0f,1.0f); glVertex2f(-0.87f, -0.5f);
    glEnd();
    glColor3f(0.5,1,0.2);
    glutSolidTeapot(0.3);
    glutSwapBuffers();
}

int main(int argc, char *argv[])
{
    glutInit(&argc, argv);
    glutInitDisplayMode(GLUT_RGB | GLUT_DOUBLE | GLUT_DEPTH);
    glutCreateWindow("GLUT Shapes");
    glutDisplayFunc(display);
    glutMainLoop();
}


glBegin(GL_LINE_LOOP);
改函式即改樣式





#include <GL/glut.h>
#include <math.h>
static void display(void)
{
    glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT);

    glBegin(GL_POLYGON);

        glColor3f(1.0f,0.0f,1.0f);
        for(float angle=0; angle<3.14159265358979*2; angle+=0.01)
        {
            glVertex2f( 0.5*cos(angle), 0.5*sin(angle) );
        }
    glEnd();
    glColor3f(0.5,1,0.2);
    glutSolidTeapot(0.3);
    glutSwapBuffers();
}

int main(int argc, char *argv[])
{
    glutInit(&argc, argv);
    glutInitDisplayMode(GLUT_RGB | GLUT_DOUBLE | GLUT_DEPTH);
    glutCreateWindow("GLUT Shapes");
    glutDisplayFunc(display);
    glutMainLoop();
}






2021年2月24日 星期三

08160226 2/24 week1

用code blocks 開啟新的專案

Files-New-project

使用openGL

(執行結果如圖)



WebGL Water模擬水中有球



用code blocks 開啟新的專案

Files-New-project

使用Glut以及freeglut

是由一個叫R.mark的人發明的




(執行結果如圖)







2020年6月18日 星期四

08160226_week17

float x=200,y=150;
float vx=0,vy=0;
void setup()
{
  size (300,300);
}
void draw()
{
  background(#FFFFFF);
  stroke(#000000);
  line(100,150, x,y);
  
  fill(#000000);
  noStroke();
  ellipse(100,150, 13,13);
  ellipse(x,y, 13,13);
  if( ! mousePressed){
    float dx=x-100, dy=y-150;
    float len=sqrt(dx*dx+dy*dy);
    vx -=dx*(len-100)/len*0.001;
    vy -=dy*(len-100)/len*0.001;
    x += vx;
    y += vy;
  }
}
void mouseDragged()
{
  x = mouseX;  y = mouseY;
}

2020年5月21日 星期四

憤鳥實作

PImage imgBird;
void setup()
{
  size(500,400);
  imgBird=loadImage("bird.png");
  imageMode(CENTER);
}
float birdX=100,birdY=300, oldX,oldY;
void draw()
{
  background(255);
  image(imgBird, birdX,birdY,100,100);
  if(mousePressed) line(birdX,birdY,oldX,oldY);
}
void mousePressed()
{
  oldX=birdX;oldY=birdY;
}
void mouseDragged()
{
  birdX=mouseX; birdY=mouseY;
}
簡易憤怒鳥ㄟ,小時候的童年

2020年5月7日 星期四

NO.RANDOM

int []a=new int[10];//Java's Array
//int []a={6,3,5,9,1,0,4,2,7,8};
//int []a={1,2,3,5,0,4,6,7,8,9};
//int []a={9,8,7,6,5,4,3,2,1,0};
void setup(){
  size(500,800);
  for(int i=0;i<10;i++){//random choose number
    a[i]=int(random(10));//亂數決定數字
  }
  textSize(36);
  textAlign(LEFT,TOP);
  showArray(y);
}
int y=0;
void showArray(int y){
  for(int i=0;i<10;i++){
    fill(255);  rect(i*50, y, 50,50);
    fill(0);         text(a[i], i*50, y);
  } 
}
void draw(){
 
}
void mousePressed(){
  for(int i=0; i<10-1;i++){
    if(a[i] > a[i+1]){
      int temp=a[i];
      a[i]=a[i+1];
      a[i+1]=temp;
      fill(255,0,0,128); rect(i*50, y, 100,50);
    }
  }
  y+=50;
  showArray(y);
}

2020年4月16日 星期四

來~是動動喔!












附上程式碼:
void setup(){
  size(300,200);
}
int angle=45;
void draw(){
  background(255);
  angle=mouseX;
  arc(100(座標x軸),100(座標y軸),100(寬),100(高), radians(angle),radians(360-angle),PIE);
}


利用滑鼠的滑動來控制操作360度的圓
就好像PAC-MAN呢



附上程式碼:
void setup(){
  size(300,200);
}
int angle=45;
void draw(){
  background(255);
  angle= (frameCount*2) %50;  ///[這行是重點!!!引響了嘴巴閉合的速度]
  if(angle>60) angle=120-angle;
  arc(100,100,100,100, radians(angle),radians(360-angle),PIE);
}


那~就順便為她加點色彩和動作吧
如下



附上程式碼:
void setup(){
  size(300,200);
}
int angle=45;
void draw(){
  background(255);
  angle= (frameCount*2) %50;
  if(angle>60) angle=120-angle;
  fill(0,64,128);     ///[填顏色選一個你喜歡的顏色]
  arc(100,100,100,100, radians(angle+120),radians(360-angle+120),PIE);
}

躲貓貓的左右


:
附上程式碼:
PImage img1;
PImage img2;
PImage img3;
PImage img;
void setup(){
  size(300,300);
  img1=loadImage("img1.png");///向右
  img2=loadImage("img2.png");///向左
  img3=loadImage("img3.png");///置中
  img=img3;
}
void draw(){
  background(255);
  image(img,100,100);
}
void keyPressed(){
  if(keyCode==LEFT)img=img2;///案左變左
  if(keyCode==RIGHT)img=img1;///案右變右
}
void keyReleased(){///放開回到中間
  img=img3;
}

改變x軸和y軸就真的讓他們都不見了~很有趣吧

2020年3月12日 星期四

是程設課ㄟweek 02

int x=0, y=0 (設定隕石的座標)

circle (x, y, 10)畫隕石

y++(隕石就會一直掉落耶)

然而下張圖片做一點調整
背景改為黑色
是不是就像下雪一樣,很有趣呢
這裡最為困難的地方就是考慮到落下時是否會直接落到頁面的底邊
所以減去掉雪的半徑,使得看起來落在地面上


文章到此結束

謝謝您的觀賞

Wish you have a good day!