2020年3月17日 星期二

兩百一3

🎇🎈🎉第3週🎅🎄🎃

以下是簡易步驟😃😃

1 複製上個禮拜的程式碼(上一週文章內)

程式碼解釋:

glBegin(GL_POLYGON);//開始

glColor3f( R /255.0, G /255.0,  B /255.0);//設定顏色程式碼

glVertex2f(( X -150)/150.0, - ( Y -150)/150.0);//設定頂點程式碼

glEnd();//結束

glBegin(GL_POLYGON);//開始

  for(float angle=0 ; angle<=3.1415926 * 2 ;angle+=0.01)

{

glVertex2f(長*cos(angle) +- X ,寬*sin(angle) +- Y );//圓形

 }

 glEnd();//結束

2 修改成新的程式碼

以下是程式碼
#include <GL/glut.h>
#include <stdio.h>
float teapotX=0,teapotY=0;
void display()

{
    glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT);
    glPushMatrix();
        glTranslatef(teapotX,teapotY,0);
        glutSolidTeapot(0.3);
    glPopMatrix();
    glutSwapBuffers();

}
void mouse(int button,int state,int x,int y)
{
    printf("%f %f\n",(x-150)/150.0,(y-150)/150.0);
    teapotX=  (x-150)/150.0;
    teapotY= -(y-150)/150.0;
}
int main(int argc,char**argv)

{
    glutInit(&argc,argv);
    glutInitDisplayMode(GLUT_DOUBLE | GLUT_DEPTH);
    glutCreateWindow("week02 Yes!!!");
    glutDisplayFunc(display);
    glutMouseFunc(mouse);
    glutMainLoop();

}

3 ( 清畫面 畫圖 )使用滑鼠這樣就能移動茶壺了😊😊

按照步驟一步一步就能完成啦😽😽
謝謝觀賞🙌🙌

作品:


比目魚是什麼系???










ㄤ得了系。


好der~

程式碼如下:
#include <GL/glut.h>
#include <stdio.h>
#include <math.h>

void display()

{
    glClearColor(115/255.0,144/255.0,133/255.0,1);
    glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT);

    glBegin(GL_POLYGON);
    glColor3f((248/255.0),(204/255.0),(90/255.0));
    for(float angle=0 ; angle<=3.1415926 * 2 ;angle+=0.01)
    {
    glVertex2f(0.75*cos(angle),0.5*sin(angle));
    }
    glEnd();

    glBegin(GL_POLYGON);
    glColor3f(7/255.0,77/255.0,102/255.0);
    glVertex2f((40-150)/150.0, - (129-150)/150.0);
    glVertex2f((18-150)/150.0, - (119-150)/150.0);
    glVertex2f((16-150)/150.0, - (163-150)/150.0);
    glVertex2f((37-150)/150.0, - (154-150)/150.0);
    glEnd();
        glBegin(GL_POLYGON);
    glColor3f(7/255.0,77/255.0,102/255.0);
    glVertex2f((115-150)/150.0, - (79-150)/150.0);
    glVertex2f((103-150)/150.0, - (58-150)/150.0);
    glVertex2f((205-150)/150.0, - (60-150)/150.0);
    glVertex2f((186-150)/150.0, - (78-150)/150.0);
    glEnd();

    glBegin(GL_POLYGON);
    glColor3f(7/255.0,77/255.0,102/255.0);
    glVertex2f((179-150)/150.0, - (153-150)/150.0);
    glVertex2f((181-150)/150.0, - (140-150)/150.0);
    glVertex2f((206-150)/150.0, - (126-150)/150.0);
    glVertex2f((206-150)/150.0, - (169-150)/150.0);
    glEnd();

    glBegin(GL_POLYGON);
    glColor3f(7/255.0,77/255.0,102/255.0);
    glVertex2f((257-150)/150.0, - (130-150)/150.0);
    glVertex2f((286-150)/150.0, - (103-150)/150.0);
    glVertex2f((286-150)/150.0, - (189-150)/150.0);
    glVertex2f((258-150)/150.0, - (165-150)/150.0);
    glEnd();

    glBegin(GL_POLYGON);
    glColor3f((255/255.0),(255/255.0),(255/255.0));
    for(float angle=0 ; angle<=3.1415926 * 2 ;angle+=0.01)
    {
    glVertex2f(0.15*cos(angle)-0.5,0.15*sin(angle)+0.1);
    }
    glEnd();
    glBegin(GL_POLYGON);
    glColor3f((255/255.0),(255/255.0),(255/255.0));
    for(float angle=0 ; angle<=3.1415926 * 2 ;angle+=0.01)
    {
    glVertex2f(0.15*cos(angle)-0.155,0.15*sin(angle)+0.1);
    }
    glEnd();

    glBegin(GL_POLYGON);
    glColor3f((0/255.0),(0/255.0),(0/255.0));
    for(float angle=0 ; angle<=3.1415926 * 2 ;angle+=0.01)
    {
    glVertex2f(0.1*cos(angle)-0.5,0.1*sin(angle)+0.1);
    }
    glEnd();

    glBegin(GL_POLYGON);
    glColor3f(255/255.0,127/255.0,39/255.0);
    glVertex2f((80-150)/150.0, - (170-150)/150.0);
    glVertex2f((126-150)/150.0, - (170-150)/150.0);
    glVertex2f((101-150)/150.0, - (190-150)/150.0);
    glEnd();

        glBegin(GL_POLYGON);
    glColor3f((0/255.0),(0/255.0),(0/255.0));
    for(float angle=0 ; angle<=3.1415926 * 2 ;angle+=0.01)
    {
    glVertex2f(0.1*cos(angle)-0.155,0.1*sin(angle)+0.1);
    }
    glEnd();

    glBegin(GL_POLYGON);
    glColor3f(7/255.0,77/255.0,102/255.0);
    glVertex2f((126-150)/150.0, - (78-150)/150.0);
    glVertex2f((126-150)/150.0, - (101-150)/150.0);
    glVertex2f((131-150)/150.0, - (102-150)/150.0);
    glVertex2f((132-150)/150.0, - (78-150)/150.0);
    glEnd();

    glBegin(GL_POLYGON);
    glColor3f(7/255.0,77/255.0,102/255.0);
    glVertex2f((135-150)/150.0, - (79-150)/150.0);
    glVertex2f((137-150)/150.0, - (104-150)/150.0);
    glVertex2f((142-150)/150.0, - (104-150)/150.0);
    glVertex2f((142-150)/150.0, - (79-150)/150.0);
    glEnd();

    glBegin(GL_POLYGON);
    glColor3f(7/255.0,77/255.0,102/255.0);
    glVertex2f((155-150)/150.0, - (77-150)/150.0);
    glVertex2f((155-150)/150.0, - (107-150)/150.0);
    glVertex2f((162-150)/150.0, - (107-150)/150.0);
    glVertex2f((162-150)/150.0, - (78-150)/150.0);
    glEnd();

glutSwapBuffers();
}

void mouse(int button, int state, int x, int y)
{
    if(state==GLUT_DOWN)
    {
    printf("glVertex2f((%d-150)/150.0, - (%d-150)/150.0);\n",x,y);
    }
}

int main(int argc, char**argv)
{
    glutInit(&argc,argv);
    glutInitDisplayMode(GLUT_DOUBLE | GLUT_DEPTH);
    glutCreateWindow("Week03");

    glutDisplayFunc(display);
    glutMouseFunc(mouse);
    glutMainLoop();
}


20歲生日蛋糕
birthday cake





程式碼如下:
#include <GL/glut.h>
#include <stdio.h>
#include <math.h>

void display()

{
    glClearColor(153/255.0,217/255.0,234/255.0,1);
    glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT);

    glBegin(GL_POLYGON);//第二層方方
    glColor3f((239/255.0),(239/255.0),(239/255.0));
    glVertex2f((30-150)/150.0, - (170-150)/150.0);
    glVertex2f((30-150)/150.0, - (246-150)/150.0);
    glVertex2f((270-150)/150.0, - (246-150)/150.0);
    glVertex2f((270-150)/150.0, - (170-150)/150.0);
    glEnd();
    glBegin(GL_POLYGON);//第二層底圓
    glColor3f((239/255.0),(239/255.0),(239/255.0));
    for(float angle=0 ; angle<=3.1415926 * 2 ;angle+=0.01)
    {
    glVertex2f(0.8*cos(angle),0.2*sin(angle)-0.66);
    }
    glEnd();

    glBegin(GL_POLYGON);//第二層頂圓
    glColor3f((255/255.0),(255/255.0),(255/255.0));
    for(float angle=0 ; angle<=3.1415926 * 2 ;angle+=0.01)
    {
    glVertex2f(0.8*cos(angle),0.2*sin(angle)-0.13);
    }
    glEnd();

    glBegin(GL_POLYGON);//第一層方方
    glColor3f(239/255.0,239/255.0,239/255.0);
    glVertex2f((52-150)/150.0, - (100-150)/150.0);
    glVertex2f((52-150)/150.0, - (152-150)/150.0);
    glVertex2f((247-150)/150.0, - (152-150)/150.0);
    glVertex2f((247-150)/150.0, - (100-150)/150.0);
    glEnd();

    glBegin(GL_POLYGON);//第一層底圓
    glColor3f((239/255.0),(239/255.0),(239/255.0));
    for(float angle=0 ; angle<=3.1415926 * 2 ;angle+=0.01)
    {
    glVertex2f(0.65*cos(angle),0.2*sin(angle)-0);
    }
    glEnd();

    glBegin(GL_POLYGON);//第一層頂圓
    glColor3f((255/255.0),(255/255.0),(255/255.0));
    for(float angle=0 ; angle<=3.1415926 * 2 ;angle+=0.01)
    {
    glVertex2f(0.65*cos(angle),0.2*sin(angle)+0.35);
    }
    glEnd();

    glBegin(GL_POLYGON);//巧克力牌
    glColor3f((115/255.0),(87/255.0),(66/255.0));
    glVertex2f((105-150)/150.0, - (55-150)/150.0);
    glVertex2f((105-150)/150.0, - (100-150)/150.0);
    glVertex2f((190-150)/150.0, - (100-150)/150.0);
    glVertex2f((190-150)/150.0, - (55-150)/150.0);
    glEnd();

    glBegin(GL_POLYGON);//草莓中間(紅)
    glColor3f((255/255.0),(0/255.0),(0/255.0));
    for(float angle=0 ; angle<=3.1415926 * 2 ;angle+=0.01)
    {
    glVertex2f(0.04*cos(angle),0.04*sin(angle)+0.22);
    }
    glEnd();
    glBegin(GL_POLYGON);//草莓(橘)
    glColor3f((255/255.0),(168/255.0),(64/255.0));
    for(float angle=0 ; angle<=3.1415926 * 2 ;angle+=0.01)
    {
    glVertex2f(0.04*cos(angle)-0.2,0.04*sin(angle)+0.23);
    }
    glEnd();
    glBegin(GL_POLYGON);//草莓(橘)
    glColor3f((255/255.0),(168/255.0),(64/255.0));
    for(float angle=0 ; angle<=3.1415926 * 2 ;angle+=0.01)
    {
    glVertex2f(0.04*cos(angle)+0.2,0.04*sin(angle)+0.23);
    }
    glEnd();
    glBegin(GL_POLYGON);//草莓(紅)
    glColor3f((255/255.0),(0/255.0),(0/255.0));
    for(float angle=0 ; angle<=3.1415926 * 2 ;angle+=0.01)
    {
    glVertex2f(0.04*cos(angle)-0.4,0.04*sin(angle)+0.28);
    }
    glEnd();
    glBegin(GL_POLYGON);//草莓(紅)
    glColor3f((255/255.0),(0/255.0),(0/255.0));
    for(float angle=0 ; angle<=3.1415926 * 2 ;angle+=0.01)
    {
    glVertex2f(0.04*cos(angle)+0.4,0.04*sin(angle)+0.28);
    }
    glEnd();
    glBegin(GL_POLYGON);//草莓(橘)
    glColor3f((255/255.0),(168/255.0),(64/255.0));
    for(float angle=0 ; angle<=3.1415926 * 2 ;angle+=0.01)
    {
    glVertex2f(0.04*cos(angle)-0.55,0.04*sin(angle)+0.35);
    }
    glEnd();
    glBegin(GL_POLYGON);//草莓(橘)
    glColor3f((255/255.0),(168/255.0),(64/255.0));
    for(float angle=0 ; angle<=3.1415926 * 2 ;angle+=0.01)
    {
    glVertex2f(0.04*cos(angle)+0.55,0.04*sin(angle)+0.35);
    }
    glEnd();
    glBegin(GL_POLYGON);//草莓(紅)
    glColor3f((255/255.0),(0/255.0),(0/255.0));
    for(float angle=0 ; angle<=3.1415926 * 2 ;angle+=0.01)
    {
    glVertex2f(0.04*cos(angle)-0.43,0.04*sin(angle)+0.46);
    }
    glEnd();
    glBegin(GL_POLYGON);//草莓(紅)
    glColor3f((255/255.0),(0/255.0),(0/255.0));
    for(float angle=0 ; angle<=3.1415926 * 2 ;angle+=0.01)
    {
    glVertex2f(0.04*cos(angle)+0.43,0.04*sin(angle)+0.46);
    }
    glEnd();

    glBegin(GL_POLYGON);//草莓2中間(紅)
    glColor3f((255/255.0),(0/255.0),(0/255.0));
    for(float angle=0 ; angle<=3.1415926 * 2 ;angle+=0.01)
    {
    glVertex2f(0.04*cos(angle),0.04*sin(angle)-0.26);
    }
    glEnd();
    glBegin(GL_POLYGON);//草莓(橘)
    glColor3f((255/255.0),(168/255.0),(64/255.0));
    for(float angle=0 ; angle<=3.1415926 * 2 ;angle+=0.01)
    {
    glVertex2f(0.04*cos(angle)-0.2,0.04*sin(angle)-0.25);
    }
    glEnd();
    glBegin(GL_POLYGON);//草莓(橘)
    glColor3f((255/255.0),(168/255.0),(64/255.0));
    for(float angle=0 ; angle<=3.1415926 * 2 ;angle+=0.01)
    {
    glVertex2f(0.04*cos(angle)+0.2,0.04*sin(angle)-0.25);
    }
    glEnd();
    glBegin(GL_POLYGON);//草莓(紅)
    glColor3f((255/255.0),(0/255.0),(0/255.0));
    for(float angle=0 ; angle<=3.1415926 * 2 ;angle+=0.01)
    {
    glVertex2f(0.04*cos(angle)-0.4,0.04*sin(angle)-0.22);
    }
    glEnd();
    glBegin(GL_POLYGON);//草莓(紅)
    glColor3f((255/255.0),(0/255.0),(0/255.0));
    for(float angle=0 ; angle<=3.1415926 * 2 ;angle+=0.01)
    {
    glVertex2f(0.04*cos(angle)+0.4,0.04*sin(angle)-0.22);
    }
    glEnd();
    glBegin(GL_POLYGON);//草莓(橘)
    glColor3f((255/255.0),(168/255.0),(64/255.0));
    for(float angle=0 ; angle<=3.1415926 * 2 ;angle+=0.01)
    {
    glVertex2f(0.04*cos(angle)-0.55,0.04*sin(angle)-0.19);
    }
    glEnd();
    glBegin(GL_POLYGON);//草莓(橘)
    glColor3f((255/255.0),(168/255.0),(64/255.0));
    for(float angle=0 ; angle<=3.1415926 * 2 ;angle+=0.01)
    {
    glVertex2f(0.04*cos(angle)+0.55,0.04*sin(angle)-0.19);
    }
    glEnd();
    glBegin(GL_POLYGON);//草莓(紅)
    glColor3f((255/255.0),(0/255.0),(0/255.0));
    for(float angle=0 ; angle<=3.1415926 * 2 ;angle+=0.01)
    {
    glVertex2f(0.04*cos(angle)-0.7,0.04*sin(angle)-0.12);
    }
    glEnd();
    glBegin(GL_POLYGON);//草莓(紅)
    glColor3f((255/255.0),(0/255.0),(0/255.0));
    for(float angle=0 ; angle<=3.1415926 * 2 ;angle+=0.01)
    {
    glVertex2f(0.04*cos(angle)+0.7,0.04*sin(angle)-0.12);
    }
    glEnd();

    glBegin(GL_POLYGON);//2橫
    glColor3f((255/255.0),(255/255.0),(255/255.0));
    glVertex2f((113-150)/150.0, - (58-150)/150.0);
    glVertex2f((113-150)/150.0, - (65-150)/150.0);
    glVertex2f((132-150)/150.0, - (65-150)/150.0);
    glVertex2f((132-150)/150.0, - (58-150)/150.0);
    glEnd();
    glBegin(GL_POLYGON);//2列
    glColor3f((255/255.0),(255/255.0),(255/255.0));
    glVertex2f((132-150)/150.0, - (58-150)/150.0);
    glVertex2f((132-150)/150.0, - (76-150)/150.0);
    glVertex2f((139-150)/150.0, - (76-150)/150.0);
    glVertex2f((139-150)/150.0, - (58-150)/150.0);
    glEnd();
    glBegin(GL_POLYGON);//2橫
    glColor3f((255/255.0),(255/255.0),(255/255.0));
    glVertex2f((113-150)/150.0, - (76-150)/150.0);
    glVertex2f((113-150)/150.0, - (83-150)/150.0);
    glVertex2f((139-150)/150.0, - (83-150)/150.0);
    glVertex2f((139-150)/150.0, - (76-150)/150.0);
    glEnd();
    glBegin(GL_POLYGON);//2列
    glColor3f((255/255.0),(255/255.0),(255/255.0));
    glVertex2f((113-150)/150.0, - (83-150)/150.0);
    glVertex2f((113-150)/150.0, - (90-150)/150.0);
    glVertex2f((120-150)/150.0, - (90-150)/150.0);
    glVertex2f((120-150)/150.0, - (83-150)/150.0);
    glEnd();
    glBegin(GL_POLYGON);//2橫
    glColor3f((255/255.0),(255/255.0),(255/255.0));
    glVertex2f((113-150)/150.0, - (90-150)/150.0);
    glVertex2f((113-150)/150.0, - (97-150)/150.0);
    glVertex2f((139-150)/150.0, - (97-150)/150.0);
    glVertex2f((139-150)/150.0, - (90-150)/150.0);
    glEnd();

    glBegin(GL_POLYGON);//0外
    glColor3f((255/255.0),(255/255.0),(255/255.0));
    glVertex2f((155-150)/150.0, - (58-150)/150.0);
    glVertex2f((155-150)/150.0, - (97-150)/150.0);
    glVertex2f((183-150)/150.0, - (97-150)/150.0);
    glVertex2f((183-150)/150.0, - (58-150)/150.0);
    glEnd();

    glBegin(GL_POLYGON);//0外
    glColor3f((115/255.0),(87/255.0),(66/255.0));
    glVertex2f((162-150)/150.0, - (64-150)/150.0);
    glVertex2f((162-150)/150.0, - (90-150)/150.0);
    glVertex2f((176-150)/150.0, - (90-150)/150.0);
    glVertex2f((176-150)/150.0, - (64-150)/150.0);
    glEnd();

    glBegin(GL_POLYGON);//三角形
    glColor3f((255/255.0),(174/255.0),(201/255.0));
    glVertex2f((141-150)/150.0, - (233-150)/150.0);
    glVertex2f((120-150)/150.0, - (223-150)/150.0);
    glVertex2f((120-150)/150.0, - (251-150)/150.0);
    glEnd();
    glBegin(GL_POLYGON);//三角形
    glColor3f((255/255.0),(174/255.0),(201/255.0));
    glVertex2f((159-150)/150.0, - (233-150)/150.0);
    glVertex2f((180-150)/150.0, - (251-150)/150.0);
    glVertex2f((180-150)/150.0, - (223-150)/150.0);
    glEnd();
    glBegin(GL_POLYGON);//圈圈
    glColor3f((255/255.0),(174/255.0),(201/255.0));
    for(float angle=0 ; angle<=3.1415926 * 2 ;angle+=0.01)
    {
    glVertex2f(0.08*cos(angle)+0,0.08*sin(angle)-0.57);
    }
    glEnd();

glutSwapBuffers();
}

void mouse(int button, int state, int x, int y)
{
    if(state==GLUT_DOWN)
    {
    printf("glVertex2f((%d-150)/150.0, - (%d-150)/150.0);\n",x,y);
    }
}

int main(int argc, char**argv)
{
    glutInit(&argc,argv);
    glutInitDisplayMode(GLUT_DOUBLE | GLUT_DEPTH);
    glutCreateWindow("Week03");

    glutDisplayFunc(display);
    glutMouseFunc(mouse);
    glutMainLoop();
}

光做那些球球眼睛就快瞎掉了:)

1 則留言:

  1. 老師班會課的時候說有人這個禮拜生日 你有沒有頭緒

    回覆刪除