flag.py 8.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222
  1. import hyperion, time
  2. hyperion.imageMinSize(10,10)
  3. iW = hyperion.imageWidth()
  4. iH = hyperion.imageHeight()
  5. countries = hyperion.args.get('countries', ("de","at"))
  6. duration = int(hyperion.args.get('switch-time', 5))
  7. imgIds = []
  8. nr = 0
  9. def switchImage():
  10. global nr
  11. if nr >= len(imgIds):
  12. nr = 0
  13. hyperion.imageShow(imgIds[nr])
  14. nr += 1
  15. def printFlag(country):
  16. # official country codes
  17. #############
  18. # EU flags -> missing: cyprus, UK
  19. #############
  20. # de flag (Germany)
  21. if country == "de":
  22. hyperion.imageSolidFill(0, 0, iW, int(iH*0.33), 0, 0, 0)
  23. hyperion.imageSolidFill(0, int(iH*0.33), iW, int(iH*0.33), 221, 0, 0)
  24. hyperion.imageSolidFill(0, int(iH*0.66), iW, iH, 255, 206, 0)
  25. # at flag (Austria)
  26. if country == "at":
  27. hyperion.imageSolidFill(237, 41, 57)
  28. hyperion.imageSolidFill(0, int(iH*0.33), iW, int(iH*0.33), 255, 255, 255)
  29. # fr flag (France)
  30. if country == "fr":
  31. hyperion.imageSolidFill(0, 0, int(iW*0.33), iH, 0, 35, 149)
  32. hyperion.imageSolidFill(int(iW*0.33), 0, int(iW*0.33), iH, 255, 255, 255)
  33. hyperion.imageSolidFill(int(iW*0.66), 0, iW, iH, 237, 41, 57)
  34. # be flag (Belgium)
  35. if country == "be":
  36. hyperion.imageSolidFill(0, 0, int(iW*0.33), iH, 0, 0, 0)
  37. hyperion.imageSolidFill(int(iW*0.33), 0, int(iW*0.33), iH, 255, 224, 66)
  38. hyperion.imageSolidFill(int(iW*0.66), 0, iW, iH, 237, 41, 57)
  39. # it flag (Italy)
  40. if country == "it":
  41. hyperion.imageSolidFill(0, 0, int(iW*0.33), iH, 0, 146, 70)
  42. hyperion.imageSolidFill(int(iW*0.33), 0, int(iW*0.33), iH, 255, 255, 255)
  43. hyperion.imageSolidFill(int(iW*0.66), 0, iW, iH, 206, 43, 55)
  44. # es flag (Spain)
  45. if country == "es":
  46. hyperion.imageSolidFill(198, 11, 30)
  47. hyperion.imageSolidFill(0, int(iH*0.25), iW, int(iH*0.55), 255, 196, 0)
  48. # bg flag (Bulgaria)
  49. if country == "bg":
  50. hyperion.imageSolidFill(0, 0, iW, int(iH*0.33), 255, 255, 255)
  51. hyperion.imageSolidFill(0, int(iH*0.33), iW, int(iH*0.33), 0, 150, 110)
  52. hyperion.imageSolidFill(0, int(iH*0.66), iW, iH, 214, 38, 18)
  53. # ee flag (Estonia)
  54. if country == "ee":
  55. hyperion.imageSolidFill(0, 0, iW, int(iH*0.33), 72, 145, 217)
  56. hyperion.imageSolidFill(0, int(iH*0.33), iW, int(iH*0.33), 0, 0, 0)
  57. hyperion.imageSolidFill(0, int(iH*0.66), iW, iH, 255, 255, 255)
  58. # dk flag (Denmark)
  59. if country == "dk":
  60. hyperion.imageSolidFill(198, 12, 48)
  61. hyperion.imageDrawLine(int(iW*0.35), 0, int(iW*0.35), iH, int(iW*0.13), 255, 255, 255)
  62. hyperion.imageDrawLine(0, int(iH*0.5), iW, int(iH*0.5), int(iW*0.13), 255, 255, 255)
  63. # fi flag (Finland)
  64. if country == "fi":
  65. hyperion.imageSolidFill(255, 255, 255)
  66. hyperion.imageDrawLine(int(iW*0.35), 0, int(iW*0.35), iH, int(iW*0.18), 0, 53, 128)
  67. hyperion.imageDrawLine(0, int(iH*0.5), iW, int(iH*0.5), int(iW*0.18), 0, 53, 128)
  68. # hu flag (Hungary)
  69. if country == "hu":
  70. hyperion.imageSolidFill(0, 0, iW, int(iH*0.33), 205, 42, 62)
  71. hyperion.imageSolidFill(0, int(iH*0.33), iW, int(iH*0.33), 255, 255, 255)
  72. hyperion.imageSolidFill(0, int(iH*0.66), iW, iH, 67, 111, 77)
  73. # ie flag (Ireland)
  74. if country == "ie":
  75. hyperion.imageSolidFill(0, 0, int(iW*0.33), iH, 0, 155, 72)
  76. hyperion.imageSolidFill(int(iW*0.33), 0, int(iW*0.33), iH, 255, 255, 255)
  77. hyperion.imageSolidFill(int(iW*0.66), 0, iW, iH, 255, 121, 0)
  78. # lv flag (Latvia)
  79. if country == "lv":
  80. hyperion.imageSolidFill(158, 48, 57)
  81. hyperion.imageDrawLine(0, int(iH*0.5), iW, int(iH*0.5), int(iH*0.2), 255, 255, 255)
  82. # lt flag (Lithuanian)
  83. if country == "lt":
  84. hyperion.imageSolidFill(0, 0, iW, int(iH*0.33), 253, 185, 19)
  85. hyperion.imageSolidFill(0, int(iH*0.33), iW, int(iH*0.33), 0, 106, 68)
  86. hyperion.imageSolidFill(0, int(iH*0.66), iW, iH, 193, 39, 45)
  87. # lu flag (Luxembourg)
  88. if country == "lu":
  89. hyperion.imageSolidFill(0, 0, iW, int(iH*0.33), 237, 41, 57)
  90. hyperion.imageSolidFill(0, int(iH*0.33), iW, int(iH*0.33), 255, 255, 255)
  91. hyperion.imageSolidFill(0, int(iH*0.66), iW, iH, 0, 161, 222)
  92. # mt flag (Malta)
  93. if country == "mt":
  94. hyperion.imageSolidFill(0, 0, int(iW*0.5), iH, 255, 255, 255)
  95. hyperion.imageSolidFill(int(iW*0.5), 0, int(iW*0.5), iH, 207, 20, 43)
  96. # nl flag (Netherlands)
  97. if country == "nl":
  98. hyperion.imageSolidFill(0, 0, iW, int(iH*0.33), 174, 28, 40)
  99. hyperion.imageSolidFill(0, int(iH*0.33), iW, int(iH*0.33), 255, 255, 255)
  100. hyperion.imageSolidFill(0, int(iH*0.66), iW, iH, 33, 70, 139)
  101. # pl flag (Poland)
  102. if country == "pl":
  103. hyperion.imageSolidFill(255, 255, 255)
  104. hyperion.imageSolidFill(0, int(iH*0.5), iW, iH, 220, 20, 60)
  105. # pt flag (Portugal)
  106. if country == "pt":
  107. hyperion.imageSolidFill(0, 102, 0)
  108. hyperion.imageSolidFill(int(iW*0.4), 0, iW, iH, 255, 0, 0)
  109. # ro flag (Romania)
  110. if country == "ro":
  111. hyperion.imageSolidFill(0, 0, int(iW*0.33), iH, 0, 43, 127)
  112. hyperion.imageSolidFill(int(iW*0.33), 0, int(iW*0.33), iH, 252, 209, 22)
  113. hyperion.imageSolidFill(int(iW*0.66), 0, iW, iH, 206, 17, 38)
  114. # sl flag (Slovakia/Slovenia)
  115. if country == "sl":
  116. hyperion.imageSolidFill(0, 0, iW, int(iH*0.33), 255, 255, 255)
  117. hyperion.imageSolidFill(0, int(iH*0.33), iW, int(iH*0.33), 11, 78, 162)
  118. hyperion.imageSolidFill(0, int(iH*0.66), iW, iH, 238, 28, 37)
  119. # se flag (Sweden)
  120. if country == "se":
  121. hyperion.imageSolidFill(0, 106, 167)
  122. hyperion.imageDrawLine(int(iW*0.35), 0, int(iW*0.35), iH, int(iW*0.14), 254, 204, 0)
  123. hyperion.imageDrawLine(0, int(iH*0.5), iW, int(iH*0.5), int(iW*0.14), 254, 204, 0)
  124. # cz flag (Czech Republic)
  125. if country == "cz":
  126. hyperion.imageSolidFill(255, 255, 255)
  127. hyperion.imageSolidFill(0, int(iH*0.5), iW, iH, 215, 20, 26)
  128. hyperion.imageDrawPolygon(bytearray([0,0,int(iH*0.5),int(iH*0.5),0,iH]),17, 69, 126)
  129. # gr flag (Greece)
  130. if country == "gr":
  131. hyperion.imageSolidFill(13, 94, 175)
  132. hyperion.imageDrawLine(int(iW*0.35), int(iH*0.15), iW, int(iH*0.15),int(0.1*iH), 255, 255, 255)
  133. hyperion.imageDrawLine(int(iW*0.35), int(iH*0.35), iW, int(iH*0.35),int(0.1*iH), 255, 255, 255)
  134. hyperion.imageDrawLine(0, int(iH*0.55), iW, int(iH*0.55),int(0.1*iH), 255, 255, 255)
  135. hyperion.imageDrawLine(0, int(iH*0.75), iW, int(iH*0.75),int(0.1*iH), 255, 255, 255)
  136. hyperion.imageDrawLine(int(0.175*iW), 0, int(0.175*iW), int(iH*0.35),int(0.1*iH), 255, 255, 255)
  137. hyperion.imageDrawLine(0, int(0.175*iW), int(iH*0.35), int(0.175*iW),int(0.1*iH), 255, 255, 255)
  138. #############
  139. # other flags
  140. #############
  141. # ch flag (Swiss)
  142. if country == "ch":
  143. hyperion.imageSolidFill(255, 0, 0)
  144. hyperion.imageDrawLine(int(iW*0.5), int(iH*0.25), int(iW*0.5), int(iH*0.75), int(iH*0.15), 255, 255, 255)
  145. hyperion.imageDrawLine(int(iW*0.26), int(iH*0.5), int(iW*0.75), int(iH*0.5), int(iH*0.15), 255, 255, 255)
  146. # cmr flag (Cameroon)
  147. if country == "cmr":
  148. hyperion.imageSolidFill(0, 0, int(iW*0.33), iH, 0, 255, 0)
  149. hyperion.imageSolidFill(int(iW*0.33), 0, int(iW*0.33), iH, 255, 0, 0)
  150. hyperion.imageSolidFill(int(iW*0.66), 0, iW, iH, 255, 255, 0)
  151. # ru flag (Russia)
  152. if country == "ru":
  153. hyperion.imageSolidFill(0, 0, iW, int(iH*0.33), 255, 255, 255)
  154. hyperion.imageSolidFill(0, int(iH*0.33), iW, int(iH*0.33), 0, 57, 166)
  155. hyperion.imageSolidFill(0, int(iH*0.66), iW, iH, 213, 43, 30)
  156. # gb-eng flag (England)
  157. if country == "gb-eng":
  158. hyperion.imageSolidFill(255, 255, 255)
  159. hyperion.imageDrawLine(0, int(iH*0.50), iW, int(iH*0.50), int(iW*0.10), 255, 0, 0)
  160. hyperion.imageDrawLine(int(iW*0.50), 0, int(iW*0.50), iH, int(iW*0.10), 255, 0, 0)
  161. # gb-sct flag (Scotland)
  162. if country == "gb-sct":
  163. hyperion.imageSolidFill(0, 0, 255)
  164. hyperion.imageDrawLine(0, 0, iW, iH, int(iW*0.15), 255, 255, 255)
  165. hyperion.imageDrawLine(0, iH, iW, 0, int(iW*0.15), 255, 255, 255)
  166. # gb flag (United Kingdom)
  167. if country == "gb":
  168. hyperion.imageSolidFill(0, 0, 255)
  169. hyperion.imageDrawLine(0, int(iH*0.50), iW, int(iH*0.50), int(iW*0.25), 255, 255, 255)
  170. hyperion.imageDrawLine(int(iW*0.50), 0, int(iW*0.50), iH, int(iW*0.25), 255, 255, 255)
  171. hyperion.imageDrawLine(0, 0, iW, iH, int(iH*0.25), 255, 255, 255)
  172. hyperion.imageDrawLine(0, iH, iW, 0, int(iH*0.25), 255, 255, 255)
  173. hyperion.imageDrawLine(0, int(iH*0.50), iW, int(iH*0.50), int(iW*0.15), 255, 0, 0)
  174. hyperion.imageDrawLine(int(iW*0.50), 0, int(iW*0.50), iH, int(iW*0.15), 255, 0, 0)
  175. hyperion.imageDrawLine(int(iW*0.95), 0, int(iW*0.475), int(iH*0.50), int(iH*0.10), 255, 0, 0)
  176. hyperion.imageDrawLine(int(iW*0.05), iH, int(iW*0.525), int(iH*0.50), int(iH*0.10), 255, 0, 0)
  177. hyperion.imageDrawLine(int(-iW*0.05), 0, int(iW*0.475), int(iH*0.50), int(iH*0.10), 255, 0, 0)
  178. hyperion.imageDrawLine(int(iW*1.05), iH, int(iW*0.475), int(iH*0.50), int(iH*0.10), 255, 0, 0)
  179. #prepare wanted flags
  180. for cf in countries:
  181. printFlag(cf)
  182. imgIds.append(hyperion.imageSave())
  183. hyperion.imageSolidFill(0, 0, 0)
  184. while not hyperion.abort():
  185. switchImage()
  186. time.sleep(duration)