Exemplo n.º 1
0
        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() );
        }
Exemplo n.º 2
0
        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;
        }
Exemplo n.º 3
0
Arquivo: Game.cs Projeto: nrkn/LosvRL
 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());
 }
Exemplo n.º 4
0
 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() );
 }