Created
May 12, 2021 23:19
-
-
Save scruss/98d80168658a84c7279c866b28689a93 to your computer and use it in GitHub Desktop.
lazy caterer plots - coloured lines, but rather dull
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/python3 | |
# lazy caterer sequence - 'thank' you josh millard ... | |
# scruss - 2021-05 | |
# usage: lazy_caterer.py [lines] > output.eps | |
from random import uniform | |
from math import sin, cos, radians | |
from sys import argv | |
lines = 9 | |
if len(argv) > 1: | |
lines = int(argv[1]) | |
points = [None] * (2*lines) | |
sector = 360 / (2*lines) | |
offset = uniform(0, 120) | |
for i in range(len(points)): | |
points[i] = uniform(sector*i, sector*(i+1)) | |
# ps coords are y up from BL | |
# circle radius 75 mm, centre (90, 90) mm | |
mm = 72/25.4 # mm in PS units | |
xc = 90 * mm | |
yc = 90 * mm | |
radius = 75 * mm | |
linethick = 0.25 * mm | |
print("%!") | |
print("%%BoundingBox: 42 42 469 469") | |
print("%%HiResBoundingBox: 42.155999 42.155999 468.079861 468.071986") | |
print(linethick, "setlinewidth") | |
print("1 setlinecap") | |
print("0.95 setgray") | |
print("newpath") | |
print(xc+radius, yc, "moveto") | |
print(xc, yc, radius, "0 360 arc fill newpath") | |
for i in range(lines): | |
print("% line", i+1, ": from ", | |
points[i], "deg to ", points[i+lines], "deg") | |
angle = (points[i] + (points[i+lines] + points[i])/2) % 360 | |
angle = (angle+offset) % 360 | |
print(angle/360.0, "1 1 sethsbcolor") | |
p1 = [xc + radius * cos(radians(points[i])), | |
yc + radius * sin(radians(points[i]))] | |
p2 = [xc + radius * cos(radians(points[i+lines])), | |
yc + radius * sin(radians(points[i+lines]))] | |
print(p1[0], p1[1], "moveto") | |
print(p2[0], p2[1], "lineto stroke") | |
print("0 setgray") | |
print("newpath") | |
print(xc+radius, yc, "moveto") | |
print(xc, yc, radius, "0 360 arc stroke") | |
print("showpage") |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment