Forays into Anti-Aliased ASCII Art

Time limit1sMemory limit128 MB

Problem

Aliasing is the name for the artifacts that appear when a digital device samples an analog source at a finite resolution. It is a common problem in computer graphics, where straight lines and smooth curves look jagged once they are drawn as discrete pixels. For instance, a naive attempt to plot the line

$$y = mx + b$$

might produce something like this:

        *** 
      **
   ***
***

which looks more like a staircase than a smooth line.

Aliasing (also called jaggies) can be reduced by anti-aliasing, where pixels are drawn in different shades of gray so that, seen from a distance, the image looks smoother.

The scheme used here shades two pixels in each column. For every integer $x$, take $y = mx + b$ and split it into a whole part $y_w$ (the largest integer that is at most $y$) and a fractional part $y_f$, so that

$$y_w + y_f = y, \qquad 0 \le y_f < 1.$$

For example, if $y = 23.56$ then $y_w = 23$ and $y_f = 0.56$; if $y = -1.3$ then $y_w = -2$ and $y_f = 0.7$.

Let the gray level of a pixel be a value from $0.0$ to $1.0$, where $0.0$ is pure white and $1.0$ is pure black. In column $x$:

  • If $y_f = 0$, shade pixel $(x, y_w)$ at gray level $1.0$.
  • If $y_f \ne 0$, shade pixel $(x, y_w)$ at gray level $1 - y_f$ and pixel $(x, y_w + 1)$ at gray level $y_f$.

Write a program that draws anti-aliased lines with this scheme.

Input

The input contains several test cases. Each case is a single line with two numbers, $m$ and $b$, the slope and the intercept of the line $y = mx + b$. Both are given as floating-point numbers with at most two digits after the decimal point. $m$ lies between $0.00$ and $0.50$ inclusive, and $b$ lies between $-20.00$ and $20.00$ inclusive.

A line whose $m$ and $b$ are both zero marks the end of the input and is not plotted.

Output

For each input line, draw a separate plot: a $20 \times 20$ block of characters covering the region $0 \le x < 20$, $0 \le y < 20$ of the Cartesian plane. Any position the line does not touch is left blank (a space).

For each shaded pixel, take its gray level, round it to the nearest tenth (breaking ties by rounding up), and choose the matching character from this table:

Rounded gray level0.00.10.20.30.40.50.60.70.80.91.0
Character.:-=+tw*#%@

The characters are period, colon, hyphen, equals, plus, lowercase t, lowercase w, asterisk, hash, percent, and at. Both $y_f$ and the gray level must be computed exactly.

Print the plot from the top of the region downward: the first row is $y = 19$ and the last row is $y = 0$. Print each of the 20 rows as its 20 characters, immediately preceded and followed by a vertical bar (|). After each plot, print one line of 22 underscores (_).