Created
January 7, 2019 16:03
-
-
Save nst/cc3b0bfc6645157ffdfef4840eb99214 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/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, rotation and alpta does increase at each row | |
# Sample output: ... | |
import cairo | |
import random | |
import math | |
def rainbow_color(pct = 0.0, offset = 0.0): | |
p = 2 * math.pi * (offset + pct) | |
r = math.sin(p + 0) * 0.5 + 0.5 | |
g = math.sin(p + 2) * 0.5 + 0.5 | |
b = math.sin(p + 4) * 0.5 + 0.5 | |
return (r,g,b) | |
if __name__ == "__main__": | |
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.set_line_width(2) | |
c.save() | |
c.set_source_rgb(1,1,1) | |
c.paint() | |
c.restore() | |
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 | |
r,g,b = rainbow_color(pct = 1.0 * row / ROWS) | |
alpha = 1.0 - (1.0 * row / ROWS) | |
c.set_source_rgba(r,g,b,alpha) | |
c.save() | |
c.translate(translate_x, translate_y) | |
c.rotate(radians) | |
c.rectangle(0, 0, WIDTH, WIDTH) | |
c.fill_preserve() | |
c.set_source_rgb(0,0,0) | |
c.stroke() | |
c.restore() | |
surface.write_to_png("schotter_color.png") |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment