シェルピンスキー・ガスケット注:rand.datは[0,1]で乱数が収められているファイルです。 #include <stdio.h>
#define CALC_REPEAT 1000000
#define SIDE_LENGTH 1.0
#define X0 0.5
#define Y0 0.1
int main(void)
{
FILE *rd,*fs;
double x=X0,y=Y0,r;
int count=0;
if(((rd=fopen("rand.dat","r")) != NULL) && ((fs=fopen("plot_gasket.dat","w+"))!=NULL))
{
fprintf(fs,"%lf %lf\n",x,y);
while(count<CALC_REPEAT)
{
fscanf(rd,"%lf",&r);
switch ((int)(r*3.0))
{
case 0:
x=x/2;
y=y/2;
break;
case 1:
x=(x+SIDE_LENGTH)/2;
y=y/2;
break;
case 2:
x=(x+SIDE_LENGTH/2)/2;
y=(y+SIDE_LENGTH*1.73205/2)/2;
break;
}
fprintf(fs,"%lf %lf\n",x,y);
count++;
}
fclose(rd);
fclose(fs);
}
return 0;
}
2008/07/24 13:29 |
プロフィール
2008年07月
最近の記事
Extension:DynamicPageList3 (DPL3), version 3.5.2: Error: No selection criteria found! You must use at least one of the following parameters: category, namespace, titlematch, linksto, uses, createdby, modifiedby, lastmodifiedby, or their 'not' variants アーカイブ
Extension:DynamicPageList3 (DPL3), version 3.5.2: Error: No selection criteria found! You must use at least one of the following parameters: category, namespace, titlematch, linksto, uses, createdby, modifiedby, lastmodifiedby, or their 'not' variants YouTube
日記を書く <createbox> width=20% preload=Make/Dialy prefix=Alpha 1/シェルピンスキー・ガスケット/ buttonlabel=作る </createbox> 注意:トップページからのみ日記を作成してください。他のページから作ると記事空間がおかしくなります。 |