generativepy tutorial


Martin McBride, 2021-04-18
Categories generativepy generativepy tutorial
In Generative art

This section is a basic tutorial for generativepy.

If you are new to generativepy, it is worth reading through the tutorials in order, to gain an understanding of how to use the library.

generativepy supports several different types of image creation:

  • Vector images, which can be used to create all types of geometric art. It uses the Pycairo library, which provides a comprehensive set of vector drawing tools to produce very high-quality graphics.
  • Bitmap images, which can be used to create various types of pixel art. This uses two libraries:
    • Pillow, an image processing library that provides a wide range of functions for manipulating images, similar to the sort of functions you might use in programs like GIMP or Photoshop.
    • NumPy, which stores images as a data array. It is more suited to performing heavy-duty maths on image pixels, for example creating certain types of fractals.
  • 3D images, using the ModernGL library, which supports modern OpenGL. This is still at quite an experimental stage.

Each of these modes supports a common interchange format, the frame, which is actually a NumPy array. This allows for the exchange of data between the different modes.

In addition, generativepy supports:

  • Image sequences, which work by calling one of the above modes repeatedly to create a sequence of images. This can be stored as a set of PNG files (that can be converted to a movie using ffmpeg or similar), or an animated GIF file.
  • Mathematical extensions for vector imaging, which can be used to create various graphs and geometric diagrams, that can also be stored as images or movies.

There are also some support modules:

  • color, a module that provides common colour handling across the different modes, including support for named colours, HSL, and alpha. It also supports colour maps that can be used, for example, to colourise fractals.
  • tween, a module that supports basic tweening of numerical values and vector quantities (such as positions and colours).
If you found this article useful, you might be interested in the book Computer Graphics in Python or other books by the same author.