加入收藏 | 设为首页 | 会员中心 | 我要投稿 李大同 (https://www.lidatong.com.cn/)- 科技、建站、经验、云计算、5G、大数据,站长网!
当前位置: 首页 > 综合聚焦 > 服务器 > Windows > 正文

圆的绘制 分形图案

发布时间:2020-12-14 04:28:45 所属栏目:Windows 来源:网络整理
导读:? 1.圆的绘制 #include windows.h ? #include GL/gl.h #include GL/glu.h #include GL/glaux.h ? #include math.h ? #define PI 3.1415926535897 ? void myinit (void) { ??? /*? 将背景清为白色? */ ??? glClearColor (1.0,1.0,0.0); ??? glShadeModel (GL_

?

1.圆的绘制

#include <windows.h>

?

#include <GL/gl.h>

#include <GL/glu.h>

#include <GL/glaux.h>

?

#include <math.h>

?

#define PI 3.1415926535897

?

void myinit (void)

{

??? /*? 将背景清为白色? */

??? glClearColor (1.0,1.0,0.0);

??? glShadeModel (GL_FLAT);

}

?

void CALLBACK display(void)

{

??? int i,num_points=100;

??? glClear (GL_COLOR_BUFFER_BIT);

??? /*? 将所有的线画为黑色? */

??? glColor3f (0.0,0.0,0.0);

???

??? glBegin(GL_LINE_LOOP);

??? for ( i = 0; i < 100; i++)

??? {

?????? double t=2*PI*i/num_points;

?????? glVertex2d(200+100*cos(t),200+100*sin(t));

??? }

??? glEnd();

??? glFlush();

}?

?

int main(int argc,char** argv)

{

??? auxInitDisplayMode (AUX_SINGLE | AUX_RGBA);

??? auxInitPosition (0,400,400);

??? auxInitWindow ("Circle");

?? ?myinit ();

??? auxMainLoop(display);

??? return 0;

}

?

  1. 分形图案

#include<windows.h>

#include<GL/gl.h>

#include<GL/glu.h>

#include<GL/glaux.h>

#include<math.h>

#define PI 3.14159

#define MaxIter 8000

?

void CALLBACK myReshape(GLint w,GLint h)

{

??? glViewport(0,w,h);

?

??? glMatrixMode(GL_PROJECTION);

??? glLoadIdentity();

??? gluOrtho2D(-8,8,-3,13);

???

??? glMatrixMode(GL_MODELVIEW);

??? glLoadIdentity();

???

}

?

void? CALLBACK display(void)

{

??? GLfloat x=0,y=0;

??? glClear(GL_COLOR_BUFFER_BIT);

??? glColor3f(0.4f,0.8f,0.4f);

??? glBegin(GL_POINTS);

??? for (int i=1;i<=MaxIter;i++)

??? {

?????? int n=(int) 100*rand()/(RAND_MAX+1);

?????? GLfloat x1,y1;

?????? if(n<1)

?????? {

?????????? x1=0;

?????????? y1=0.16*y;

?????? }

?????? else if(n<8)

?????? {

?????????? x1=0.2*x-0.26*y;

?????????? y1=0.23*x+0.22*y+1.6;

?????? }

?????? else if(n<16)

?????? {

?????????? x1=-0.15*x+0.28*y;

?????????? y1=0.26*x+0.24*y+0.44;

?????? }

?????? else

?????? {

?????????? x1=0.85*x+0.04*y;

?????????? y1=-0.04*x+0.85*y+1.6;

?????? }

?????? //按概率随机选取一个仿射变换??????

?????? glVertex2f(x1,y1);

??????? x=x1;y=y1;

??? ??? glFlush();

??? }

??? glEnd();

??? glFlush();

}

?

int main(int argc,char* argv[])

{??

??? auxInitDisplayMode (AUX_SINGLE | AUX_RGBA);

??? auxInitPosition (0,300,300);

??? auxInitWindow ("分形图案");

??? glClearColor(0.0,0.0);

??? auxReshapeFunc(myReshape);

??? auxMainLoop(display);

}

(编辑:李大同)

【声明】本站内容均来自网络,其相关言论仅代表作者个人观点,不代表本站立场。若无意侵犯到您的权利,请及时与联系站长删除相关内容!

    推荐文章
      热点阅读