コード例 #1
0
ファイル: terrain.cpp プロジェクト: verdoss/TerrainGenerator
int main (void) //test
{
	srand((unsigned int)time(NULL));//seed rand with time, small %'s only
	int*vals=NULL;
	int n=6, size=(int)pow(2,(double)n);
	int avg=0,count=0;
	while(1)
	{
		if(vals!=NULL)free(vals);
		vals=(int*)malloc(size*size*sizeof(int));
		fractal_noise(vals,n);
		avg=0;count=0;
		for(int i=0;i<size*size;i++) {
			avg+=vals[i];count++;
		}	avg/=count;
		for(int x=0;x<size;x++)
		{	for(int y=0;y<size;y++)
			{	if(vals[x*size+y]>=10)
					printf(":^");
				else if(vals[x*size+y]<0)
					printf(":-");
				else
					printf(":%d",vals[x*size+y]);
		
			}
			printf(":\n");
		}
		system("pause");
	}
}
コード例 #2
0
ファイル: mapgen.c プロジェクト: CraigCraig/OpenRCT2
static void mapgen_simplex(mapgen_settings *settings)
{
	sint32 x, y;

	float freq = settings->simplex_base_freq * (1.0f / _heightSize);
	sint32 octaves = settings->simplex_octaves;

	sint32 low = settings->simplex_low;
	sint32 high = settings->simplex_high;

	noise_rand();
	for (y = 0; y < _heightSize; y++) {
		for (x = 0; x < _heightSize; x++) {
			float noiseValue = clamp(-1.0f, fractal_noise(x, y, freq, octaves, 2.0f, 0.65f), 1.0f);
			float normalisedNoiseValue = (noiseValue + 1.0f) / 2.0f;

			set_height(x, y, low + (sint32)(normalisedNoiseValue * high));
		}
	}
}