Scratchpad Wiki
Advertisement

シェルピンスキー・ガスケット

注: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;
	}
Gnuplot gasket

2008/07/24 13:29

プロフィール
  • 名前:Tommy6
  • ニックネーム:( ・ω・)
  • 性別:男
  • 生年月日:
  • 出身地:北
  • 血液型:B
2008年07月
1 2 3 4 5
6 7 8 9 10 11 12
13 14 15 16 17 18 19
20 21 22 23 24 25 26
27 28 29 30 31
最近の記事

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> 注意:トップページからのみ日記を作成してください。他のページから作ると記事空間がおかしくなります。


Advertisement