~
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

195 lines
5.7 KiB

#!/usr/bin/env python3
import cairo
from math import pi
from time import sleep
from subprocess import run, PIPE
from datetime import datetime
from tempfile import NamedTemporaryFile
WIDTH, HEIGHT = 1920, 1080
FC1 = "#ea9a97"
FC2 = "#e0def4"
DC1 = "#c4a7e7"
DC2 = "#ea9a97"
LC1 = "#393552"
LC2 = "#9ccfd8"
BG1 = "#232136"
def fractal():
with NamedTemporaryFile(suffix='.config') as config, NamedTemporaryFile(suffix='.ppm') as ppm:
config.write(b'\n'.join([
b'c075',
b'julia',
b'0.5 0.25',
b'1.5 0 5 2.8125',
b'1E+40 1000',
b'1',
b'0x0',
b'averagecoloring',
b'curvature spline',
b'cube',
b'0.075 0.45',
bytes('0 0x%s 0.47 0x%s 0.65 0x%s 1 0x%s' % (DC2[1:], BG1[1:], LC1[1:], DC2[1:]), encoding='ascii')
]))
config.flush()
run('fractalnow -c %s -x %d -y %d -o %s' % (config.name, WIDTH, HEIGHT, ppm.name), stdout=PIPE, shell=True)
f = NamedTemporaryFile(suffix='.png')
run('convert %s %s' % (ppm.name, f.name), stdout=PIPE, shell=True)
return f
def pointer(c: cairo.Context, t: float, r1: float, r2: float):
o = c.get_current_point()
c.save()
c.rotate(t - pi / 2)
c.rel_move_to(r1, 0)
c.rel_line_to(r2 - r1, 0)
c.stroke()
c.restore()
c.move_to(*o)
def ngram(c: cairo.Context, n: int, d: int, t: float, r: float, w: float,
h: float):
lw = h / (2 * d - 1)
o = c.get_current_point()
c.save()
c.set_line_width(lw)
c.rotate(t)
x, y = c.get_current_point()
y = y + (h - lw) / 2 - r
for i in range(d):
z = ~(n >> i) & 1
c.move_to(x + z * lw / 2, y - i * 2 * lw)
c.rel_line_to(w / 2 - z * lw / 2, 0)
c.move_to(x - z * lw / 2, y - i * 2 * lw)
c.rel_line_to(-w / 2 + z * lw / 2, 0)
c.stroke()
c.restore()
c.move_to(*o)
def ultimate(c: cairo.Context, t: float, r: float, e: float):
border = (int(DC2[1:3], 16) / 256, int(DC2[3:5], 16) / 256, int(DC2[5:7], 16) / 256)
yin = (int(BG1[1:3], 16) / 256, int(BG1[3:5], 16) / 256, int(BG1[5:7], 16) / 256)
yang = (int(FC1[1:3], 16) / 256, int(FC1[3:5], 16) / 256, int(FC1[5:7], 16) / 256)
o = c.get_current_point()
c.save()
c.rotate(t - pi / 2)
x, y = c.get_current_point()
c.set_source_rgb(*border)
c.arc(x, y, 1.25 * r, 0, 2 * pi)
c.fill()
c.set_source_rgb(*yin)
c.arc(x, y, r, 0, pi)
c.fill()
c.set_source_rgb(*yang)
c.arc(x, y, r, pi, 0)
c.fill()
c.set_source_rgb(*yin)
c.arc(x - r / 2, y, r / 2, pi, 0)
c.fill()
c.set_source_rgb(*yang)
c.arc(x + r / 2, y, r / 2, 0, pi)
c.fill()
c.set_source_rgb(*yang)
c.arc(x - r / 2, y, e, 0, 2 * pi)
c.fill()
c.set_source_rgb(*yin)
c.arc(x + r / 2, y, e, 0, 2 * pi)
c.fill()
c.restore()
c.move_to(*o)
def main():
w, h = WIDTH, HEIGHT
bg1 = BG1[1:]
fc1 = FC1[1:]
fc2 = FC2[1:]
fc3 = (int(FC2[1:3], 16) / 256, int(FC2[3:5], 16) / 256, int(FC2[5:7], 16) / 256)
dc2 = DC2[1:]
dc3 = (int(DC2[1:3], 16) / 256, int(DC2[3:5], 16) / 256, int(DC2[5:7], 16) / 256)
lc2 = LC2[1:]
with NamedTemporaryFile(suffix='.png') as wp, fractal() as f:
while True:
s = cairo.ImageSurface.create_from_png(f.name)
c = cairo.Context(s)
b = 0.13 * min(w, h)
c.translate((1.5 * w - b) / 2, (h - b) / 2)
c.scale(b, b)
c.move_to(0.5, 0.5)
c.set_source_rgb(*fc3)
for i, n in enumerate([5, 0, 3, 7, 2, 4, 1, 6]):
ngram(c, n, 3, i * pi / 4, 0.5, 0.25, 0.21)
c.set_source_rgb(*dc3)
c.set_line_width(0.01)
t = datetime.now()
pointer(c, pi * (t.hour / 6 + t.minute / 360), 0.08, 0.28)
pointer(c, pi * t.minute / 30, 0.08, 0.35)
ultimate(c, 0, 0.04, 0.006)
s.write_to_png(wp.name)
run(' '.join([
'pscircle',
'--output-width=%d' % w,
'--output-height=%d' % h,
'--root-pid=1',
'--max-children=90',
'--dot-radius=2',
'--dot-border-width=2',
'--dot-color-min=' + lc2,
'--dot-color-max=' + bg1,
'--dot-border-color-min=' + dc2,
'--dot-border-color-max=' + lc2,
'--link-width=1.25',
'--link-convexity=0.4',
'--link-color-min=' + dc2,
'--link-color-max=' + lc2,
'--tree-font-size=12',
'--tree-font-face="IBM Plex Sans"',
'--tree-font-color=' + fc2,
'--tree-anchor-proc-name=kthreadd',
'--tree-center=%f:%f' % (0.25 * w, 0),
'--tree-radius-increment=%f' % (0.8547 * b),
'--toplists-row-height=20',
'--toplists-font-size=12',
'--toplists-font-color=' + fc2,
'--toplists-pid-font-color=' + fc1,
'--toplists-font-face="BigBlue TerminalPlus"',
'--toplists-column-padding=15',
'--toplists-bar-width=60',
'--toplists-bar-height=2',
'--toplists-bar-background=' + dc2,
'--toplists-bar-color=' + lc2,
'--cpulist-center=%f:%f' % (0.34 * w, -0.39 * h),
'--memlist-center=%f:%f' % (0.34 * w, 0.39 * h),
'--background-image=' + wp.name,
'--output=' + wp.name
]), stdout=PIPE, shell=True)
run(['feh', '--no-fehbg', '--bg-fill', wp.name])
sleep(30)
if __name__ == '__main__':
try:
main()
except KeyboardInterrupt:
pass