Algorithm °æ (¾«»ªÇø)
·¢ÐÅÈË: sino (²èË®²©Ê¿), ÐÅÇø: Theory
±ê Ìâ: »ìãçͼ¼¯--mandleblot¼¯
·¢ÐÅÕ¾: ¹þ¹¤´ó×϶¡Ïã (Sun Aug 27 13:27:40 2000), תÐÅ
·¢ÐÅÈË: FreeFighter.bbs@bbs.whnet.edu.cn (×ÔÓÉ¿Õ¼ä), ÐÅÇø: algorithm
·¢ÐÅÕ¾: Î人°×Ôƻƺ×Õ¾ (Tue Jan 6 05:11:34 1998)
תÐÅÕ¾: ACEBBS!ustcnews!whbbs
NÄêÒÔÇ°×ö¹ýһЩ»ìãçºÍ·ÖÐεijÌÐò£¬´¿´â³öÓÚºÃÍ棬ÏÖPOST³öÀ´£¬
ÒÔ÷ÏÓÐÐÄÕß¡£
ÓÉÓÚÄÇʱºòÖ»ÓÐTC£¬ËùÒÔÄãÏÖÔÚ×îºÃÕÒµ½ÄǸö¹ÅÀϵļһ
MANDELBLOT¼¯µÄͼÏó¿ÉÒÔ˵ÊÇ»ìãçµÄ±êÖ¾£¬ÎÞÈ˲»Îª´ËÉîÉîÎüÒý£¬
ÎÒµÚÒ»´Î»æ³öÄǸöºù«״µÄ¹ÖÎïʱ£¬ÐË·ÜÖ®ÇéÄÑÒÔÃ÷×´£¬¹Ê½«Æä
×ö³ÉÁËÒ»¸öÒ»Ö±ÏÔʾϸ½ÚͼƬµÄ³ÌÐò£¬¹Ê¶ø¿ÉÒÔ¿´µ½ÎÞÇîÎÞ¾¡µÄ
É«²Ê°ßìµµÄħ»¡£±àÒëÒÔϳÌÐò£¬ÔËÐкó£¬Ã¿ÏÔʾһ·ùͼƬ£¬ÓÃ
¹â±ê¼ü¿ÉÒÔÑ¡ÔñеķŴóÇøÓòÒÔ»æÖÆеÄͼƬ¡£¡£
Enjoy yourself.
#include<stdio.h>
#include<alloc.h>
#include<math.h>
#include<complex.h>
#include<graphics.h>
#include <stdlib.h>
#include <conio.h>
#include <dos.h>
#include <bios.h>
#include "key.h"
int NUMBER;
float eff=0.009;
float a0,b0,c0,d0;
int mandel(float,float,float,float);
int getchoice(int *,int *,void far *);
void main(void)
{
void far *buf;
int gdriver = DETECT, gmode, errorcode;
int x,y,i,j,c,e,n;
char buf1[1000];
char filename[]="MANDEL_A.IMG";
FILE *fp;
initgraph(&gdriver, &gmode, "d:\\bc\\bgi");
errorcode = graphresult();
if (errorcode != grOk){
printf("Graphics error: %s\n", grapherrormsg(errorcode));
printf("Press any key to halt:");
getch();
exit(1);
}
a0=b0=0; c0=d0=1;
NUMBER=48;
buf= &buf1[0];
getimage(0,0,32,24, buf);
for(i=4;i<900;i++) buf1[i]=0xff;
mandel(0,0,1,1);
n=0; e=0xff;
do{
x=0;y=0;
/* fp=fopen(filename,"wb");
if(fp==NULL) break;
for(j=0;j<480;j++){
for(i=0;i<640;i++){
c=getpixel(i,j);
if(e==c){
n++;
if(n<4000) continue;
}
putw((n<<4)|e,fp);
e=c; n=0;
}
}
putw((n<<4)|e,fp);
if(fclose(fp)) break;
filename[7]++;
*/ sound(1000);
delay(100);
nosound();
bioskey(0);
if(getchoice(&x,&y,buf)) break;
mandel(x+16,y-12,10,10);
}while(1);
closegraph();
}
int mandel(float a1,float b1,float c1,float d1)
{
complex z1,z2;
int i,j,k;
a0=a1/c0+a0; c0*=c1;
b0=b1/d0+b0; d0*=d1;
for(j=239;j>=-240;j--){
for(i=-320;i<319;i++){
z1=complex((i/c0+a0)*eff,(j/d0+b0)*eff);
z2=complex(0,0);
for(k=0;k<NUMBER;k++){
z2=z2*z2+z1;
if(abs(real(z2))>2) break;
else if(abs(imag(z2))>2) break;
}
putpixel(i+320,240-j,k/3);
if(bioskey(1)) return 1;
}
}
NUMBER+=8;
return 0;
}
int getchoice(int *x,int *y,void far *buf)
{
int x1,y1;
int key;
x1=*x; y1=*y;
do{
putimage(x1+320, 240-y1, buf, XOR_PUT);
key=bioskey(0);
switch(key){
case ESC: return -1;
case LEFT: x1--;break;
case RIGHT: x1++;break;
case UP: y1++;break;
case DOWN: y1--;break;
default: break;
}
putimage((*x)+320, 240-(*y), buf, XOR_PUT);
*x=x1; *y=y1;
}while(key!=CR);
return 0;
}
ê
--
ÓÀºãµÄÖÐ΢×Ó
-------------------------------------------------o
¡ù ÐÞ¸Ä:£®fib ì¶ Aug 27 13:25:18 Ð޸ı¾ÎÄ£®[FROM: bbs.hit.edu.cn]
--
¡ù ת¼Ä:£®ÄϾ©´óѧС°ÙºÏ bbs.nju.edu.cn£®[FROM: bbs.hit.edu.cn]
--
¡î À´Ô´:£®¹þ¹¤´ó×϶¡Ïã bbs.hit.edu.cn£®[FROM: fib.bbs@bbs.nju.edu.]
Powered by KBS BBS 2.0 (http://dev.kcn.cn)
Ò³ÃæÖ´ÐÐʱ¼ä£º2.472ºÁÃë