Exemplo n.º 1
0
 public static void FloodFill( this IGrid<Rgba> grid, Point pt, Rgba targetColor, Rgba replacementColor )
 {
     var q = new Queue<Point>();
       q.Enqueue( pt );
       while( q.Count > 0 ) {
     var n = q.Dequeue();
     if( !ColorMatch( grid[ n.X, n.Y ], targetColor ) )
       continue;
     Point w = n, e = new Point( n.X + 1, n.Y );
     while( ( w.X > 0 ) && ColorMatch( grid[ w.X, w.Y ], targetColor ) ) {
       grid[ w.X, w.Y ] = replacementColor;
       if( ( w.Y > 0 ) && ColorMatch( grid[ w.X, w.Y - 1 ], targetColor ) )
     q.Enqueue( new Point( w.X, w.Y - 1 ) );
       if( ( w.Y < grid.Height - 1 ) && ColorMatch( grid[ w.X, w.Y + 1 ], targetColor ) )
     q.Enqueue( new Point( w.X, w.Y + 1 ) );
       w.X--;
     }
     while( ( e.X < grid.Width - 1 ) && ColorMatch( grid[ e.X, e.Y ], targetColor ) ) {
       grid[ e.X, e.Y ] = replacementColor;
       if( ( e.Y > 0 ) && ColorMatch( grid[ e.X, e.Y - 1 ], targetColor ) )
     q.Enqueue( new Point( e.X, e.Y - 1 ) );
       if( ( e.Y < grid.Height - 1 ) && ColorMatch( grid[ e.X, e.Y + 1 ], targetColor ) )
     q.Enqueue( new Point( e.X, e.Y + 1 ) );
       e.X++;
     }
       }
 }
Exemplo n.º 2
0
 public static void SetRgba( this BitmapData bitmapData, Rgba rgba, int x, int y )
 {
     //32bpp
       var offset = y * bitmapData.Stride + ( 4 * x );
       Marshal.WriteByte( bitmapData.Scan0, offset + 2, rgba.Red );
       Marshal.WriteByte( bitmapData.Scan0, offset + 1, rgba.Green );
       Marshal.WriteByte( bitmapData.Scan0, offset, rgba.Blue );
       Marshal.WriteByte( bitmapData.Scan0, offset + 3, rgba.Alpha );
 }
Exemplo n.º 3
0
 private static bool ColorMatch( Rgba a, Rgba b )
 {
     return a.Equals( b );
 }
Exemplo n.º 4
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());
 }