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);
        }
 /// <summary>
 /// Generates a cellular texture image
 /// </summary>
 /// <param name="Width">Width</param>
 /// <param name="Height">Height</param>
 /// <param name="NumberOfPoints">Number of points</param>
 /// <param name="Seed">Random seed</param>
 /// <returns>Returns an image of a cellular texture</returns>
 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 #3
0
 public OilPainting(Bitmap Image,int Seed,int NumberOfPoints)
 {
     _Image = new Bitmap(Image);
     _NumberOfPoints = NumberOfPoints;
     Map = new CellularMap(Seed, Image.Width, Image.Height, NumberOfPoints);
     SetupImage();
 }
 /// <summary>
 /// Constructor
 /// </summary>
 /// <param name="Image">Input image</param>
 /// <param name="Seed">Randomization seed</param>
 /// <param name="NumberOfPoints">Number of points for the painting</param>
 public OilPainting(Bitmap Image, int Seed, int NumberOfPoints)
 {
     if (Image == null)
         throw new ArgumentNullException("Image");
     _Image = new Bitmap(Image);
     _NumberOfPoints = NumberOfPoints;
     Map = new CellularMap(Seed, Image.Width, Image.Height, NumberOfPoints);
     SetupImage();
 }
 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;
 }