费根鲍姆图matlab,菲根鲍姆图(费根鲍姆图,Feigenbaum)的制作

#include#define Begin 0.7//The begin number of x[]

SDL_Surface *screen;//The screen pointer on which we draw.

SDL_Surface *initSDL(int w,int y)//start the SDL and create a screen.

{

SDL_Surface *screen;

SDL_Init(SDL_INIT_VIDEO);

screen=SDL_SetVideoMode(w,y,8,SDL_SWSURFACE);

return screen;

}

void drawPoint(SDL_Surface *surface,int x,int y)//draw a point on screen

{

Uint32 yellow;

int bpp;

Uint8 *p;

yellow=SDL_MapRGB(surface->format,0xff,0xff,0x00);

if(SDL_MUSTLOCK(surface)){

if(SDL_LockSurface(surface)<0){

fprintf(stderr,"Can't lock screen: %s\n",SDL_GetError());

return;

}

}

bpp=surface->format->BytesPerPixel;

p=(Uint8 *)surface->pixels+y*surface->pitch+x*bpp;

switch(bpp){

case 1:

*p=yellow;

break;

case 2:

*(Uint16 *)p=yellow;

break;

case 3:

if(SDL_BYTEORDER==SDL_BIG_ENDIAN){

p[0]=(yellow>>16) &0xff;

p[1]=(yellow>>8)& 0xff;

p[2]=yellow & 0xff;

}else{

p[0]=yellow&0xff;

p[1]=(yellow>>8)&0xff;

p[2]=(yellow>>16)&0xff;

}

break;

case 4:

*(Uint32 *)p=yellow;

break;

}

if(SDL_MUSTLOCK(surface)){

SDL_UnlockSurface(surface);

}

SDL_UpdateRect(surface,x,y,1,1);

}

void fgbm(double startr,double endr,double stepr,double startx,double endx,double stepx)//The fun we design most

{

double r,x[2000];

int j;

for(r=startr;r<=endr;r+=stepr){

x[0]=Begin;

for(j=1;j<2000;j++){

x[j]=r*x[j-1]*(1-x[j-1]);//create the number

//draw the number is the screen

if(j>999 && x[j]>=startx && x[j]<=endx) drawPoint(screen,(int)((x[j]-startx)/stepx+1),(int)((r-startr)/stepr+1));

}

}

}

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

{

double startr,endr,stepr,startx,endx,stepx;

sscanf(argc[1],"%lf",&startr);

sscanf(argc[2],"%lf",&endr);

sscanf(argc[3],"%lf",&stepr);

sscanf(argc[4],"%lf",&startx);

sscanf(argc[5],"%lf",&endx);

sscanf(argc[6],"%lf",&stepx);

screen=initSDL((int)((endx-startx)/stepx+2),(int)((endr-startr)/stepr+2));

fgbm(startr,endr,stepr,startx,endx,stepx);

SDL_SaveBMP(screen,"a.bmp");

getchar();

SDL_Quit();

return 0;

}

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值