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


C# Grid.SetEach方法代码示例

本文整理汇总了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() );
        }
开发者ID:nrkn,项目名称:LosvRL,代码行数:20,代码来源:Program.cs

示例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;
        }
开发者ID:nrkn,项目名称:NrknLib,代码行数:18,代码来源:GridExtensions.cs

示例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());
 }
开发者ID:nrkn,项目名称:LosvRL,代码行数:29,代码来源:Game.cs

示例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() );
 }
开发者ID:nrkn,项目名称:NrknLib,代码行数:17,代码来源:ConsoleViewDemo.cs


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