コード例 #1
0
ファイル: Program.cs プロジェクト: thedanieldude1/DanielCode
 	public static void Main(string[] args){
		int resolution = 1024;
		Bitmap map = new Bitmap(resolution,resolution);
		Bitmap map1 = new Bitmap(resolution,resolution);
				Random rand = new Random();
        int bluramount = 10;
		MySimplexFast gen = new MySimplexFast(rand.Next(),2);
		MySimplexFast gen2 = new MySimplexFast(rand.Next(),32);
		MySimplexFast gen3 = new MySimplexFast(rand.Next(),32);
		MySimplexFast gen4 = new MySimplexFast(rand.Next(),32);
		MySimplexFast gen5 = new MySimplexFast(rand.Next(),32);
		var vor = new Voronoi();
		vor.Frequency = 0.01;
		vor.DistanceEnabled = true;
		var chooser = new Select();
		for(int y = -resolution/2;y<resolution/2;y++){
			for(int x = -resolution/2;x<resolution/2;x++){
				Vector3D samp = new Vector3D(-x,-y,resolution/2);
				//samp.Normalize();
				//samp.MapToSphere();
				double biomeval1 = (gen2.GetValue(samp.X,samp.Y,samp.Z,1,0.0008,2,2,0.6));

                double val1 = (gen.GetValue(samp.X,samp.Y,samp.Z,8,0.01,3,2,0.7));
				double biomeval2 = (gen3.GetValue(samp.X,samp.Y,samp.Z,1,0.001,2,2,0.6)+1)/2;
                double val2 = (gen4.GetValue(samp.X, samp.Y, samp.Z, 16, 0.003, 2, 2, .3));
				//double val2 = (gen2.GetValue((double)x/resolution,(double)y/resolution,0,1,16,2,2,0.3));
				//double val3 = (gen3.GetValue((double)x/resolution,(double)y/resolution,0,1,16,2,2,0.3));
				double biomeval3 = 1-Math.Abs(biomeval2-biomeval1);
				double val3 = 0;//(gen.GetValue(samp.X,samp.Y,samp.Z,8,2,3,.2,0.7))*0.1;
				
				//var totalval=(biomeval1+biomeval2);
				//biomeval1/=totalval;
				//biomeval2/=totalval;
				//biomeval2 = Lerp(biomeval3,biomeval2,biomeval2);
				//biomeval1 = Lerp(biomeval2,biomeval1,biomeval1);
                double left = vor.GetValue(samp.X + bluramount, samp.Y, samp.Z);
                double right = vor.GetValue(samp.X - bluramount, samp.Y, samp.Z);
                double up = vor.GetValue(samp.X, samp.Y + bluramount, samp.Z);
                double down = vor.GetValue(samp.X, samp.Y - bluramount, samp.Z);
                double pixelsval = vor.GetValue(samp.X, samp.Y, samp.Z);
                double val = (pixelsval+right+left+up+down)/5.0;
                if (val != pixelsval)
                {
                    double downright=0;
                    double downleft=0;
                    double upleft=0;
                    double upright = 0;
                    for (int i = 1; i < bluramount; i++)
                    {
                        //if (i == 0) { continue; };
                        left += vor.GetValue(samp.X + i, samp.Y, samp.Z);
                        right += vor.GetValue(samp.X - i, samp.Y, samp.Z);
                        down += vor.GetValue(samp.X, samp.Y + i, samp.Z);
                        up += vor.GetValue(samp.X, samp.Y + i, samp.Z);
                        downright += vor.GetValue(samp.X - i, samp.Y - i, samp.Z);
                        downleft += vor.GetValue(samp.X + i, samp.Y - i, samp.Z);
                        upright += vor.GetValue(samp.X + i, samp.Y + i, samp.Z);
                        upleft += vor.GetValue(samp.X - i, samp.Y + i, samp.Z);
                    }
                    //left = left + vor.GetValue(samp.X + 2, samp.Y, samp.Z) + vor.GetValue(samp.X + 3, samp.Y, samp.Z) + vor.GetValue(samp.X + 4, samp.Y, samp.Z) + vor.GetValue(samp.X + 1, samp.Y, samp.Z);
                    //right = right + vor.GetValue(samp.X - 4, samp.Y, samp.Z) + vor.GetValue(samp.X - 3, samp.Y, samp.Z) + vor.GetValue(samp.X - 2, samp.Y, samp.Z) + vor.GetValue(samp.X - 1, samp.Y, samp.Z);
                   // up = up + vor.GetValue(samp.X, samp.Y + 4, samp.Z) + vor.GetValue(samp.X, samp.Y + 3, samp.Z) + vor.GetValue(samp.X, samp.Y + 2, samp.Z) + vor.GetValue(samp.X, samp.Y + 1, samp.Z);
                   // down = down + vor.GetValue(samp.X, samp.Y - 4, samp.Z) + vor.GetValue(samp.X, samp.Y - 3, samp.Z) + vor.GetValue(samp.X, samp.Y - 2, samp.Z) + vor.GetValue(samp.X, samp.Y - 1, samp.Z);
                     //= vor.GetValue(samp.X-4, samp.Y - 4, samp.Z) + vor.GetValue(samp.X-3, samp.Y - 3, samp.Z) + vor.GetValue(samp.X-2, samp.Y - 2, samp.Z) + vor.GetValue(samp.X-1, samp.Y - 1, samp.Z);
                    // = vor.GetValue(samp.X + 4, samp.Y - 4, samp.Z) + vor.GetValue(samp.X + 3, samp.Y - 3, samp.Z) + vor.GetValue(samp.X + 2, samp.Y - 2, samp.Z) + vor.GetValue(samp.X + 1, samp.Y - 1, samp.Z);
                    // = vor.GetValue(samp.X - 4, samp.Y + 4, samp.Z) + vor.GetValue(samp.X - 3, samp.Y + 3, samp.Z) + vor.GetValue(samp.X - 2, samp.Y + 2, samp.Z) + vor.GetValue(samp.X - 1, samp.Y + 1, samp.Z);
                   // double upright = vor.GetValue(samp.X + 4, samp.Y + 4, samp.Z) + vor.GetValue(samp.X + 3, samp.Y + 3, samp.Z) + vor.GetValue(samp.X + 2, samp.Y + 2, samp.Z) + vor.GetValue(samp.X + 1, samp.Y + 1, samp.Z);
                    val = (pixelsval + left + right + up +down+downright+downleft+upright+upleft) / (5+8*(bluramount-1));
                }
                else
                {
                    
                }
                //val = chooser.Choose(val1,val2,val);//(val1*biomeval1+val2*biomeval2+val3*biomeval3);
                //if(biomeval1>biomeval2) val = Lerp(val2,val1,biomeval1);
				//if(biomeval2>biomeval1) val = Lerp(val2,val1,biomeval2);
				if(val>1) val = 1;
				if(val<-1) val = -1;
				//val*=255;
		  		val = ((val+1)/(1+1) *(1+0)+0)*255;
				double red =255*((biomeval1+1)/2);
				double green = 255*((biomeval2+1)/2);
		  		//val2 = ((val2+1)/(1+1) *(1+0)+0)*255;
		  		//val3 = ((val3+1)/(1+1) *(1+0)+0)*255;
				var test = (rand.NextDouble()/255)*32730+37;
				//Console.Beep((int)test,100);
				map.SetPixel(x+resolution/2,y+resolution/2,Color.FromArgb((int)val,(int)val,(int)val));
				map1.SetPixel(x+resolution/2,y+resolution/2,Color.FromArgb((int)red,(int)green,(int)0));
}}
map.Save("test.png",ImageFormat.Png);
map1.Save("test1.png",ImageFormat.Png);
		Bitmap map2 = new Bitmap(resolution,resolution);
		for(int y = -resolution/2;y<resolution/2;y++){
			for(int x = -resolution/2;x<resolution/2;x++){
				Vector3D samp = new Vector3D(-resolution/2,-y,-(x));
				//samp.Normalize();
				//samp.MapToSphere();

				double val = (gen.GetValue(samp.X,samp.Y,samp.Z,1,0.002,2,2,0.6));
				//double val2 = (gen2.GetValue((double)x/resolution,(double)y/resolution,0,1,16,2,2,0.3));
				//double val3 = (gen3.GetValue((double)x/resolution,(double)y/resolution,0,1,16,2,2,0.3));
		  		val = ((val+1)/(1+1) *(1+0)+0)*255;
		  		//val2 = ((val2+1)/(1+1) *(1+0)+0)*255;
		  		//val3 = ((val3+1)/(1+1) *(1+0)+0)*255;
				map2.SetPixel(x+resolution/2,y+resolution/2,Color.FromArgb((int)val,(int)val,(int)val));
}}
map2.Save("test2.png",ImageFormat.Png);
	}
コード例 #2
0
ファイル: Program.cs プロジェクト: thedanieldude1/DanielCode
 	public static void Main(string[] args){
		int resolution = 1024;
		Bitmap map = new Bitmap(resolution,resolution);
		Bitmap map1 = new Bitmap(resolution,resolution);
				Random rand = new Random();
		MySimplexFast gen = new MySimplexFast(rand.Next(),2);
		MySimplexFast gen2 = new MySimplexFast(rand.Next(),32);
		MySimplexFast gen3 = new MySimplexFast(rand.Next(),32);
		MySimplexFast gen4 = new MySimplexFast(rand.Next(),32);
		MySimplexFast gen5 = new MySimplexFast(rand.Next(),32);
		var vor = new Voronoi();
		vor.Frequency = 0.01;
		//vor.DistanceEnabled = true;
		var chooser = new Select();
		for(int y = -resolution/2;y<resolution/2;y++){
			for(int x = -resolution/2;x<resolution/2;x++){
				Vector3D samp = new Vector3D(-x,-y,resolution/2);
				//samp.Normalize();
				//samp.MapToSphere();
				double biomeval1 = (gen2.GetValue(samp.X,samp.Y,samp.Z,1,0.0008,2,2,0.6));
				
				double val1 = -1;//(gen.GetValue(samp.X,samp.Y,samp.Z,8,0.01,3,2,0.7));
				double biomeval2 = (gen3.GetValue(samp.X,samp.Y,samp.Z,1,0.001,2,2,0.6)+1)/2;
				double val2 = 1;//(gen4.GetValue(samp.X,samp.Y,samp.Z,16,0.003,2,2,.3));
				//double val2 = (gen2.GetValue((double)x/resolution,(double)y/resolution,0,1,16,2,2,0.3));
				//double val3 = (gen3.GetValue((double)x/resolution,(double)y/resolution,0,1,16,2,2,0.3));
				double biomeval3 = 1-Math.Abs(biomeval2-biomeval1);
				double val3 = 0;//(gen.GetValue(samp.X,samp.Y,samp.Z,8,2,3,.2,0.7))*0.1;
				
				var totalval=(biomeval1+biomeval2);
				//biomeval1/=totalval;
				//biomeval2/=totalval;
				//biomeval2 = Lerp(biomeval3,biomeval2,biomeval2);
				//biomeval1 = Lerp(biomeval2,biomeval1,biomeval1);
				double val = chooser.Choose(val1,val2,vor.GetValue(samp.X,samp.Y,samp.Z));//(val1*biomeval1+val2*biomeval2+val3*biomeval3);
				//if(biomeval1>biomeval2) val = Lerp(val2,val1,biomeval1);
				//if(biomeval2>biomeval1) val = Lerp(val2,val1,biomeval2);
				if(val>1) val = 1;
				if(val<-1) val = -1;
				//val*=255;
				val= vor.GetValue(x,y,0);
		  		val = ((val+1)/(1+1) *(1+0)+0)*255;
				double red =255*((biomeval1+1)/2);
				double green = 255*((biomeval2+1)/2);
		  		//val2 = ((val2+1)/(1+1) *(1+0)+0)*255;
		  		//val3 = ((val3+1)/(1+1) *(1+0)+0)*255;
				var test = (rand.NextDouble()/255)*32730+37;
				//Console.Beep((int)test,100);
				map.SetPixel(x+resolution/2,y+resolution/2,Color.FromArgb((int)val,(int)val,(int)val));
				map1.SetPixel(x+resolution/2,y+resolution/2,Color.FromArgb((int)red,(int)green,(int)0));
				Console.ReadLine();
}}
map.Save("test.png",ImageFormat.Png);
map1.Save("test1.png",ImageFormat.Png);
		Bitmap map2 = new Bitmap(resolution,resolution);
		for(int y = -resolution/2;y<resolution/2;y++){
			for(int x = -resolution/2;x<resolution/2;x++){
				Vector3D samp = new Vector3D(-resolution/2,-y,-(x));
				//samp.Normalize();
				//samp.MapToSphere();

				double val = (gen.GetValue(samp.X,samp.Y,samp.Z,1,0.002,2,2,0.6));
				//double val2 = (gen2.GetValue((double)x/resolution,(double)y/resolution,0,1,16,2,2,0.3));
				//double val3 = (gen3.GetValue((double)x/resolution,(double)y/resolution,0,1,16,2,2,0.3));
		  		val = ((val+1)/(1+1) *(1+0)+0)*255;
		  		//val2 = ((val2+1)/(1+1) *(1+0)+0)*255;
		  		//val3 = ((val3+1)/(1+1) *(1+0)+0)*255;
				map2.SetPixel(x+resolution/2,y+resolution/2,Color.FromArgb((int)val,(int)val,(int)val));
}}
map2.Save("test2.png",ImageFormat.Png);
	}