test.py 1.6 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980
  1. #!/usr/bin/env python3
  2. # Author: Owen Smith - Rewritten from test.pl by Huidae Cho
  3. # Run: d.mon start=wx0 && ./test.py | d.text at=0,100
  4. import math
  5. import re
  6. # Quiet black syntax checking for fonts and colors to keep the code printed to
  7. # the display vertically short.
  8. # fmt: off
  9. fonts = ("cyrilc", "gothgbt", "gothgrt", "gothitt", "greekc", "greekcs",
  10. "greekp", "greeks", "italicc", "italiccs", "italict", "romanc",
  11. "romancs", "romand", "romans", "romant", "scriptc", "scripts",
  12. "cyrilc", "gothgbtlu")
  13. colors = ("red", "orange", "yellow", "green", "blue", "indigo", "violet",
  14. "black", "gray", "brown", "magenta", "aqua", "grey", "cyan",
  15. "purple")
  16. # fmt: on
  17. def rc(r, c):
  18. print(f".X {r}\n.Y {c}")
  19. def xy(x, y):
  20. print(f".X {x}%\n.Y {y}%")
  21. def font(f):
  22. print(f".F {f}")
  23. def size(s):
  24. print(f".S {s}")
  25. def color(c):
  26. print(f".C {c}")
  27. def rotate(r):
  28. print(f".R {r}")
  29. def align(a):
  30. print(f".A {a}")
  31. def text(in_text):
  32. print(f"{in_text}")
  33. for i in range(36):
  34. font(fonts[int(i % len(fonts))])
  35. size(((36 - i if (i >= 9 and i <= 18 or i > 27) else i) % 9))
  36. rotate(i * 10)
  37. color(colors[i % len(colors)])
  38. xy(
  39. (80 + 10 * math.cos(i * 10 / 180 * 3.141593)),
  40. (50 + 10 * 640 / 480 * math.sin(i * 10 / 180 * 3.141593)),
  41. )
  42. text(fonts[int(i % len(fonts))])
  43. size(2)
  44. rotate(0)
  45. font("romans")
  46. color("gray")
  47. rc(1, 1)
  48. with open(__file__) as f:
  49. src = f.read()
  50. print(
  51. ".L 0\n"
  52. + re.sub(
  53. '(".*?")',
  54. "\n.C red\n,\\g<0>\n.C gray\n",
  55. re.sub("\n", "\n.L 1\n.L 0\n", re.sub("(?m)^#.*\n?", "", src)),
  56. )
  57. )