169 lines
4.6 KiB
Python
169 lines
4.6 KiB
Python
#!/usr/bin/env python3
|
|
|
|
import cairo
|
|
from math import pi
|
|
from time import sleep
|
|
from subprocess import run
|
|
from datetime import datetime
|
|
from tempfile import NamedTemporaryFile
|
|
|
|
WIDTH, HEIGHT = 1920, 1080
|
|
|
|
FC1 = "#9aa7bd"
|
|
FC2 = "#51617d"
|
|
BC1 = "#ffffff"
|
|
DC1 = "#608cc3"
|
|
DC2 = "#b15e7c"
|
|
LC1 = "#323c4d"
|
|
LC2 = "#b5a262"
|
|
BG1 = "#232936"
|
|
|
|
|
|
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 = not (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, r, e):
|
|
o = c.get_current_point()
|
|
c.save()
|
|
c.rotate(t - pi / 2)
|
|
x, y = c.get_current_point()
|
|
c.set_source_rgb(0, 0, 0)
|
|
c.arc(x, y, r, 0, pi)
|
|
c.fill()
|
|
c.set_source_rgb(1, 1, 1)
|
|
c.arc(x, y, r, pi, 0)
|
|
c.fill()
|
|
c.set_source_rgb(0, 0, 0)
|
|
c.arc(x - r / 2, y, r / 2, pi, 0)
|
|
c.fill()
|
|
c.set_source_rgb(1, 1, 1)
|
|
c.arc(x + r / 2, y, r / 2, 0, pi)
|
|
c.fill()
|
|
c.set_source_rgb(1, 1, 1)
|
|
c.arc(x - r / 2, y, e, 0, 2 * pi)
|
|
c.fill()
|
|
c.set_source_rgb(0, 0, 0)
|
|
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 = (int(BG1[1:3], 16) / 256, int(BG1[3:5], 16) / 256,
|
|
int(BG1[5:7], 16) / 256)
|
|
fc1 = FC1[1:]
|
|
fc2 = FC2[1:]
|
|
fc3 = (int(BC1[1:3], 16) / 256, int(BC1[3:5], 16) / 256,
|
|
int(BC1[5:7], 16) / 256)
|
|
dc1 = DC1[1:]
|
|
dc2 = DC2[1:]
|
|
lc1 = LC1[1:]
|
|
lc2 = LC2[1:]
|
|
|
|
s = cairo.ImageSurface(cairo.FORMAT_ARGB32, w, h)
|
|
c = cairo.Context(s)
|
|
|
|
b = 0.13 * min(w, h)
|
|
c.translate((w - b) / 2, (h - b) / 2)
|
|
c.scale(b, b)
|
|
|
|
with NamedTemporaryFile(suffix='.png') as wp:
|
|
while True:
|
|
c.move_to(0.5, 0.5)
|
|
|
|
c.set_source_rgb(*bg1)
|
|
c.paint()
|
|
|
|
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_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([
|
|
'pscircle',
|
|
'--output-width=%d' % w,
|
|
'--output-height=%d' % h,
|
|
'--root-pid=1',
|
|
'--max-children=90',
|
|
'--dot-radius=2',
|
|
'--dot-border-width=1',
|
|
'--dot-color-min=' + dc1,
|
|
'--dot-color-max=' + dc2,
|
|
'--dot-border-color-min=' + lc1,
|
|
'--dot-border-color-max=' + lc2,
|
|
'--link-width=1.25',
|
|
'--link-convexity=0.4',
|
|
'--background-image=~/.config/wall.png',
|
|
'--link-color-min=' + lc1,
|
|
'--link-color-max=' + lc2,
|
|
'--tree-font-size=12',
|
|
'--tree-font-face=TamzenForPowerline',
|
|
'--tree-font-color=' + fc1,
|
|
'--tree-anchor-proc-name=kthreadd',
|
|
'--tree-radius-increment=%f' % (0.8547 * b),
|
|
'--toplists-row-height=20',
|
|
'--toplists-font-size=12',
|
|
'--toplists-font-color=' + fc1,
|
|
'--toplists-pid-font-color=' + fc2,
|
|
'--toplists-font-face=TamzenForPowerline',
|
|
'--toplists-column-padding=15',
|
|
'--toplists-bar-width=60',
|
|
'--toplists-bar-height=3',
|
|
'--toplists-bar-background=' + lc1,
|
|
'--toplists-bar-color=' + dc1,
|
|
'--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
|
|
])
|
|
|
|
run(['feh', '--no-fehbg', '--bg-fill', wp.name])
|
|
sleep(30)
|
|
|
|
|
|
if __name__ == '__main__':
|
|
try:
|
|
main()
|
|
except KeyboardInterrupt:
|
|
pass
|