42 Astoundingly Useful Scripts and Automations for the Macintosh

Astounding ASCII Art

ASCII art images created using the asciiArt script of 42 Astounding Scripts and Automations for the Macintosh.

Jerry Stratton

Create your own ASCII art palettes with densitySort—Wednesday, January 27th, 2021
ASCII viola: A viola created from the letters of the musical scale.; ascii art; violas

asciiArt Viola.jpg --palette "BDAGECF " --save viola.png --bgcolor 1,1,1,0

A lot of choosing your palette for ASCII art is an art, because the distribution of pixels in each character matters as much as the number of them. Even resolution can matter: a densely packed character such as an asterisk might look darker than a sparsely packed character such as a thick letter O if there are only a few characters per row, but instead have the same effect if there are thousands of characters per row.

But a script can get you started. I wrote densitySort to help me put together the palettes I used in 42 Astounding Scripts.

The script is fairly simple. It creates an image of each character, calculates the darkness of the image, and then saves that darkness in an array.

Then, it sorts the array by darkness descending and prints out the sorted palette.

At its most basic, you can give it a palette and it will sort the palette using the Monaco font, because that’s the font I use in Terminal.

Say you want to use all of the letters that make up a musical scale in an ASCII image:

  • $ ~/bin/densitySort ABCDEFG
  • BDAGECF

You can now use that palette to create, say, an ASCII art image of a guitar (or of a viola, as in the top image on this post):

  • asciiArt Guitar.jpg --palette "BDAGECF "

Because some characters have special meanings on the command line, you’ll often need to surround the palette with apostrophes:

  • $ ~/bin/densitySort '$&%@!'
  • @&%$!

You can change the font using the --font option.

  • $ ~/bin/densitySort '$&%@!' --font Courier
  • @$&%!

If you leave off the palette, it will provide the entire normal ASCII art character set for the font:

Random colors in your ASCII art—Wednesday, April 29th, 2020

I recently wanted to put dollar signs inside a Texas shape for a blog post about local sales taxes. That, of course, is easy with the asciiArt script: just set up a single-character palette and use a solid two-color image of Texas. But I also wanted to highlight the potential patchwork of sales taxes that people will have to know just to sell things online or even to send things sold in-person to the customer’s home.

The obvious solution was to randomly color each character in the image. The asciiArt script in the book can handle colors, but not random colors. It can use the color of the main image or overlay the color of a different image. Adding a random color option wasn’t difficult, however, because the script already grabs the red, green, and blue components of the image in a central place.

Here’s how I added a random color option to the script. The first question is, how to request random colors? There’s already a request for an overlay image file. What I want now is to, instead, overlay random colors. So I’m going to use --overlay random. It will make no sense to use an overlay file and random colors at the same time. The colors have to come from somewhere, and if they come randomly the file won’t be seen, and if they come from a file the random colors won’t be seen. So combining those options into a single place makes sense.

That means changing the case for --overlay:

[toggle code]

  • case "--overlay", "-o":
    • overlayFile = popString(warning:"Overlaying requires an image to overlay.")
    • if overlayFile == "random" || files.fileExists(atPath: overlayFile) {
      • useColors = true
    • } else {
      • help(message:"File " + overlayFile + " does not exist.")
    • }
  • case "--palette", "-p":

The bold lines, lines three through seven, are the new lines. All it really changes is to add “random” as a valid value for --overlay. If the overlay string exists as a file or, if the string is the word “random”, that section of code does what it did before. Otherwise, it displays the script’s help text and quits the script.

Because overlayFile can now contain text that is not a file, the check for reading the overlay file has to be changed, too:

Hello World in Amber—Wednesday, January 22nd, 2020
Hello World: ASCII art of a head and “hello world”.; Jerry Stratton; ascii art

I considered this for the cover, but the seventies amber was too over the top even for me.

  • ~/bin/asciiArt face.png --width 120 --palette "hello world" --sequence 0.8 --lighten 3.9 --save hello --bgcolor .995,.621,.037 --fgcolor 1,1,1

The amber I used is the color of many of the screens from the era. And many of those that were just white on black, you could buy screen overlays to make them be amber (or green). The excuse was that it was easier on the eyes, but I think the real reason is that amber and green made their screens look more like people thought a computer ought to look.

We still have that today: one of the most popular Terminal color schemes is green on black. It’s what I eventually went with for the Astounding Scripts cover.

But this amber ASCII art does highlight another feature of the ASCII art script in 42 Astoundingly Useful Scripts and Automations for the Macintosh: the ability to wash out an image, to brighten it, so as to highlight the areas with the most contrast. The original image had an off white fireplace and a window in the background. Lightening helped remove that, but it also helps when making an image like this to use a photo editor, such as GIMP or GraphicCoverter, to remove everything around the focus of the image. In the end I used the magic wand in GraphicConverter to get rid of the background. The lightening got rid of the lines on my face, highlighting the silly Incredibles Kleenex mask, hair, and shirt.

The argument --lighten 3.9 multiplies every color in the image by 3.9; the argument --sequence 0.8 tells the script to not only use the palette in order (so that it spells “hello world” instead of assumes that those letters are in order by density) but to cut off the sequence when the combined grayscale exceeds 0.8. If you look at the script itself, you’ll see that the default cutoff is 1.0; since there is no way for a greyscale to exceed 1.0 (colors range from 0.0 through 1.0), normally there is no cutoff at all.

Computers and Serial Imagery—Saturday, November 16th, 2019

“The tradition of serial imagery in painting began with Monet who, being vitally concerned with light, often painted the same object or scene repeatedly under varying light conditions… Since Monet, many painters (mostly abstract) have worked serially. Andy Warhol, with his painted (and printed) series of movie stars, Mona Lisas, soup cans, coke bottles, etc. is the foremost serial artist today.”

ASCII art has always fascinated me. So when I ran across Laurence Press’s article in the old Artist and Computer collection, it inspired me to write the asciiArt script for 42 Astounding Scripts.

I ended up not using his greyscale palette, however, mainly because it required too much choice for a script. Most of the letters appear multiple times in his palette. That said, it’s not a bad palette. Choosing somewhat randomly from his 8-level list, the palette --palette "#OX*+=- " produces recognizable ASCII art for complex images.

He also suggests inserting “arbitrary material”, which is what I called “sequential” in the book: using a word or phrase for all non-white sections of the image.

He has some very interesting ideas that I did not use for the script, but which you could program in if you wanted, such as randomly adding noise to the non-white or the white sections.

But also interesting is how unsure he is that using computers for art is a worthwhile use of computer time.

It is uncomfortable to be begging for ‘bootleg’ time. The problem is that computer art doesn’t really fit anywhere. Neither computer scientists and computer science departments, nor artists and art departments generally take it seriously enough to underwrite experimentation. Perhaps this is as it should be, or perhaps the quality of our work will win a place for computer generated art, I think that the jury is (justifiably) still out.

I think the jury is in today about whether using computers for artwork is a worthwhile use of computer time. And that’s partly because a few years after he wrote that, he’d have been able to go out to the local Radio Shack and buy a complete computer that could do what he had to use “bootleg time” for in 1975.

Older posts