#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;
}