Example #1
0
        /// <summary>
        /// Returns a raster scanline for a single row of 'pixels' in the output.
        /// This scanline should not contain the label, which is inserted by the calling process.
        /// </summary>
        /// <param name="line"></param>
        /// <returns>raster scanline for a single row of 'pixels' in the output</returns>
        protected virtual string GetScanLine(int line, ShapeParameters shapeParameters)
        {
            string scanLine = string.Empty;

            // collect pixels with boundaries of shape.
            if (line >= 0 && line < shapeParameters.Height) {
                scanLine = GetShapePixels(line, shapeParameters);
            }

            // Incorporate label into output.
            if (((shapeParameters.LabelRow - 1) == line) && !string.IsNullOrEmpty(shapeParameters.Label)) {
                scanLine = TextUtils.Overlay(scanLine, shapeParameters.Label);
            }

            return scanLine;
        }
Example #2
0
        /// <summary>
        /// Generates a shape, writing it to given <see cref="TextWriter"/> instance.
        /// </summary>
        /// <param name="textWriter"><see cref="TextWriter"/> to write shape to/param>
        /// <param name="shapeParameters">Shape parameters</param>
        /// <returns>argument <see cref="TextWriter"/></returns>
        public TextWriter WriteShape(TextWriter textWriter, ShapeParameters shapeParameters)
        {
            // Collect all unformatted scanlines.
            List<String> scanLines = new List<string>();
            int scanLineCount = GetScanLineCount(shapeParameters);
            for (int i = 0; i < scanLineCount; i++)
            {
                scanLines.Add(GetScanLine(i, shapeParameters));
            }

            // Output each line, centered with respect to the longest line.
            int maxLineLength =
                (scanLines.Count > 0) ? scanLines.Max(s => s.Length) : 0;
            foreach (string scanLine in scanLines)
            {
                textWriter.WriteLine(TextUtils.Center(scanLine, maxLineLength));
            }

            return textWriter;
        }
Example #3
0
 protected override string GetShapePixels(int line, ShapeParameters shapeParameters)
 {
     return PixelRun(line + 1);
 }
Example #4
0
 /// <summary>
 /// Computes the total number of scanlines in the ASCII-art output.
 /// </summary>
 /// <param name="shapeParameters">Shape parameters</param>
 /// <returns>total number of scanlines in ASCII-art output.</returns>
 private int GetScanLineCount(ShapeParameters shapeParameters)
 {
     // total height should respect the label position.
     int lineCount = Math.Max(shapeParameters.Height, shapeParameters.LabelRow);
     lineCount = Math.Max(0, lineCount);
     return lineCount;
 }
Example #5
0
 protected abstract string GetShapePixels(int line, ShapeParameters shapeParameters);
Example #6
0
 /// <summary>
 /// Generates a shape and returns it as a string.
 /// </summary>
 /// <param name="shapeParameters">Shape parameters</param>
 /// <returns>Generated shape as a string.</returns>
 public string GetShapeString(ShapeParameters shapeParameters)
 {
     return WriteShape(new StringWriter(), shapeParameters).ToString();
 }
Example #7
0
 protected override string GetShapePixels(int line, ShapeParameters shapeParameters)
 {
     int runLength = Math.Min(shapeParameters.Height - line, line + 1);
     return PixelRun(runLength);
 }
Example #8
0
 private string GetShapeScanLine(ShapeParameters shapeParameters)
 {
     int runLength = (int)Math.Round(shapeParameters.Height * _aspectRatio);
     return PixelRun(runLength);
 }
Example #9
0
 protected override string GetShapePixels(int line, ShapeParameters shapeParameters)
 {
     return GetShapeScanLine(shapeParameters);
 }