Skip to content

Instantly share code, notes, and snippets.

@nst
Created September 14, 2022 16:55
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/c689416bf23cccfc858e0f184280d7ed to your computer and use it in GitHub Desktop.
Save nst/c689416bf23cccfc858e0f184280d7ed to your computer and use it in GitHub Desktop.
#!/usr/bin/env python3
# https://twitter.com/nst021/status/1570047611989540865
# https://seriot.ch/visualization/circles.png
import cairo
import math
N = 10
STEP = 20
MARGIN = 70
W = MARGIN*2 + 2*(N-1)*STEP
H = W
surface = cairo.ImageSurface(cairo.FORMAT_ARGB32, W, H)
c = cairo.Context(surface)
c.set_source_rgb(0,0,0)
c.paint()
c.set_source_rgb(0.3,0.3,1)
c.set_line_width(3)
m1 = cairo.Matrix(x0=MARGIN)
m2 = cairo.Matrix(xx=-1, x0=W-MARGIN, yy=-1, y0=H)
for m in [m1, m2]:
c.save()
c.transform(m)
for n in range(N):
c.arc(STEP*n, H/2, STEP*(n+1), math.pi, 0)
c.stroke()
c.restore()
surface.write_to_png("circles.png")
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment