Skip to content

Instantly share code, notes, and snippets.

@nst
Last active November 5, 2023 12:02
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save nst/0dc0afa913a2cab218222b0576d0fd2e to your computer and use it in GitHub Desktop.
Save nst/0dc0afa913a2cab218222b0576d0fd2e to your computer and use it in GitHub Desktop.
Reproducing "Schotter" by Georg Nees with pycairo
#!/usr/bin/env python
# Nicolas Seriot, 2018-11-04
# According to "Schotter" by Georg Nees
# https://collections.vam.ac.uk/item/O221321/schotter-print-nees-georg/
# Idea: randomness for x, y and rotation does increase at each row
# Sample output: http://seriot.ch/visualization/schotter_pycairo.png
import cairo
import random
COLS = 12
ROWS = 24
MARGIN = 80
WIDTH = 60
CANVAS_WIDTH = COLS * WIDTH + MARGIN * 2
CANVAS_HEIGHT = ROWS * WIDTH + MARGIN * 2 + 20
surface = cairo.ImageSurface(cairo.FORMAT_ARGB32, CANVAS_WIDTH, CANVAS_HEIGHT)
c = cairo.Context(surface)
c.save()
c.set_source_rgb(1,1,1)
c.paint()
c.restore()
c.set_line_width(1)
for col in xrange(COLS):
for row in xrange(ROWS):
origin_x = MARGIN + col * WIDTH
origin_y = MARGIN + row * WIDTH
translate_x = origin_x + random.uniform(-0.5, 0.5) * row * 5
translate_y = origin_y + random.uniform(-0.5, 0.5) * row * 5
radians = random.uniform(-0.5, 0.5) * row / 10.0
c.save()
c.translate(translate_x, translate_y)
c.rotate(radians)
c.rectangle(0, 0, WIDTH, WIDTH)
c.stroke()
c.restore()
surface.write_to_png("schotter.png")
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment