.. _computer-art: ============== Computer art ============== [status: content-partly-written] Sadly the fractal flame screensaver ElectricSheep was made proprietary several years ago, so it cannot grace our computer monitors anymore. But there is much good computer art that can be generated using free software tools. Here are some references to explore to see if it is possible to develop a chapter for this book on computer art. At this time these references are focused on evolutionary art, but other possibilities should be examined. Connections to 1d and 2d (like Conway's life) cellular automata should be explored. Understanding photos and images =============================== Discussion of graphics formats ------------------------------ Show a PDF and a .png or .jpg and try to zoom in on them. Talk about vector formats vs. raster formats. Photo collection management --------------------------- Introduce shotwell and digikam. Urge students to take pictures with a camera or phone, but bring a cheap camera to have students take some 80 photos at the start of class, then download them to the computer with a USB cable. Or alternatively grab a collection of free stock photos off the web: ``cd ~/Pictures`` ``mkdir stock`` ``cd stock`` ``wget -r -np -nc http://creativity103.com/collections/AbstractLight/index.html`` ``wget -r -np -nc http://creativity103.com/collections/Aviation/index.html`` or to get the full package ``wget -r -np -nc http://creativity103.com/`` Emphasize the importance of tagging and rating photos immediately. Image manipulation: GUI and command line ---------------------------------------- * Introduce the Gimp. https://www.noupe.com/inspiration/tutorials-inspiration/best-of-gimp-40-professional-tutorials-to-level-up-your-skills-79428.html * Introduce ImageMagick. metapixel and photomosaics ========================== * Collect a bunch of photos in a hurry, possibly with some cool use of wget and an image search. For example, creativity103.com has archives of images licensed under the "creative commons "attribution" license: https://creativecommons.org/licenses/by/3.0/ * I already showed how to beef up your Pictures folder with commands like ``wget -r -np -nc http://creativity103.com/`` * Install metapixel on Linux * the metapixel tutorial I have found has pointless racy images, so I need to find another one. * install the webcollage screensaver: ``sudo apt install xscreensaver-screensaver-webcollage`` * we have beefed up our personal ~/Pictures directory so we can use that to make the photomosaic database .. code:: bash mkdir ~/mp metapixel-prepare -r ~/Pictures ~/mp --width 32 --height 32 once the database is ready we can prepare .. code:: bash metapixel --metapixel work_photo.jpg photomosaic.png --library ~/mp --scale=10 ASCII art ========= What is ASCII? What is ASCII art? Tools for drawing ASCII art. Converting raster images to ASCII art. ``jp2a`` on GNU/Linux systems. Evolutionary art ================ * https://en.wikipedia.org/wiki/Electric_Sheep * https://en.wikipedia.org/wiki/Software_art * https://en.wikipedia.org/wiki/Evolutionary_art * http://iasl.uni-muenchen.de/links/GCA-IV.3e.html * transcend http://transcend.sourceforge.net/ Image manipulation from your own Python program =============================================== We will learn to use the python imaging library (PIL). At the shell: .. code:: bash sudo apt install python3-pil Also give yourself a photo to work with. For this tutorial let's keep it small so it's faster and views better. You can use a command like: .. code:: bash convert -resize 800 my_big_picture.jpg work_photo.jpg In the python interpreter, following the tutorial at http://effbot.org/imagingbook/introduction.htm .. code:: python ## import the Image portion of the PIL library from PIL import Image ## load an image im = Image.open('work_photo.jpg') ## show its information print(im.format, im.size, im.mode) ## show the picture itself im.show() ## then close that window We now have an image stored in the object ``im`` and we can work on manipulating it. Geometric transformations ------------------------- .. code:: python import os, sys from PIL import Image size = 128, 128 infile = 'work_photo.jpg' outfile = os.path.splitext(infile)[0] + '.thumbnail' + '.jpg' thumb = Image.open(infile) thumb.thumbnail(size) thumb.save(outfile, 'JPEG') .. code:: python ## copy a rectangle from the image box = (100, 100, 400, 400) region = im.crop(box) ## now play with that rectangle, then paste it back in region = region.transpose(Image.ROTATE_180) ## now paste it back in im.paste(region, box) ## now box is the image with the small region we chose im.show() im.save('work_photo_pasted.jpg', 'JPEG') You will now see that the region we cut out of the photo has been rotated 180 degrees. .. code:: python ## reload the image from scratch im = Image.open('work_photo.jpg') ## rotate 45 degrees counterclockwise rotated = im.rotate(45) rotated.save('work_photo_rotated_45.jpg', 'JPEG') ## now make an animation various_rotations = [] for i in range(360): rotated = im.rotate(i) fname = 'work_photo_rotated_%03d.jpg' % i print('writing out %s' % fname) rotated.save(fname, 'JPEG') If you type ``ls`` you will see that you now have many files with names like ``work_photo_rotated_17.jpg``. You can use ``geeqie`` to view them and even get a crude animation by holding the space bar down. You can also use what we learned in :numref:`sec-making-a-movie-animation-of-the-walk` and try this: .. code:: bash ## make a movie with: ffmpeg -framerate 24 -i work_photo_rotated_%03d.jpg work_photo_animated.mpg ## view it with: vlc work_photo_animated.mpg Filters and enhancement ----------------------- .. code:: from PIL import Image from PIL import ImageFilter ## load an image im = Image.open('work_photo.jpg') ## out = im.filter(ImageFilter.DETAIL) ## out.save('work_photo_detail.jpg', 'JPEG') out = im.filter(ImageFilter.CONTOUR) out.save('work_photo_contour.jpg', 'JPEG') out = im.filter(ImageFilter.EMBOSS) out.save('work_photo_emboss.jpg', 'JPEG') out = im.filter(ImageFilter.FIND_EDGES) out.save('work_photo_edges.jpg', 'JPEG') out = im.filter(ImageFilter.SMOOTH) out.save('work_photo_smooth.jpg', 'JPEG') ## NOTE: in the next one we start from "out", the smoothed photo restored = out.filter(ImageFilter.EDGE_ENHANCE) restored.save('work_photo_restored.jpg', 'JPEG') out = im.filter(ImageFilter.SMOOTH_MORE) out.save('work_photo_smooth_more.jpg', 'JPEG') Now compare all the images we produced. In particular, look carefully at ``work_photo_smooth.jpg`` and ``work_photo_restored.jp`` to see how the EDGE_ENHANCE transformation takes away the fuzziness that had been introduced by SMOOTH.