public Task<long[, ]> Excute(int iteration, double rangeX = 4.0, double rangeY = 4.0) { long[,] pixel = new long[PixelWidth, PixelHeight]; int width = PixelWidth; int height = PixelHeight; var reUnit = rangeX / width; var imUnit = rangeY / height; var startX = -(rangeX / 2); var startY = -(rangeY / 2); var endX = (rangeX / 2); var endY = (rangeY / 2); var task = Task.Run<long[,]>(() => { var calc = new BuddhabrotCalculator(iteration); var p = Parallel.For(0, width, x => { for (int y = 0; y < height; y++) { var re = startX + (reUnit * x); var im = startY + (imUnit * y); var c = calc.Calculate(re, im); if (c.Divergence == -1) continue; foreach (var item in c.Reasult) { var resultX = (int)Math.Round((item.Real + endX) / reUnit); var resultY = (int)Math.Round((item.Imag + endY) / imUnit); if (resultX < width && resultY < height) { pixel[resultX, resultY]++; } } } }); return pixel; }); return task; }
public Task<long[, ]> ExcuteRandom(int iteration, int count, double rangeX = 4.0, double rangeY = 4.0) { long[,] pixel = new long[PixelWidth, PixelHeight]; int width = PixelWidth; int height = PixelHeight; var startX = -(rangeX / 2); var startY = -(rangeY / 2); var endX = (rangeX / 2); var endY = (rangeY / 2); var pointX = width / rangeX; var pointY = height / rangeY; var task = Task.Run(() => { var calc = new BuddhabrotCalculator(iteration); // var rand = new Mt19937(); var rand = new Random(); var p = Parallel.For(0, count, i => { var re = (rand.NextDouble() * rangeX) - 2.0; var im = (rand.NextDouble() * rangeY) - 2.0; var c = calc.Calculate(re, im); if (c.Divergence != -1) { foreach (var item in c.Reasult) { var resultX = (int)Math.Round((item.Real + endX) * pointX); var resultY = (int)Math.Round((item.Imag + endY) * pointY); if (resultX < width && resultY < height) { pixel[resultX, resultY]++; } } } }); return pixel; }); return task; }