Author: Mahesh Venkitachalam
Publisher: No Starch Press
Audience: Python Programmers
Reviewer: Alex Armstrong
If you don't already see Python as a potential playground you probably haven't used it. Can this book guide you through the fun?
The subtiltle of this book is:
Geeky Projects for the Curious Programmer
and this is about right as a one-line summary of the contents. This is not a book for the Python beginner. You need to be happy reading code, installing modules, particularly Numpy, and using them. Don't be too put off as you equally don't have to be a super expert. If you can write a Python program and use import then you are probably going to cope with the coding. Some of the projects are fairly advanced so there may be a second requirement to get the best from this book. It is important that you are actually interested in the subject matter of the projects.
The book is divided into five sections. The first, Warming Up and contains two fairly simple projects - parsing iTurnes Playlists and a Spirograph program which gives you some exposure to basic Python and graphics. It is the following sections that are going to determine if the book is of any interest to you. Part II is all about Conway's Game of Life and similar things, Part III is about idiosyncratic graphics methods, Part IV is an OpenGL tutorial and the final Part V is about hardware hacking using the Arduino and the Raspberry Pi. If none of these are your "thing" then the book's only hope is to get you interested and that might be a difficult task.
Part II: Simulating Life isn't restricted to Conway's Life but the first project is an implementation that might just get you interested. The next project is more about physics. The Karplus-Strong algorithm is a really novel approach to generating simulated musical notes. The chapter introduces the idea but doesn't really succeed in getting you to understand what the motivation is or why it works. This is the first time in the book that the program is presented without you necessarily understanding the theory behind it in enough detail. You do discover how to write wav files as a byproduct. The final project is Boids - a classic simulation of flocking behavior. Even if you have seen Boids before ??you will have a lot of fun discovering the rules that generate flocking and you can always tinker and try out your own.
Part III is titled Fun With Images but it isn't about traditional 2D graphics. It is about what you might call idiosyncratic graphic realizations. The first is auto-generated ASCII art. ASCII art is created by printing characters to produce variable densities. The program takes an image converts it to greyscale, maps each tile to an ASCII character. The second project is doing the same sort of thing but to create a photomosaic. In this case the picture is divided into large tiles, each one set to the average of the pixels it contains - it is a basic blurring operation. As a spin-off you get to learn to use the Python Imaging Library. The final project in the section is autostereograms. These were popular a while back and they tend to resurface every now and again as another group of people encounter them for the first time. An autostereogram looks like noise, but if you can master the trick of looking at it in the right way an image jumps out at you because of depth perception.
Part IV: Enter 3D is about 3D graphics with OpenGL and this is a notoriously difficult topic involving the graphics pipeline and shaders - programs writing in a shader language. The first project is just a basic getting started with OpenGL. Does it succeed in getting you to understand what is going on? Not really. At best it provides you with a "Hello World" for OpenGL that might stimulate you to find out more but as to understanding the role of the shader and how to write one it really doesn't give you more than a high level view. The second project implements a particle system which is a task that is easier to understand using shaders than a more general 3D scene. This is however advanced but exciting. It might just give you enough enthusiasm to find out more. The final project is volume rendering which is the sort of thing that an X-ray scanner uses to put together 2D scans into a 3D representation. The project doesn't tackle the problem on converting the scans into 2D slices, deconvolution, it starts off from processed data and constructs a 3D model. This is an easier task and really the only difficulty is in understanding OpenGL. This is not a good introduction to OpenGL if you are interested in how it works and doing general 3D graphics.
The final section, Hardware Hacking, is the most difficult to evaluate. Its first project is an introduction to the Arduino, which is fine but the standard language to use to program it is Processing and not Python. You build a light sensor and write a Processing program to read it. Then you write a Python program to present the data as a graph. Most of the code is about reading the serial interface for the data and drawing a graph.
The second project builds a laser projector that produces patterns in response to audio input. It uses an Arduino and an add on board to control to mirrors mounted on motors. The laser is reflected off the mirrors which can then scan it around the room and make patterns. The patterns are derived from a Fourier transform of the audio data. Along the way you find out about using audio and Numpy Fourier transforms.
The final project switches to use a Raspberry Pi to create a weather monitor. For a book on Python the Pi is a much better choice because you can program it directly in Python. The project takes a DHT11 temperature and humidity sensor and builds it into a finished system that serves a web page showing a chart.
This is a book that is packed with interesting projects and, as long as you are interested in one or more, it is a good read. However, the subject matter encountered in each project is huge and you can't expect full explanations. There also isn't much explanation of Python - you are just expected to be able to read the code. The later projects are longer and the ratio of explanation to code goes down with multipage listings presenting the final programs. For me, the part that was least useful was the one on OpenGL but it might serve to get someone interested.
Overall this is a reasonably good book as long as you are up to the projects and find them interesting.