Chinaunix首页 | 论坛 | 博客
  • 博客访问: 748266
  • 博文数量: 759
  • 博客积分: 7000
  • 博客等级: 少将
  • 技术积分: 4775
  • 用 户 组: 普通用户
  • 注册时间: 2008-09-22 15:16
文章分类

全部博文(759)

文章存档

2008年(759)

我的朋友

分类:

2008-09-25 15:55:22

这里采用了Linux下的gcc编译C,并使用了SDL.
这个程序可以作任意精度。



/* fgbm 1.0 fgbm is free software; you can redistribute it and/or modify it under the terms of the GNU General Public License as published by the Free Software Foundation; either version 2, or (at your option) any later version. fgbm is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for more details. You should have received a copy of the GNU General Public License along with fgbm; see the file COPYING. If not, write to the Free Software Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. Contact Info: ygxyvesuvius@gmail.com */ //This is a programme to draw fygenbm pic. //x[0]=Begin; //x[i]=r*x[i-1]*(1-x[i-1]); //draw (y) r from 0 to 4 //draw (x) x[i] i for 1000 to 1999 //The programme is designed by Vesuvius. //ygxyvesuvius@yahoo.com.cn // //You need to pass number about where the r x start and end //and the step long // //The Library I use is SDL. // #include #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; }



--------------------next---------------------

阅读(901) | 评论(0) | 转发(0) |
0

上一篇:Linux 常用命令

下一篇:GRUB简介及实用操作

给主人留下些什么吧!~~