本文整理汇总了C#中Grid.SetEach方法的典型用法代码示例。如果您正苦于以下问题:C# Grid.SetEach方法的具体用法?C# Grid.SetEach怎么用?C# Grid.SetEach使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类Grid
的用法示例。
在下文中一共展示了Grid.SetEach方法的4个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。
示例1: Main
static void Main( string[] args )
{
const int size = 1000;
var blocks = new Grid<bool>( new Size( size, size ) );
blocks.SetEach( () => RandomHelper.Random.NextDouble() < 0.4 );
var line = new Line( new Point( 0, 0 ), new Point( size - 1, size - 1 ) );
var points = line.DrunkenWalk( 0.25, blocks.Bounds ).Distinct();
var pointsHash = new HashSet<IPoint>( points );
blocks.SetEach( ( value, point ) => pointsHash.Contains( point ) ? false : value );
var flood = blocks.FloodFill( new Point( 0, 0 ) );
var fill = new Grid<bool>( new Size( size, size ) );
foreach( var point in flood ) {
fill[ point ] = true;
}
File.WriteAllText( "blocks.pbm", blocks.ToPbm() );
File.WriteAllText( "fill.pbm", fill.ToPbm() );
}
示例2: ToGrid
public static IGrid<Rgba> ToGrid( this Bitmap bitmap )
{
var grid = new Grid<Rgba>( bitmap.Width, bitmap.Height );
using( var clone = new Bitmap( bitmap.Width, bitmap.Height, PixelFormat.Format32bppPArgb ) ) {
using( var graphics = Graphics.FromImage( clone ) ) {
graphics.DrawImage( bitmap, new System.Drawing.Rectangle( 0, 0, clone.Width, clone.Height ) );
}
var bitmapData = clone.LockBits(
new System.Drawing.Rectangle( 0, 0, grid.Width, grid.Height ),
ImageLockMode.ReadWrite,
clone.PixelFormat
);
grid.SetEach( bitmapData.GetPixel );
clone.UnlockBits( bitmapData );
}
return grid;
}
示例3: Dump
private void Dump()
{
var color = new Grid<Rgba>(_map.Size);
color.SetEach(
(rgba, point) =>
{
var cBack = GetBackgroundColor(point, true);
var fore = ConsoleToRgbaConverter.FormatColor(GetForegroundColor(new Point(), point, true));
var back =
_map.SilentPaths[point] ? ConsoleToRgbaConverter.FormatColor(cBack).Average(new Rgba(0, 255, 0))
: ConsoleToRgbaConverter.FormatColor(cBack);
if (cBack == ConsoleColor.DarkGreen && _map.Trees[point] != ".")
{
back = new Rgba(0, 255, 0);
var noiseToLightness = ((_map.Noise[point] / 255.0) * 0.5) + 0.125;
return back.SetBrightness(noiseToLightness * back.ToHsla().Lightness);
}
return back.Average(fore, 2);
}
);
File.WriteAllText("map.ppm", color.ToPpm());
color.SetEach(
(rgba, point) => _map.Seen[point] ? rgba : new Rgba(0, 0, 0).Average(rgba, 2)
);
File.WriteAllText("seen.ppm", color.ToPpm());
File.WriteAllText("noise.pgm", _map.Noise.ToPgm());
File.WriteAllText("reachable.pbm", _map.Reachable.ToPbm());
File.WriteAllText("blocks.pbm", _map.BlocksPlayer.ToPbm());
}
示例4: GenerateBlock
private void GenerateBlock()
{
_blocks = new Grid<bool>(_gridSize);
_blocks.SetEach(
( block, point ) =>
!_paths[ point ] &&
( _trees[ point ] != '.'
|| _walls[ point ]
|| _rivers[ point ] )
);
var blocks = new Grid<byte>(_gridSize);
blocks.SetEach(
(value, point) =>
(byte)(_blocks[point] ? 0 : 255)
);
File.WriteAllText( "blocks.pgm", blocks.ToPgm() );
}