Sierpinski Gasket分形图的绘制

这篇博客展示了如何使用OpenGL通过递归分形技术来绘制Sierpinski三角形和Sierpinski四面体。内容包括初始化设置、顶点计算、递归三角形和四面体的分割,以及颜色处理。
摘要由CSDN通过智能技术生成
200792501.jpg


/* two-dimensional Sierpinski gasket          */
/* generated using randomly selected vertices */
/* and bisection                              */

#include 
< GL / glut.h >

void  myinit()
{

/* attributes */
      glClearColor(
1.01.01.01.0); /* white background */
      glColor3f(
1.00.00.0); /* draw in red */
}


void  reshape( int  w, int  h)
{
    glViewport(
0,0,(GLsizei)w,(GLsizei)h);
    glMatrixMode(GL_PROJECTION);
    glLoadIdentity();
    gluOrtho2D(
0.050.00.050.0);/* set up viewing 50.0 x 50.0 camera coordinate window with origin lower left */

    glMatrixMode(GL_MODELVIEW);
    glLoadIdentity();

}


void  display()
{
    
/* A triangle */
    GLfloat vertices[
3][2]={ { 0.0,0.0},{ 25.0,50.0},{ 50.0,0.0}};
    
int j, k;
    
int rand();       /* standard random number generator */
    GLfloat p[
2={ 7.55.0};  /* arbitrary initial point inside triangle */
    glClear(GL_COLOR_BUFFER_BIT);  
/*clear the window */
    glBegin(GL_POINTS);

/* compute and plot 5000 new points */

    
for( k=0; k<5000; k++)
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值