public void Render(string outputDirectory, string outputFilename, ColorRamp colorRamp) { _log.InfoFormat("Creating image ({0:N0}x{1:N0})", _resolution.Width, _resolution.Height); var viewPort = AreaFactory.RenderingArea; viewPort.LogViewport(); _log.Info("Loading points..."); var listReader = new ComplexNumberListReader(_inputInputDirectory, _inputFilename); var points = listReader .GetNumbers() .Select(n => viewPort.GetPointFromNumber(_resolution, n)) .Distinct() .ToArray(); _log.Info("Done loading"); _log.DebugFormat("{0:N0} distinct points found (for the specified resolution)", points.Length); var middlePoint = new Point(_resolution.Width / 2, _resolution.Height / 2); var maximumDistance = CalculateDistance(middlePoint, new Point(0, 0)); _log.Info("Starting to render"); var outputImg = new Bitmap(_resolution.Width, _resolution.Height); foreach (var point in _resolution.GetAllPoints()) { outputImg.SetPixel(point.X, point.Y, Color.Black); } foreach (var point in points) { if ((point.X < 0) || (point.Y < 0)) { continue; } outputImg.SetPixel(point.X, point.Y, ComputeColor(point, middlePoint, maximumDistance, colorRamp)); } _log.Info("Finished rendering"); _log.Debug("Saving image"); outputImg.Save(Path.Combine(outputDirectory, String.Format("{0}.png", outputFilename))); _log.Debug("Done saving image"); }
public void ShouldRoundTripNumbers() { var numbers = new[] { new Complex(), new Complex(1, 1), new Complex(0.25, 0.5) }; string path = Path.GetTempFileName(); var file = new FileInfo(path); try { var listWriter = new ComplexNumberListWriter(file.DirectoryName, file.Name); foreach (Complex n in numbers) { listWriter.SaveNumber(n); } var listReader = new ComplexNumberListReader(file.DirectoryName, String.Format("{0}*.point", file.Name)); Complex[] roundTripped = listReader.GetNumbers().ToArray(); Assert.That( roundTripped.Select(n => n.ToString()).ToArray(), Is.EquivalentTo(numbers.Select(n => n.ToString()).ToArray()), "Did not save and load numbers."); } finally { if (File.Exists(path)) { File.Delete(path); } } }
private IEnumerable<Complex> GetNumbers() { var list = new ComplexNumberListReader(_inputDirectory, _inputFilenamePattern); return list.GetNumbers(); }