当前位置: 首页>>代码示例>>C#>>正文


C# Channel.putPixel方法代码示例

本文整理汇总了C#中Procedurality.Channel.putPixel方法的典型用法代码示例。如果您正苦于以下问题:C# Channel.putPixel方法的具体用法?C# Channel.putPixel怎么用?C# Channel.putPixel使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在Procedurality.Channel的用法示例。


在下文中一共展示了Channel.putPixel方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。

示例1: getDistance

 public Channel getDistance(float c1, float c2, float c3)
 {
     Channel channel = new Channel(sizeX, sizeY);
     for (int y = 0; y < sizeY; y++)
     {
         for (int x = 0; x < sizeX; x++)
         {
             channel.putPixel(x, y, c1*dist1.getPixel(x, y) + c2*dist2.getPixel(x, y) + c3*dist3.getPixel(x, y));
         }
     }
     return channel.normalize();
 }
开发者ID:N3X15,项目名称:Procedurality4NET,代码行数:12,代码来源:Voronoi.cs

示例2: Hill

		public Hill(int size,int xp,int yp,float radius)
		{
			double r=(double)radius;
			channel = new Channel(size,size);
			double hill_height=5.0d*(radius/40.0d);
			for(int x=0;x<size;x++)
			{
				for(int y=0;y<size;y++)
				{
					double dx = (double)(yp-x);
					double dy = (double)(xp-y);
					double dist = Math.Sqrt(dx*dx + dy*dy);
					if(dist<radius)
					{
						double height = 1.0d-((dx*dx + dy*dy) / (r*r));
						height = (height*hill_height);
						channel.putPixel(x,y,Convert.ToSingle(height));//$radius^2 + (($x-$hx)^2 - ($y-(256-$hy))^2);
					}
					//channel.putPixel(x,y,(radius*radius) + (((x-dx)*(x-dx)) - ((y-dy)*(y-dy))));
				}
			}
			channel.normalize();
		}
开发者ID:N3X15,项目名称:VoxelSim,代码行数:23,代码来源:Hills.cs

示例3: erode3

        public static Channel erode3(Channel channel, Channel rain_map, float vaporization, int rain_freq, int iterations)
        {
            Channel vapor_map = rain_map.copy().multiply(0.5f);
            Channel height_map_diff = new Channel(channel.width, channel.height).fill(0f);
            Channel water_map = new Channel(channel.width, channel.height).fill(0f);
            Channel water_map_diff = new Channel(channel.width, channel.height).fill(0f);
            Channel sediment_map = new Channel(channel.width, channel.height).fill(0f);
            Channel sediment_map_diff = new Channel(channel.width, channel.height).fill(0f);

            Console.Write("Hydraulic erosion 3: ");

            for (int i = 0; i < iterations; i++) {

                Console.Write(".");

                // save frames
                /*
                if (channel.width > 128 && i%8 == 0) {
                    if (i < 10) {
                        channel.toLayer().saveAsPNG("erosion00" + i);
                    } else if (i < 100) {
                        channel.toLayer().saveAsPNG("erosion0" + i);
                    } else {
                        channel.toLayer().saveAsPNG("erosion" + i);
                    }
                }
                */

                // rain
                if (i%rain_freq == 0) {
                    water_map.channelAdd(rain_map);
                }

                // water and sediment transport
                for (int y = 1; y < channel.height - 1; y++) {
                    for (int x = 1; x < channel.width - 1; x++) {

                        // calculate total heights and height differences
                        float h = channel.getPixel(x, y) + water_map.getPixel(x, y);

                        float h1 = channel.getPixel(x, y + 1) + water_map.getPixel(x, y + 1) + sediment_map.getPixel(x, y + 1);
                        float h2 = channel.getPixel(x - 1, y) + water_map.getPixel(x - 1, y) + sediment_map.getPixel(x - 1, y);
                        float h3 = channel.getPixel(x + 1, y) + water_map.getPixel(x + 1, y) + sediment_map.getPixel(x + 1, y);
                        float h4 = channel.getPixel(x, y - 1) + water_map.getPixel(x, y - 1) + sediment_map.getPixel(x, y - 1);

                        float d1 = h - h1;
                        float d2 = h - h2;
                        float d3 = h - h3;
                        float d4 = h - h4;

                        // calculate amount of water and sediment to transport
                        float total_height = 0;
                        float total_height_diff = 0;
                        int cells = 1;

                        if (d1 > 0) {
                            total_height_diff+= d1;
                            total_height+= h1;
                            cells++;
                        }
                        if (d2 > 0) {
                            total_height_diff+= d2;
                            total_height+= h2;
                            cells++;
                        }
                        if (d3 > 0) {
                            total_height_diff+= d3;
                            total_height+= h3;
                            cells++;
                        }
                        if (d4 > 0) {
                            total_height_diff+= d4;
                            total_height+= h4;
                            cells++;
                        }

                        if (cells == 1) {
                            continue;
                        }

                        float avr_height = total_height/cells;

                        float water_amount = Math.Min(water_map.getPixel(x, y), h - avr_height);
                        water_map_diff.putPixel(x, y, water_map_diff.getPixel(x, y) - water_amount);
                        float water_inv = water_amount/total_height_diff;

                        float sediment_amount = sediment_map.getPixel(x, y);
                        sediment_map_diff.putPixel(x, y, sediment_map_diff.getPixel(x, y) - sediment_amount);
                        float sediment_inv = sediment_amount/total_height_diff;

                        float dissolve;

                        // transport water and sediment and dissolve more material
                        if (d1 > 0) {
                            water_map_diff.putPixel(x, y + 1, water_map_diff.getPixel(x, y + 1) + d1*water_inv);
                            dissolve = 10f*d1*water_amount;
                            sediment_map_diff.putPixel(x, y + 1, sediment_map_diff.getPixel(x, y + 1) + d1*sediment_inv + dissolve);
                            height_map_diff.putPixel(x, y + 1, height_map_diff.getPixel(x, y + 1) - dissolve);
                        }
                        if (d2 > 0) {
//.........这里部分代码省略.........
开发者ID:N3X15,项目名称:Procedurality4NET,代码行数:101,代码来源:ErodeHydraulic.cs

示例4: perturb

		public Channel perturb(Channel perturb, float magnitude) {
			Channel channel = new Channel(width, height);
			for (int y = 0; y < height; y++) {
				for (int x = 0; x < width; x++) {
					float perturbation = magnitude*(perturb.getPixel(x, y) - 0.5f);
					float x_coord = x + width*perturbation;
					int x_coord_lo = (int)x_coord;
					int x_coord_hi = x_coord_lo + 1;
					float x_frac = x_coord - x_coord_lo;
					float y_coord = y + height*perturbation;
					int y_coord_lo = (int)y_coord;
					int y_coord_hi = y_coord_lo + 1;
					float y_frac = y_coord - y_coord_lo;
					float val1 = Tools.interpolateLinear(getPixelWrap(x_coord_lo, y_coord_lo), getPixelWrap(x_coord_hi, y_coord_lo), x_frac);
					float val2 = Tools.interpolateLinear(getPixelWrap(x_coord_lo, y_coord_hi), getPixelWrap(x_coord_hi, y_coord_hi), x_frac);
					channel.putPixel(x, y, Tools.interpolateLinear(val1, val2, y_frac));
				}
			}
			pixels = channel.getPixels();
			return this;
		}
开发者ID:N3X15,项目名称:VoxelSim,代码行数:21,代码来源:Channel.cs

示例5: rotate

		public Channel rotate(int degrees) {
			Channel channel = null;
			int tmp = width;
			switch (degrees) {
				case 90:
					channel = new Channel(height, width);
					for (int y = 0; y < height; y++) {
						for (int x = 0; x < width; x++) {
							channel.putPixel(y, width - x - 1, getPixel(x, y));
						}
					}
					width = height;
					height = tmp;
					break;
				case 180:
					channel = new Channel(width, height);
					for (int y = 0; y < height; y++) {
						for (int x = 0; x < width; x++) {
							channel.putPixel(width - x - 1, height - y - 1, getPixel(x, y));
					}
					}
					break;
				case 270:
					channel = new Channel(height, width);
					for (int y = 0; y < height; y++) {
						for (int x = 0; x < width; x++) {
							channel.putPixel(height - y - 1, x, getPixel(x, y));
						}
					}
					width = height;
					height = tmp;
					break;
				default:
					throw new Exception("Rotation degrees not a multiple of 90");
			}
			pixels = channel.getPixels();
			return this;
		}
开发者ID:N3X15,项目名称:VoxelSim,代码行数:38,代码来源:Channel.cs

示例6: scaleFast

		public Channel scaleFast(int new_width, int new_height) {
			if (width == new_width && height == new_height) {
				return this;
			}
			Channel channel = new Channel(new_width, new_height);
			int x_coord = 0;
			int y_coord = 0;
			for (int y = 0; y < new_height; y++) {
				for (int x = 0; x < new_width; x++) {
					x_coord = x*width/new_width;
					y_coord = y*height/new_height;
					channel.putPixel(x, y, getPixel(x_coord, y_coord));
				}
			}
			pixels = channel.getPixels();
			width = new_width;
			height = new_height;
			return this;
		}
开发者ID:N3X15,项目名称:VoxelSim,代码行数:19,代码来源:Channel.cs

示例7: offset

		public Channel offset(int x_offset, int y_offset) {
			Channel channel = new Channel(width, height);
			for (int y = 0; y < height; y++) {
				for (int x = 0; x < width; x++) {
					channel.putPixel(x, y, getPixelWrap(x - x_offset, y - y_offset));
				}
			}
			pixels = channel.getPixels();
			return this;
		}
开发者ID:N3X15,项目名称:VoxelSim,代码行数:10,代码来源:Channel.cs

示例8: cropWrap

		public Channel cropWrap(int x_lo, int y_lo, int x_hi, int y_hi) {
			int new_width = x_hi - x_lo + 1;
			int new_height = y_hi - y_lo + 1;
			Channel channel = new Channel(new_width, new_height);
			for (int y = 0; y < new_height; y++) {
				int y_old = y + y_lo;
				for (int x = 0; x < new_width; x++) {
					int x_old = x + x_lo;
					if (x_old < 0 || x_old >= width || y_old < 0 || y_old >= height) {
						channel.putPixel(x, y, getPixelWrap(x_old, y_old));
					} else {
						channel.putPixel(x, y, getPixel(x_old, y_old));
					}
				}
			}
			return channel;
		}
开发者ID:N3X15,项目名称:VoxelSim,代码行数:17,代码来源:Channel.cs

示例9: smooth

		public Channel smooth(int radius, Channel mask) {
			radius = Math.Max(1, radius);
			Channel filter = new Channel(width, height);
			float factor = 1f/((2*radius + 1)*(2*radius + 1));
			for (int y = 0; y < height; y++) {
				for (int x = 0; x < width; x++) {
					filter.putPixel(x, y, factor*getPixel(x, y));
				}
			}
			for (int x = radius; x < width - radius; x++) {
				int y = radius;
				float sum = 0f;
				for (int i = -radius; i < radius + 1; i++) {
					for (int j = -radius; j < radius + 1; j++) {
						sum += filter.getPixel(x + j, y + i);
					}
				}
				for (y++; y < height - radius; y++) {
					float alpha = mask.getPixel(x, y);
					if (alpha > 0) {
						for (int j = -radius; j < radius + 1; j++) {
							sum -= filter.getPixel(x + j, y - radius - 1);
							sum += filter.getPixel(x + j, y + radius);
						}
						putPixel(x, y, alpha*sum + (1f - alpha)*getPixel(x, y));
					}
				}
			}
			return this;
		}
开发者ID:N3X15,项目名称:VoxelSim,代码行数:30,代码来源:Channel.cs

示例10: smoothWrap

		public Channel smoothWrap(int radius) {
			radius = Math.Max(1, radius);
			Channel filter = new Channel(width, height);
			float factor = 1f/((2*radius + 1)*(2*radius + 1));
			for (int y = 0; y < height; y++) {
				for (int x = 0; x < width; x++) {
					filter.putPixel(x, y, factor*getPixel(x, y));
				}
			}
			for (int x = 0; x < width; x++) {
				for (int y = 0; y < height; y++) {
					float sum = 0f;
					for (int i = -radius; i < radius + 1; i++) {
						for (int j = -radius; j < radius + 1; j++) {
							sum += filter.getPixelWrap(x + j, y + i);
						}
					}
					putPixel(x, y, sum);
				}
			}
			return this;
		}
开发者ID:N3X15,项目名称:VoxelSim,代码行数:22,代码来源:Channel.cs

示例11: smoothFast

		public Channel smoothFast() {
			Channel filter = new Channel(width, height);
			for (int y = 0; y < height; y++) {
				for (int x = 0; x < width; x++) {
					filter.putPixel(x, y, 0.25f*getPixel(x, y));
				}
			}
			for (int y = 0; y < height; y++) {
				for (int x = 0; x < width; x++) {
					putPixel(x, y, filter.getPixelWrap(x - 1, y) + filter.getPixelWrap(x + 1, y) + filter.getPixelWrap(x, y - 1) + filter.getPixelWrap(x, y + 1));
				}
			}
			return this;
		}
开发者ID:N3X15,项目名称:VoxelSim,代码行数:14,代码来源:Channel.cs

示例12: flipH

		public Channel flipH() {
			Channel channel = new Channel(width, height);
			for (int y = 0; y < height; y++) {
				for (int x = 0; x < width; x++) {
					channel.putPixel(x, y, getPixel(width - x - 1, y));
				}
			}
			pixels = channel.getPixels();
			return this;
		}
开发者ID:N3X15,项目名称:VoxelSim,代码行数:10,代码来源:Channel.cs

示例13: LoadTerrain

 public static Channel LoadTerrain(String file)
 {
     using (FileStream stream = new FileStream(file, FileMode.Open, FileAccess.Read, FileShare.Read))
     {
         Bitmap bitmap = new Bitmap(stream);
         try
         {
             Channel terrain = new Channel(bitmap.Width, bitmap.Height);
             Console.WriteLine("LOADED {0}x{1} BITMAP!", bitmap.Height, bitmap.Width);
             for (int x = 0; x < bitmap.Width; x++)
             {
                 for (int y = 0; y < bitmap.Height; y++)
                 {
                     terrain.putPixel(x, y, bitmap.GetPixel(x, y).GetBrightness());
                 }
             }
             Console.WriteLine("LOADED {0}x{1} CHANNEL!", terrain.getHeight(), terrain.getWidth());
             return terrain;//.invert();
         }
         catch (IOException)
         {
             Console.WriteLine("Cannot find " + file + ", using blank channel.");
             return new Channel(256, 256);
         }
     }
 }
开发者ID:N3X15,项目名称:Procedurality4NET,代码行数:26,代码来源:Main.cs

示例14: erode5

        public static Channel erode5(Channel channel, Channel rain, float erosion_water, float erosion_flow, float evaporation, float water_threshold, float solulibility, int ipr, int iterations)
        {
            Channel w  = new Channel(channel.width, channel.height); // water map
            Channel dw = new Channel(channel.width, channel.height); // delta water map
            Channel s  = new Channel(channel.width, channel.height); // sediment map
            Channel ds = new Channel(channel.width, channel.height); // delta sediment map

            Console.Write("Hydraulic erosion 5: ");

            for (int i = 0; i < iterations; i++) {

                Console.Write(".");

                // save frames
                /*
                if (channel.width > 128 && i%10 == 0) {
                    if (i < 10) {
                        channel.toLayer().saveAsPNG("erosion00" + i);
                    } else if (i < 100) {
                        channel.toLayer().saveAsPNG("erosion0" + i);
                    } else {
                        channel.toLayer().saveAsPNG("erosion" + i);
                    }
                }
                */

                // water is added according to rain map
                if (i%ipr == 0) {
                    w.channelAdd(rain);
                }

                // the presence of water dissolves material
                channel.channelSubtract(w.copy().multiply(erosion_water));
                s.channelAdd(w.copy().multiply(erosion_water));

                // water and sediment are transported
                float h, h1, h2, h3, h4, d1, d2, d3, d4, total_height, total_height_diff, total_height_diff_inv, avr_height, water_amount;
                int cells;
                for (int y = 0; y < channel.height; y++) {
                    for (int x = 0; x < channel.width; x++) {

                        // water transport
                        // calculate total heights and height differences
                        h = channel.getPixel(x, y) + w.getPixel(x, y) + s.getPixel(x, y);

                        h1 = channel.getPixelWrap(x    , y + 1) + w.getPixelWrap(x    , y + 1) + s.getPixelWrap(x    , y + 1);
                        h2 = channel.getPixelWrap(x - 1, y    ) + w.getPixelWrap(x - 1, y    ) + s.getPixelWrap(x - 1, y    );
                        h3 = channel.getPixelWrap(x + 1, y    ) + w.getPixelWrap(x + 1, y    ) + s.getPixelWrap(x + 1, y    );
                        h4 = channel.getPixelWrap(x    , y - 1) + w.getPixelWrap(x    , y - 1) + s.getPixelWrap(x    , y - 1);

                        d1 = h - h1;
                        d2 = h - h2;
                        d3 = h - h3;
                        d4 = h - h4;

                        // calculate amount of water to transport
                        total_height = 0f;
                        total_height_diff = 0f;
                        cells = 1;

                        if (d1 > 0) {
                            total_height_diff+= d1;
                            total_height+= h1;
                            cells++;
                        }
                        if (d2 > 0) {
                            total_height_diff+= d2;
                            total_height+= h2;
                            cells++;
                        }
                        if (d3 > 0) {
                            total_height_diff+= d3;
                            total_height+= h3;
                            cells++;
                        }
                        if (d4 > 0) {
                            total_height_diff+= d4;
                            total_height+= h4;
                            cells++;
                        }

                        if (cells == 1) {
                            continue;
                        }

                        avr_height = total_height/cells;
                        water_amount = Math.Min(w.getPixel(x, y), h - avr_height);
                        dw.putPixel(x, y, dw.getPixel(x, y) - water_amount);
                        total_height_diff_inv = water_amount/total_height_diff;

                        // transport water
                        if (d1 > 0) {
                            dw.putPixelWrap(x, y + 1, dw.getPixelWrap(x, y + 1) + d1*total_height_diff_inv);
                        }
                        if (d2 > 0) {
                            dw.putPixelWrap(x - 1, y, dw.getPixelWrap(x - 1, y) + d2*total_height_diff_inv);
                        }
                        if (d3 > 0) {
                            dw.putPixelWrap(x + 1, y, dw.getPixelWrap(x + 1, y) + d3*total_height_diff_inv);
                        }
//.........这里部分代码省略.........
开发者ID:N3X15,项目名称:Procedurality4NET,代码行数:101,代码来源:ErodeHydraulic.cs

示例15: erode4

        public static Channel erode4(Channel channel, float rain_amount, float vaporization, int rain_freq, int iterations)
        {
            Channel water_map = new Channel(channel.width, channel.height).fill(0f);
            Channel water_map_diff = new Channel(channel.width, channel.height).fill(0f);
            Channel height_map_diff = new Channel(channel.width, channel.height).fill(0f);

            Console.Write("Hydraulic erosion 4: ");

            for (int i = 0; i < iterations; i++) {

                Console.Write(".");

                // save frames
                /*
                if (channel.width > 128 && i%10 == 0) {
                    if (i < 10) {
                        channel.toLayer().saveAsPNG("erosion00" + i);
                    } else if (i < 100) {
                        channel.toLayer().saveAsPNG("erosion0" + i);
                    } else {
                        channel.toLayer().saveAsPNG("erosion" + i);
                    }
                }
                */

                // rain erodes the underlying terrain
                if (i%rain_freq == 0) {
                    water_map.channelAdd(channel.copy().multiply(rain_amount));
                }

                // water and sediment transport
                for (int y = 1; y < channel.height - 1; y++) {
                    for (int x = 1; x < channel.width - 1; x++) {

                        // calculate total heights and height differences
                        float h = channel.getPixel(x, y) + water_map.getPixel(x, y);

                        float h1 = channel.getPixel(x, y + 1) + water_map.getPixel(x, y + 1);
                        float h2 = channel.getPixel(x - 1, y) + water_map.getPixel(x - 1, y);
                        float h3 = channel.getPixel(x + 1, y) + water_map.getPixel(x + 1, y);
                        float h4 = channel.getPixel(x, y - 1) + water_map.getPixel(x, y - 1);

                        float d1 = h - h1;
                        float d2 = h - h2;
                        float d3 = h - h3;
                        float d4 = h - h4;

                        // calculate amount of water to transport
                        float total_height = 0;
                        float total_height_diff = 0;
                        int cells = 1;

                        if (d1 > 0) {
                            total_height_diff+= d1;
                            total_height+= h1;
                            cells++;
                        }
                        if (d2 > 0) {
                            total_height_diff+= d2;
                            total_height+= h2;
                            cells++;
                        }
                        if (d3 > 0) {
                            total_height_diff+= d3;
                            total_height+= h3;
                            cells++;
                        }
                        if (d4 > 0) {
                            total_height_diff+= d4;
                            total_height+= h4;
                            cells++;
                        }

                        if (cells == 1) {
                            continue;
                        }

                        float avr_height = total_height/cells;
                        float water_amount = Math.Min(water_map.getPixel(x, y), h - avr_height);
                        water_map_diff.putPixel(x, y, water_map_diff.getPixel(x, y) - water_amount);
                        float total_height_diff_inv = water_amount/total_height_diff;

                        // transport water
                        if (d1 > 0) {
                            water_amount = d1*total_height_diff_inv;
                            water_map_diff.putPixel(x, y + 1, water_map_diff.getPixel(x, y + 1) + water_amount);
                            height_map_diff.putPixel(x, y + 1, height_map_diff.getPixel(x, y + 1) - 0.1f*water_amount);
                        }
                        if (d2 > 0) {
                            water_amount = d2*total_height_diff_inv;
                            water_map_diff.putPixel(x - 1, y, water_map_diff.getPixel(x - 1, y) + water_amount);
                            height_map_diff.putPixel(x - 1, y, height_map_diff.getPixel(x - 1, y) - 0.1f*water_amount);
                        }
                        if (d3 > 0) {
                            water_amount = d3*total_height_diff_inv;
                            water_map_diff.putPixel(x + 1, y, water_map_diff.getPixel(x + 1, y) + water_amount);
                            height_map_diff.putPixel(x + 1, y, height_map_diff.getPixel(x + 1, y) - 0.1f*water_amount);
                        }
                        if (d4 > 0) {
                            water_amount = d4*total_height_diff_inv;
//.........这里部分代码省略.........
开发者ID:N3X15,项目名称:Procedurality4NET,代码行数:101,代码来源:ErodeHydraulic.cs


注:本文中的Procedurality.Channel.putPixel方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。