Project Ideas: Genetic Art
One of the more interesting applications of algorithms to images is
so-called genetic art. In this technique, we build
some form of image DNA
, generate images from that DNA,
rank the fitness
of the images, and recombine the DNA,
of images the DNA of more fit images more frequently in building the
next generation. Electric
Sheep are one of the more famous examples of genetic art.
Of course, the first part of genetic art is figuring out how to
turn the DNA
into an image. A spectacular variety
of techniques exist for such transformations. Dr. Davis has one
famous early example (done by hand, rather than by computer), in which
Francois Morellet used a phonebook as the DNA,
and rendered it in a large grid
using red for odd digits and blue for even digits.
We'll consider two versions of this repurposing of data: One in which
we use this same grid technique to turn a file into a series of pixels
(or blocks of colors or ...) and another one in which we turn a file
into a series of instructions to a turtle.
We've already seen a bit of how we can interpret any file as a
series of colors: We could read triplets of characters and treat
each triplet as a new color. Here's one implementation of that technique,
using image-calculate-pixels!, a slower variant of
image-compute-pixels! that traverses the image
systematically, row by row, from top-left to bottom right.
One problem with that technique is that it provides a fairly wide
variety of colors, giving no form at all to the image. It also doesn't
scale appropriately.
A simpler technique is to choose a smaller palette of related
colors and use the characters as indices into that palette. That is,
we pick sections of the image to draw (most simply, a grid of rectangles
or ovals), and, for each section, read a character, convert the character
to an integer, reduce that integer to the range of valid indices, and
then get it from the palette.
We might use such a procedure to make a wide variety of images by
selecting palettes, files, horizontal boxes, and vertical boxes from
n.
While these grid-like visualizations of files are fun, they are
certainly not the only thing we can do to interpret a file as the
DNA of a drawing. As mentioned above, we can treat a file as a
series of commands to a turtle.
Unfortunately, this procedure is a bit less refined than most. Still,
it may be worth exploring.