/// <inheritdoc/> protected override IEnumerable <Segment> Render(RenderContext context, int maxWidth) { var image = Image; var width = Width; var height = Height; // Got a max width? if (MaxWidth != null) { height = (int)(height * ((float)MaxWidth.Value) / Width); width = MaxWidth.Value; } // Exceed the max width when we take pixel width into account? if (width * PixelWidth > maxWidth) { height = (int)(height * (maxWidth / (float)(width * PixelWidth))); width = maxWidth / PixelWidth; } // Need to rescale the pixel buffer? if (width != Width || height != Height) { var resampler = Resampler ?? _defaultResampler; image = image.Clone(); // Clone the original image image.Mutate(i => i.Resize(width, height, resampler)); } var canvas = new Canvas(width, height) { MaxWidth = MaxWidth, PixelWidth = PixelWidth, Scale = false, }; for (var y = 0; y < image.Height; y++) { for (var x = 0; x < image.Width; x++) { if (image[x, y].A == 0) { continue; } canvas.SetPixel(x, y, new Color( image[x, y].R, image[x, y].G, image[x, y].B)); } } return(((IRenderable)canvas).Render(context, maxWidth)); }
public static Spectre.Console.Canvas Generate(int width, int height) { var canvas = new Spectre.Console.Canvas(width, height); var scale = 2 * MaxValueExtent / Math.Min(canvas.Width, canvas.Height); for (var i = 0; i < canvas.Height; i++) { var y = (canvas.Height / 2 - i) * scale; for (var j = 0; j < canvas.Width; j++) { var x = (j - canvas.Width / 2) * scale; var value = Calculate(new ComplexNumber(x, y)); canvas.SetPixel(j, i, GetColor(value)); } } return(canvas); }