I use this code to illustrate many of the tutorials on this site, and the articles I write for Dev.Mag. Ideally, I would like to package the code so that it is the minimal necessary for the particular tutorial; however, a lot of the code is reused, so that it becomes difficult to maintain. Instead, I distribute it all together. That way, new updates and extensions can be found in one place.
The current version includes classes and functions for:
- easy-syntax 2D and 3D arrays (for example, you can use grid[1:20:2, 2:3:20] to access the pixels in every second column (starting with column 1 and ending before column 20) and every third row (starting from row 2 and ending before row 20) (docs);
- general image utility function (docs);
- perlin noise (docs, tutorial);
- poisson-disk sampling (docs, tutorial);
- texture generation algorithms (docs, tutorial);
- quadtrees (docs, tutorial part1 and part 2);
- classes for generating random points (1D and 2D) from arbitrary distributions (docs, tutorial);
- functions for blending between images (for smooth transitions between regions in seamless tile sets) [see blend_demo.py, tutorial]; and
- functions for image quilting (under construction).
A few notes:
- The code is not optimised, and in general convenience and clarity takes precedence over speed. This code is not suitable for many applications where speed is important.
- The code will change often. At this stage I do not try to make it backwards compatible.
Download
Python Image Code v0.6
python_image_code_v0_6.zip (593 KB)
Requires PIL (Python Image Library).
This version includes some of the dependencies that accidentally got left behind in the previous version.
Cool ! I wonder if cython could help with speed here?
It would also be interesting to see how it runs in pypy.