## Cyclic Quine

A classic Quine is a program which outputs its own source code.
At first, such a program’s existence seems weird if not impossible, as it has to be so self-referential that it knows about itself everything, including how to know about itself. However, writing quines is possible, if not trivial.

A cyclic quine therefore is a program which outputs source code which differs from its own source code, yet outputs the original source code when run (the cycle length could be greater than one). So when running source codes $\Psi$ and $\Phi$, they output source codes $\Phi$ and $\Psi$.

Therefore, when one saves the first program as q0.py and the second as q1.py, one can create both source codes from one another (the following bash commands will not change the files’ contents).

\$ python q0.py > q1.py
\$ python q1.py > q0.py
\$ python q0.py | python > q0.py
\$ python q0.py | python | python | python | python > q1.py

j=0;Q,q="j=1;Q,q={}{}{}.replace(str(j),str(int(not(int(j)))),1),chr(34);print Q.format(q,Q,q)".replace(str(j),str(int(not(int(j)))),1),chr(34);print Q.format(q,Q,q)
j=1;Q,q="j=1;Q,q={}{}{}.replace(str(j),str(int(not(int(j)))),1),chr(34);print Q.format(q,Q,q)".replace(str(j),str(int(not(int(j)))),1),chr(34);print Q.format(q,Q,q)

## Asciify

Most images nowadays are represented using pixels. They are square, often relatively small and numerous, come in $(2^8)^3$ different colors and thereby do a good job being the fundamental building block of images. But one can imagine more coarse-grained and differently shaped pixels.
An interesting fact is, that in most monotype fonts two characters placed right next to each other (for example ‘\$\$’) occupy roughly a square area. So simple ASCII characters can indeed be used to approximately describe any ordinary image.
Asciify does exactly this; it takes in an image and some optional parameters and maps the pixels’ intensity onto a character set. Both the large and small default character sets are taken from a post by Paul Bourke.

In conjunction with asciify.py, I wrote index.py, which asciifies a bunch of images and results in their html form; it also creates an index. All images asciified for this post can be viewed through this index.

Converting an image to its asciified form works best when there is a lot of contrast in the image. Because of this, some pre-processing of the image may be required for best results (all images shown where only cropped or rotated). The built-in color functionality also only knows of $8$ colors, so bright and different colors look the best, as they interestingly differentiate from one another. The asciified image’s size also plays a role, the larger it is, the better the characters blend into one and appear to be one image.

Asciify is operated on a command prompt; python asciify.py img.png. To parse arguments, the built-in python module argparse is used. The images are opened and read using the Python Imaging Library module PIL, which needs to be installed for this program to work.
Optional arguments include --size N, where the maximum size can be specified, --invert and --smallcharset, which can sometimes increase the asciified image’s visual appeal and --html, which will output an html file to be viewed in a browser. To see the program’s full potential, simply run python asciify.py --help.
Source code for both asciify.py and index.py can be downloaded, the first is also listed below.

The two examples above use the color mode, though certain images also work in default black and white mode, such as this spider I photographed.

Then again, the colored text also has its charm, especially when the source image has bright colors and a lot of contrast.

# Python 2.7 Code
# Jonathan Frech 3rd, 4th of March 2017
#      rewritten 12th of April 2017
#         edited 13th of April, 13th, 14th, 15th of July 2017

## Mandelbrot Set ASCII Viewer

The Mandelbrot Set is the set of all complex points which, when one iteratively and infinitely applies the function $f_c(z)=z^2+c$, converge to a value. This simple rule results in stunning complexity and beauty.
Many Mandelbrot Set animations use regularly colored pixels to represent the number of iterations needed at the fractal’s edges to escape converging. Yet this mathematical object can also be represented as ASCII characters — similar to what I did in my Curses Cam post. The characters are chosen according to their opaqueness. A full stop (‘.’) looks lighter than a dollar sign (‘\$’), so they represent a smaller or larger number of iterations needed. The order of characters used is taken from this post by Paul Borke.
As there are only 70 characters used, each frame is being rendered twice to determine the minimum number of iterations needed by every point in that frame. Thereby the full visual character range is used.

The characters shown below represent a Mandelbrot Set still. To see the zoom in action, either run the program (listed below) or take a look at this Mandelbrot Set ASCII journey.

..................''''''''``"">>II``''''......
..................''''''''``^^,,ii::^^``''''......
..................''''''''``^^::ww\$\$++,,````''''......
................''''''''``^^^^""::\$\$\$\$\$\$::""^^``''''......
..............''''''````""{{;;XX\$\$\$\$\$\$\$\$uuUU,,,,""''......
............''''``````^^,,rr\$\$\$\$\$\$\$\$\$\$\$\$\$\$\$\$<<\$\$--``........
........''``````````^^""LL\$\$\$\$\$\$\$\$\$\$\$\$\$\$\$\$\$\$\$\$__""``''......
..''''''^^!!"""",,""""::__\$\$\$\$\$\$\$\$\$\$\$\$\$\$\$\$\$\$\$\$\$\$ll""''........
''''````^^::__IIYYii::ll\$\$\$\$\$\$\$\$\$\$\$\$\$\$\$\$\$\$\$\$\$\$\$\$pp^^''........
''``````"";;[[\$\$\$\$\$\$++__\$\$\$\$\$\$\$\$\$\$\$\$\$\$\$\$\$\$\$\$\$\$\$\$\$\$^^''''......
``^^^^,,;;>>\$\$\$\$\$\$\$\$\$\$\$\$\$\$\$\$\$\$\$\$\$\$\$\$\$\$\$\$\$\$\$\$\$\$\$\$ww``''''......
"",,,,II\$\$nn\$\$\$\$\$\$\$\$\$\$\$\$\$\$\$\$\$\$\$\$\$\$\$\$\$\$\$\$\$\$\$\$\$\$\$\$""``''''......
"",,,,II\$\$nn\$\$\$\$\$\$\$\$\$\$\$\$\$\$\$\$\$\$\$\$\$\$\$\$\$\$\$\$\$\$\$\$\$\$\$\$""``''''......
``^^^^,,;;>>\$\$\$\$\$\$\$\$\$\$\$\$\$\$\$\$\$\$\$\$\$\$\$\$\$\$\$\$\$\$\$\$\$\$\$\$ww``''''......
''``````"";;[[\$\$\$\$\$\$++__\$\$\$\$\$\$\$\$\$\$\$\$\$\$\$\$\$\$\$\$\$\$\$\$\$\$^^''''......
''''````^^::__IIYYii::ll\$\$\$\$\$\$\$\$\$\$\$\$\$\$\$\$\$\$\$\$\$\$\$\$pp^^''........
..''''''^^!!"""",,""""::__\$\$\$\$\$\$\$\$\$\$\$\$\$\$\$\$\$\$\$\$\$\$ll""''........
........''``````````^^""LL\$\$\$\$\$\$\$\$\$\$\$\$\$\$\$\$\$\$\$\$__""``''......
............''''``````^^,,rr\$\$\$\$\$\$\$\$\$\$\$\$\$\$\$\$<<\$\$--``........
..............''''''````""{{;;XX\$\$\$\$\$\$\$\$uuUU,,,,""''......
................''''''''``^^^^""::\$\$\$\$\$\$::""^^``''''......
..................''''''''``^^::ww\$\$++,,````''''......
..................''''''''``^^,,ii::^^``''''......

The fractal viewer is written in Python 2.7 and works by determining the terminal’s size and then printing a string of according size. This creates the illusion of a moving image, as the terminal will hopefully always perfectly scroll so that only one frame is visible at a time.
In the code’s first non-comment line one can change the complex point at the image’s center, (really, its conjugate, which is partially irrelevant as the set is symmetric along the real axis) the initial zoom value (complex distance above the image’s center), the zoom factor (the factor by which the zoom value gets multiplied after a frame), the total number of frames (-1 means there is no upper limit), the delay between frames (in seconds, can be floating-point) and the color characters used.

The program’s source code may not be particularly easy to read, yet it does its job and only requires seven non-comment lines! The code is shown below, though the .py file can also be downloaded.
To achieve the JavaScript animation linked to above, I wrote a simple Python converter which takes in the fractal renderer’s output and it spits out an HTML page. This converter’s code is not listed, though the .py file can be downloaded. Instructions on how to use the converter can be seen in its source code.

# Python 2.7 Code; Jonathan Frech, 15th and 16th of June 2017
P,Z,F,N,D,K=-.707+.353j,3,.9,-1,.1," .'`^\",:;Il!i><~+_-?][}{1)(|\\/tfjrxnuvczXYUJCLQ0OZmwqpdbkhao*#MW&8%B@\$"