Created
October 9, 2021 16:31
-
-
Save nst/bebbeb5b2cf7a4a1f305a2b93eb670d4 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 python3 | |
# 2021-10-09 | |
# Emilien & Nicolas Seriot | |
# https://seriot.ch/visualization/lines_2.png | |
import cairo | |
import random | |
WIDTH = 800 | |
HEIGHT = 600 | |
MARGIN = 20 | |
surface = cairo.ImageSurface(cairo.FORMAT_ARGB32, WIDTH, HEIGHT) | |
c = cairo.Context(surface) | |
c.set_source_rgb(0.85,0.85,0.85) | |
c.paint() | |
c.set_line_width(30) | |
c.set_line_join(cairo.LINE_JOIN_ROUND) | |
c.set_line_cap(cairo.LINE_CAP_ROUND) | |
x = WIDTH / 2 | |
y = HEIGHT / 2 | |
for i in range(400): | |
c.move_to(x, y) | |
n = random.randint(0,3) | |
l = random.choice([20, 50, 100]) | |
if n == 0: | |
x = x + l | |
elif n == 1: | |
y = y + l | |
elif n == 2: | |
y = y - l | |
elif n == 3: | |
x = x - l | |
x = max(min(WIDTH - MARGIN, x), MARGIN) | |
y = max(min(HEIGHT - MARGIN, y), MARGIN) | |
c.set_source_rgb(x/WIDTH,y/HEIGHT,1.0-(x+y)/(HEIGHT+WIDTH)) | |
c.line_to(x, y) | |
c.stroke() | |
surface.write_to_png("lines_2.png") |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment