示例#1
0
int main(int ArgumentCount, char **Arguments) {
	
	glutInit(&ArgumentCount, Arguments);
	SetupGraphics();
	
	float frequency = 0.05f;
	float amplitude = 64;
	float Max = 0, Min = 0;
	for(int y = 0; y < 512; y++) {
		for(int x = 0; x < 512; x++) {
		
			//float N = InterpolatedNoise(x);
			float Scale = 0.02f;
			float N = PerlinNoise_2D(x * Scale, y * Scale, 0.8f, 8, 0.3f);
			if(N > Max)
				Max = N;
			if(N < Min)
				Min = N;
			u8 c = (u8)(N * 100.0f) + 128;
			DrawPixel(x + 50, y + 50, Color(c, c, c));
		}
	}
	printf("%f %f\n", Min, Max);
		
	// Main
	glutMainLoop();
	
	return 0;
}
示例#2
0
/* Procedural texture function */
int ptex_fun(float u, float v, GzColor color)
{

int xs=64;
int ys=64;
int i,j;

 if (reset) 
 { 
 image = (GzColor*)malloc(sizeof(GzColor)*(xs+1)*(ys+1));

 for(j=0;j<ys;j++)
 {
	for(i=0;i<xs;i++)
	{
//	image[i+j*xs][RED]=(PerlinNoise_2D(i*3,j)+1)/2;
//	image[i+j*xs][GREEN]=(PerlinNoise_2D(2*i,3*j)+1)/2;
//	image[i+j*xs][BLUE]=(PerlinNoise_2D(i+3*j,j+j)+1)/2;

//	image[i+j*xs][RED]=2*PerlinNoise_2D(i*3,j)+3;
//	image[i+j*xs][GREEN]=0.5*PerlinNoise_2D(2*i,3*j)+i;
//	image[i+j*xs][BLUE]=1.3*PerlinNoise_2D(i+3*j,j+j);

	image[i+j*xs][RED]=((2*PerlinNoise_2D(i*3,j)+3)-1)/4;
	image[i+j*xs][GREEN]=((0.5*PerlinNoise_2D(2*i,3*j)+i)-i+0.5);
	image[i+j*xs][BLUE]=(1.3*PerlinNoise_2D(i+3*j,j+j)+1.3)/2.6;
 
	}
 }
 reset = 0;          
 }/* init is done */



/* bounds-test u,v to make sure nothing will overflow image array bounds */
  if(u<0){u=0;}
  else if(u>1){u=1;}

  if(v<0){v=0;}
  else if(v>1){v=1;}	
	
/* determine texture cell corner values and perform bilinear interpolation */

u=u*(xs-1);
v=v*(ys-1);

int uf,uc,vf,vc;
float s,t;
GzColor exactcolor;

uf=floor(u);
uc=ceil(u);
vf=floor(v);
vc=ceil(v);

s=u-uf;
t=v-vf;


exactcolor[RED]=s*t*image[uc+(vc*xs)][RED]+(1-s)*t*image[uf+(vc*xs)][RED]+s*(1-t)*image[uc+(vf*xs)][RED]+(1-s)*(1-t)*image[uf+(vf*xs)][RED];
exactcolor[GREEN]=s*t*image[uc+(vc*xs)][GREEN]+(1-s)*t*image[uf+(vc*xs)][GREEN]+s*(1-t)*image[uc+(vf*xs)][GREEN]+(1-s)*(1-t)*image[uf+(vf*xs)][GREEN];
exactcolor[BLUE]=s*t*image[uc+(vc*xs)][BLUE]+(1-s)*t*image[uf+(vc*xs)][BLUE]+s*(1-t)*image[uc+(vf*xs)][BLUE]+(1-s)*(1-t)*image[uf+(vf*xs)][BLUE];


/* set color to interpolated GzColor value and return */
/*
 if(exactcolor[RED]<0){exactcolor[RED]=0;}
  else if(exactcolor[RED]>1){exactcolor[RED]=1;}

  if(exactcolor[GREEN]<0){exactcolor[GREEN]=0;}
  else if(exactcolor[GREEN]>1){exactcolor[GREEN]=1;}

 if(exactcolor[BLUE]<0){exactcolor[BLUE]=0;}
  else if(exactcolor[BLUE]>1){exactcolor[BLUE]=1;}
 */

color[RED]=exactcolor[RED];
color[GREEN]=exactcolor[GREEN];
color[BLUE]=exactcolor[BLUE];


return GZ_SUCCESS;// write by me
}