generativepy tutorial

Martin McBride, 2021-04-18
Categories generativepy generativepy tutorial

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.

Popular tags

2d arrays abstract data type alignment and animation arc array arrays bezier curve built-in function callable object circle classes close closure cmyk colour comparison operator comprehension context context manager conversion creational pattern data types design pattern device space dictionary drawing duck typing efficiency else encryption enumerate fill filter font font style for loop function function composition function plot functools game development generativepy tutorial generator geometry gif gradient greyscale higher order function hsl html image image processing imagesurface immutable object index inner function input installing iter iterable iterator itertools l system lambda function len line linspace list list comprehension logical operator lru_cache magic method mandelbrot mandelbrot set map monad mutability named parameter numeric python numpy object open operator optional parameter or partial application path polygon positional parameter print pure function pycairo radial gradient range recipes rectangle recursion reduce rgb rotation scaling sector segment sequence singleton slice slicing sound spirograph sprite square str stream string stroke subpath symmetric encryption template text text metrics tinkerbell fractal transform translation transparency tuple turtle unpacking user space vectorisation webserver website while loop zip