private PixelColor[,] DrawNoiseMap(IAlgorithmTarget target, PixelColor[,] source, NoiseMap noiseMap, PixelColor baseColor, PixelColor shapeColor, double cutoffValue) { var random = new Random(); float random1 = (float)random.NextDouble() * random.Next(-1, 1); float random2 = (float)random.NextDouble() * random.Next(-1, 1); float upperBounds = Math.Max(random1, random2); float lowerBounds = Math.Min(random1, random2); float boundsDistance = upperBounds - lowerBounds; target.AlgorithmPixels.ForEach ( pixel => { var position = pixel.Position; int x = (int)position.X, y = (int)position.Y; var value = noiseMap.GetValue(x, y); value = value.Clamp(lowerBounds, upperBounds); var distanceFromLowerBounds = value - lowerBounds; var offsetValue = (boundsDistance == 0.0f) ? 0.0f : distanceFromLowerBounds / boundsDistance; //source[y, x] = ((value * 100) >= cutoffValue) ? shapeColor.Blend(baseColor, value) : baseColor; source[y, x] = shapeColor.Blend(baseColor, offsetValue); } ); return(source); }
private PixelColor[,] DrawRandomLine(IAlgorithmTarget target, PixelColor[,] source, IPixelsSource pixelsSource) { var random = new Random(); var direction = (SiblingDirection)random.Next(0, 7); var length = random.Next(20, 100); var currentCount = 0; var randomColor = System.Windows.Media.Color.FromArgb(255, (byte)random.Next(0, 255), (byte)random.Next(0, 255), (byte)random.Next(0, 255)).ToPixelColor(); var currentPixel = target.AlgorithmPixels[random.Next(0, target.AlgorithmPixels.Count - 1)]; do { source[(int)currentPixel.Position.Y, (int)currentPixel.Position.X] = randomColor; currentPixel = pixelsSource.GetSibling(currentPixel, direction, true); ++currentCount; }while (currentPixel != null && currentCount < length); return(source); }
public PixelColor[,] DrawAlgorithm(IAlgorithmTarget target) { var pixelsSource = target.GetPixelsSource(); var copy = pixelsSource.ToPixelColorArray(); if (!target.AlgorithmPixels.Any()) { return(copy); } var noiseMap = this.GenerateNoiseMap(copy.GetLength(0), copy.GetLength(1)); var baseColor = System.Windows.Media.Colors.SaddleBrown.ToPixelColor(); var shapeColor = System.Windows.Media.Colors.White.ToPixelColor(); var cutoffValue = new Random().Next(0, 100); copy = this.DrawNoiseMap(target, copy, noiseMap, baseColor, shapeColor, cutoffValue); return(copy); }