Example #1
0
 public static Bitmap Generate(int Width, int Height, int NumberOfPoints, int Seed)
 {
     float[,] DistanceBuffer = new float[Width, Height];
     float MinimumDistance = float.MaxValue;
     float MaxDistance = float.MinValue;
     CellularMap Map = new CellularMap(Seed, Width, Height, NumberOfPoints);
     MaxDistance = Map.MaxDistance;
     MinimumDistance = Map.MinDistance;
     DistanceBuffer = Map.Distances;
     Bitmap ReturnValue = new Bitmap(Width, Height);
     BitmapData ImageData = ReturnValue.LockImage();
     int ImagePixelSize = ImageData.GetPixelSize();
     for (int x = 0; x < Width; ++x)
     {
         for (int y = 0; y < Height; ++y)
         {
             float Value = GetHeight(x, y, DistanceBuffer, MinimumDistance, MaxDistance);
             Value *= 255;
             int RGBValue = ((int)Value).Clamp(255, 0);
             ImageData.SetPixel(x, y, Color.FromArgb(RGBValue, RGBValue, RGBValue), ImagePixelSize);
         }
     }
     ReturnValue.UnlockImage(ImageData);
     return ReturnValue;
 }
Example #2
0
 public static Bitmap OilPainting(this Bitmap Image, int Seed, int NumberOfPoints=100)
 {
     Image.ThrowIfNull("Image");
     Bitmap _Image = new Bitmap(Image);
     CellularMap Map = new CellularMap(Seed, Image.Width, Image.Height, NumberOfPoints);
     BitmapData ImageData = _Image.LockImage();
     int ImagePixelSize = ImageData.GetPixelSize();
     int Width = _Image.Width;
     int Height = _Image.Height;
     Parallel.For(0, NumberOfPoints, i =>
     {
         int Red = 0;
         int Green = 0;
         int Blue = 0;
         int Counter = 0;
         for (int x = 0; x < Width; ++x)
         {
             for (int y = 0; y < Height; ++y)
             {
                 if (Map.ClosestPoint[x,y] == i)
                 {
                     Color Pixel = ImageData.GetPixel(x, y, ImagePixelSize);
                     Red += Pixel.R;
                     Green += Pixel.G;
                     Blue += Pixel.B;
                     ++Counter;
                 }
             }
         }
         int Counter2 = 0;
         for (int x = 0; x < Width; ++x)
         {
             for (int y = 0; y < Height; ++y)
             {
                 if (Map.ClosestPoint[x,y] == i)
                 {
                     ImageData.SetPixel(x, y, Color.FromArgb(Red / Counter, Green / Counter, Blue / Counter), ImagePixelSize);
                     ++Counter2;
                     if (Counter2 == Counter)
                         break;
                 }
             }
             if (Counter2 == Counter)
                 break;
         }
     });
     _Image.UnlockImage(ImageData);
     return _Image;
 }