light-clock.py 2.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778
  1. import hyperion, time, datetime
  2. hyperion.imageMinSize(32,32)
  3. # Get the parameters
  4. showSec = bool(hyperion.args.get('show_seconds', True))
  5. hC = hyperion.args.get('hour-color', (0,0,255))
  6. mC = hyperion.args.get('minute-color', (0,255,0))
  7. sC = hyperion.args.get('second-color', (255,0,0))
  8. bgC = hyperion.args.get('background-color', (0,0,0))
  9. markEnable = hyperion.args.get('marker-enabled', False)
  10. markD = int(hyperion.args.get('marker-depth', 5))/100.0
  11. markW = int(hyperion.args.get('marker-width', 5))/100.0
  12. markC = hyperion.args.get('marker-color', (255,255,255))
  13. #calculate some stuff
  14. centerX = int(round(hyperion.imageWidth())/2)
  15. centerY = int(round(float(hyperion.imageHeight())/2))
  16. markDepthX = int(round(hyperion.imageWidth()*markD))
  17. markDepthY = int(round(hyperion.imageHeight()*markD))
  18. markThick = int(round(hyperion.imageHeight()*markW))
  19. colorsSecond = bytearray([
  20. 0, sC[0],sC[1],sC[2],255,
  21. 8, sC[0],sC[1],sC[2],255,
  22. 10, 0,0,0,0,
  23. ])
  24. colorsMinute = bytearray([
  25. 0, mC[0],mC[1],mC[2],255,
  26. 35, mC[0],mC[1],mC[2],255,
  27. 50, mC[0],mC[1],mC[2],127,
  28. 90, 0,0,0,0,
  29. ])
  30. colorsHour = bytearray([
  31. 0, hC[0],hC[1],hC[2],255,
  32. 90, hC[0],hC[1],hC[2],255,
  33. 150, hC[0],hC[1],hC[2],127,
  34. 191, 0,0,0,0,
  35. ])
  36. # effect loop
  37. while not hyperion.abort():
  38. now = datetime.datetime.now()
  39. angleH = 449 - 30*(now.hour if now.hour<12 else now.hour-12)
  40. angleM = 449 - 6*now.minute
  41. angleS = 449 - 6*now.second
  42. angleH -= 0 if angleH<360 else 360
  43. angleM -= 0 if angleM<360 else 360
  44. angleS -= 0 if angleS<360 else 360
  45. #reset image
  46. hyperion.imageSolidFill(bgC[0],bgC[1],bgC[2])
  47. #paint clock
  48. if angleH-angleM < 90 and angleH-angleM > 0:
  49. hyperion.imageConicalGradient(centerX, centerY, angleM, colorsMinute)
  50. hyperion.imageConicalGradient(centerX, centerY, angleH, colorsHour)
  51. else:
  52. hyperion.imageConicalGradient(centerX, centerY, angleH, colorsHour)
  53. hyperion.imageConicalGradient(centerX, centerY, angleM, colorsMinute)
  54. if showSec:
  55. hyperion.imageConicalGradient(centerX, centerY, angleS, colorsSecond)
  56. if markEnable:
  57. #marker left, right, top, bottom
  58. hyperion.imageDrawLine(0, centerY, 0+markDepthX, centerY, markThick, markC[0], markC[1], markC[2])
  59. hyperion.imageDrawLine(int(hyperion.imageWidth()), centerY, int(hyperion.imageWidth())-markDepthX, centerY, markThick, markC[0], markC[1], markC[2])
  60. hyperion.imageDrawLine(centerX, 0, centerX, 0+markDepthY, markThick, markC[0], markC[1], markC[2])
  61. hyperion.imageDrawLine(centerX, int(hyperion.imageHeight()), centerX, int(hyperion.imageHeight())-markDepthY, markThick, markC[0], markC[1], markC[2])
  62. hyperion.imageShow()
  63. time.sleep(0.5)