glut示例程序Mandelbrot集

Z是一个复数,x[0]=0,x[n+1]=x[n]^2+Z,使x[n](n->无穷大时)收敛的Z就是Mandelbrot集的元素。下面的程序近似表达了它从整体看的形状,这是一个分形。
// glut04.cpp : 定义控制台应用程序的入口点。
//

#include "stdafx.h"
#include 
   
   
    
    
#include 
    
    
     
     //把这个头文件放在最后

const int width=800,height=800;
const double xmin=-2, xmax=0.5, ymin=-1.25, ymax=1.25;
const double xstep=(xmax-xmin)/width;
const double ystep=(ymax-ymin)/height;
const int iterationtimes=64;

namespace w_h_
{
	struct rgbColor
	{
		GLubyte red;
		GLubyte green;
		GLubyte blue;
		void set(GLubyte r,GLubyte g,GLubyte b)
		{
			r=red;	g=green;	b=blue;
		}
	};
}


void pickColor( const std::complex
     
     
      
      & z, struct w_h_::rgbColor& c ) 
{
	std::complex
      
      
       
        w;//zero
	GLubyte iterations=0;
	while(iterations
       
       
         16) break; iterations++; } if(iterations==iterationtimes) c.red=c.green=c.blue=255; else { GLubyte grey=((double)iterations)/(iterationtimes-1)*254; c.red=c.green=c.blue=grey; } } void display() { int a,b; double x,y; struct w_h_::rgbColor c; glClear(GL_COLOR_BUFFER_BIT); glBegin(GL_POINTS); for(a=0,x=xmin;a 
        
          (x,y),c); glColor3ub(c.red,c.green,c.blue); glVertex2i(a,b); } } glEnd(); glFlush(); } int _tmain(int argc, _TCHAR* argv[]) { glutInit(&argc,(char **)argv); glutInitDisplayMode(GLUT_SINGLE|GLUT_RGB); glutInitWindowSize(width,height); glutInitWindowPosition(0,0); glutCreateWindow("sample"); glClearColor(1,1,1,0); gluOrtho2D(0,width,0,height); glutDisplayFunc(display); glutMainLoop(); return 0; } 
         
       
      
      
     
     
    
    
   
   

 

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值