vpu_live.py 22 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803
  1. import math
  2. import random
  3. import time
  4. import os
  5. from optparse import OptionParser
  6. ...
  7. parser = OptionParser()
  8. parser.add_option("-m", "--mode", dest="mode",
  9. help="pixel mode") #, metavar="FILE")
  10. parser.add_option("-X", "--XX", dest="XX", #default=1,
  11. help="x-split") #, metavar="FILE")
  12. parser.add_option("-x", "--xx", dest="xsplit", #default=1,
  13. help="x-split") #, metavar="FILE")
  14. parser.add_option("-y", "--yy", dest="ysplit",#default=1,
  15. help="y-split") #, metavar="FILE")
  16. parser.add_option("-s", "--start-univ", dest="start_univ",#default=1,
  17. help="set start-univers default=2") #, metavar="FILE")
  18. parser.add_option("-g", "--gobo-ch", dest="gobo_ch",#default=1,
  19. help="gobo ch univ on 1") #, metavar="FILE")
  20. #parser.add_option("-f", "--file", dest="filename",
  21. # help="write report to FILE", metavar="FILE")
  22. #parser.add_option("-q", "--quiet",
  23. # action="store_false", dest="verbose", default=True,
  24. # help="don't print status messages to stdout")
  25. (options, args) = parser.parse_args()
  26. START = time.time()
  27. # ===== ARTNET DMX =========
  28. import memcache
  29. mc = memcache.Client(['127.0.0.1:11211'], debug=0)
  30. def read_index():
  31. ips=mc.get("index")#cmd)
  32. if ips is None:
  33. ips = {}
  34. #for k,v in ips.items():
  35. # print(k,v)
  36. return ips
  37. def select_ip(ips, univ=2): # artnet univ
  38. _univ = ":{}".format(univ)
  39. for ip in ips: #high priority
  40. if "2.0.0" in ip and _univ in ip:
  41. return ip
  42. for ip in ips:
  43. if "ltp-out" in ip and _univ in ip:
  44. return ip
  45. FUNC = 0
  46. def read_dmx(ip):
  47. global frame
  48. r = ""
  49. if ip:
  50. #t = int(math.sin(time.time() - s)*10)
  51. r = mc.get(ip) #"2.0.0.13:2")
  52. frame += 1
  53. rr = [0]*512
  54. for i,v in enumerate(r):
  55. try: #cleanup ltp-out to int
  56. v = int(v)
  57. rr[i] = v
  58. except:pass
  59. r = rr
  60. if not r:
  61. c = 0
  62. #time.sleep(0.1)
  63. r = [0] *512
  64. for i in range(12*8+1):
  65. dmx = i*4
  66. #print(dmx)
  67. r[dmx:dmx+4] = [255,10,10,40]
  68. return r
  69. # ===== ARTNET DMX =========
  70. p = 16
  71. block = [p,p]
  72. _x = 8
  73. _y = 8
  74. #HD = "0"
  75. if options.mode:
  76. try:
  77. HD = options.mode
  78. p,_x,_y = HD.split(",")
  79. _x = int(_x)
  80. _y = int(_y)
  81. p = int(p)
  82. block = [p,p]
  83. except Exception as e:
  84. print( "Exc",options.mode,e)
  85. HD_x = 2
  86. HD_y = 2
  87. print( [options.xsplit])
  88. print( [options.ysplit])
  89. try:
  90. if options.xsplit:
  91. HD_x = int(options.xsplit)
  92. if options.ysplit:
  93. HD_y = int(options.ysplit)
  94. except Exception as e:
  95. print( "Exc",options.mode,e)
  96. print("HD",HD_x,HD_y)
  97. print("xy",_x,_y)
  98. print("++++++++++++++++++", p,_x,_y)
  99. _x2 = _x
  100. try:
  101. if options.XX:
  102. _x2 = int(options.XX)
  103. except Exception as e:
  104. print( "Exc",options.mode,e)
  105. print("_x2 , -X",_x2)
  106. # ===== GUI =========
  107. import pygame
  108. import pygame.gfxdraw
  109. import pygame.font
  110. os.environ['SDL_VIDEO_WINDOW_POS'] = '%i,%i' % (200,164)
  111. os.environ['SDL_VIDEO_CENTERED'] = '0'
  112. pg = pygame
  113. pygame.init()
  114. pygame.mixer.quit()
  115. f = pygame.font.get_fonts()
  116. for i in f:
  117. if "mono" in i.lower():
  118. print(i)
  119. font = pygame.font.SysFont("freemonobold",22)
  120. font10 = pygame.font.SysFont("freemonobold",10)
  121. font12 = pygame.font.SysFont("freemonobold",12)
  122. font15 = pygame.font.SysFont("freemonobold",15)
  123. #font = pygame.font.SysFont(None,30)
  124. fr = font.render("hallo" ,1, (200,0,255))
  125. main_size=(600,500)
  126. try:
  127. wx = 100+block[0] * _x
  128. wy = 100+block[1] * _y
  129. main_size=(wx,wy)
  130. except Exception as e:
  131. print("Exception:",e)
  132. #main_size=(280,200)
  133. window = pygame.display.set_mode(main_size,pg.RESIZABLE)#,32)#,pygame.FULLSCREEN) #x left->right ,y top-> bottom
  134. pg.display.set_caption('LibreLight LED-SCREEN')
  135. class Fix():
  136. def __init__(self,_id,pos,block=[16,16],univ=0,dmx=0,ch=4):
  137. #print("Fix",_id)
  138. self._id = _id
  139. self.dmx = (_id-1) * ch +1 #dmx
  140. self.univ = univ
  141. self.ch = ch
  142. self.pos = pos
  143. self.rgb = [0,0,0]
  144. self.block = block #[10,10]
  145. self.x = pos[0]
  146. self.y = pos[1]
  147. self.strobo = time.time()
  148. self.bmp = 250
  149. self.sub_fix = []
  150. sub_block =[block[0]/HD_x,block[1]/HD_y]
  151. if _id <= 0: #exit
  152. return
  153. spalte = (_id-1)%_y +1
  154. zeile = int((_id-1)/_x2) #+1
  155. #zeile = zeile*_x*HD_x*HD_y
  156. add_row = _x*HD_x*HD_y
  157. #zeile 1
  158. sid = (_id-1)*2 + zeile*HD_x*_x2
  159. #for i in range(1,HD_x):
  160. sid = sid+1
  161. #sid = zeile
  162. sub_pos= [pos[0]*block[0],pos[1]*block[1]]
  163. sub_fix = SubFix(sid,sub_pos,sub_block,univ,dmx,ch)
  164. self.sub_fix.append(sub_fix)
  165. sid = sid+1
  166. #sid = zeile
  167. sub_pos= [pos[0]*block[0]+block[0]/2,pos[1]*block[1]]
  168. sub_fix = SubFix(sid,sub_pos,sub_block,univ,dmx,ch)
  169. self.sub_fix.append(sub_fix)
  170. #zeile 2
  171. sid = (_id-1)*2+1 + _x2*HD_x + zeile*HD_x*_x2 # int(add_row)
  172. #sid = sid+1
  173. #sid = HD_x
  174. sub_pos= [pos[0]*block[0],pos[1]*block[1]+block[1]/2]
  175. sub_fix = SubFix(sid,sub_pos,sub_block,univ,dmx,ch)
  176. self.sub_fix.append(sub_fix)
  177. #sid = sid+1
  178. sid = sid+1
  179. sub_pos= [pos[0]*block[0]+block[0]/2,pos[1]*block[1]+block[1]/2]
  180. sub_fix = SubFix(sid,sub_pos,sub_block,univ,dmx,ch)
  181. self.sub_fix.append(sub_fix)
  182. def calc(self,data):
  183. _rgb = [0,255,0]
  184. return _rgb
  185. def sub_calc(self,data):
  186. _rgb = [0,255,0]
  187. for sub_fix in self.sub_fix:
  188. sub_fix.block = self.block[:]
  189. _rgb = sub_fix.calc(data)
  190. return _rgb
  191. def POS(self,x=0,y=0,a=0,b=0):
  192. A = (self.pos[0])*self.block[0]
  193. B = (self.pos[1])*self.block[1]
  194. C = self.block[0]-a
  195. D = self.block[1]-b
  196. return [x+A,y+B,C,D]
  197. def subPOS(self,x=0,y=0,a=0,b=0):
  198. __out = []
  199. for sub_fix in self.sub_fix:
  200. __out.append( sub_fix.POS(x,y,a,b) )
  201. return __out
  202. class SubFix():
  203. def __init__(self,_id,pos,block=[16,16],univ=0,dmx=0,ch=4):
  204. #print("Fix",_id)
  205. self._id = _id
  206. self.dmx = (_id-1) * ch +1 #dmx
  207. self.univ = univ
  208. self.ch = ch
  209. self.pos = pos
  210. self.rgb = [0,0,40]
  211. self.block = block #[10,10]
  212. self.x = pos[0]
  213. self.y = pos[1]
  214. self.strobo = time.time()
  215. self.bmp = 250
  216. def calc(self,data):
  217. #return [130,30,20]
  218. dmx_sub = [30]*10
  219. #print(dmx_sub)
  220. dmx = self.dmx -1
  221. _dmx_sub = []
  222. if self.dmx >= 0:
  223. dmx = rDMX(self.univ,self.dmx)-1
  224. if dmx+self.ch < len(data):
  225. _dmx_sub = data[dmx:dmx+self.ch]
  226. if _dmx_sub:
  227. dmx_sub = _dmx_sub
  228. #print(dmx_sub)
  229. dim = dmx_sub[0]/255
  230. #print("dmx",dmx,dmx_sub)
  231. r = dmx_sub[1]*dim
  232. g = dmx_sub[2]*dim
  233. b = dmx_sub[3]*dim
  234. r = int(r)
  235. g = int(g)
  236. b = int(b)
  237. self.rgb = [r,g,b]
  238. return self.rgb
  239. def POS(self,x=0,y=0,a=0,b=0):
  240. A = (self.pos[0]) #+self.block[0]
  241. B = (self.pos[1]) #+self.block[1]
  242. C = self.block[0]-a
  243. D = self.block[1]-b
  244. if NR:
  245. C-=1
  246. D-=1
  247. return [int(x+A),int(y+B),int(C),int(D)]
  248. class POINTER():
  249. def __init__(self):
  250. self.pos = [0,0,0,0]
  251. self.on = 0
  252. self.rgb = [0,100,10]
  253. self._x = 0
  254. self._y = 0
  255. self.x = 0
  256. self.y = 0
  257. self.fix = Fix(0 ,[999,999],[16,16],0,0,0)
  258. def row_move(self,x,y):
  259. self._x = x
  260. self._y = y
  261. def move(self,pos):
  262. self.pos = pos
  263. self.on = 1
  264. def cross(self,x,y):
  265. self.x = x
  266. self.y = y
  267. def draw(self):
  268. if self.on:
  269. pygame.draw.rect(window,self.rgb,self.pos)
  270. #pygame.draw.line(window,self.rgb, (self.pos[0],self.pos[1]) , (self.pos[0]+100,self.pos[1]) )
  271. # mouse grid posision
  272. fr = font15.render("{}/{}".format(self.fix.x+1,self.fix.y) ,1, (200,200,200))
  273. _nr = self.fix.y * _x + self.fix.x +1
  274. #fr = font15.render("{:02} {}/{}".format(_nr, self.fix.x+1,self.fix.y+1 ) ,1, (200,200,200))
  275. fr = font15.render("{:02}".format(_nr ) ,1, (200,200,200))
  276. window.blit(fr,(self.pos[0]+2,self.pos[1]+2 ))
  277. window.blit(fr,(200,25))
  278. # fix pos
  279. txt=str(self.pos)
  280. fr = font15.render(txt ,1, (200,200,200))
  281. #window.blit(fr,(self.pos[0]+2,self.pos[1]+2 ))
  282. window.blit(fr,(200,10))
  283. # univers
  284. #fr = font15.render("{:02}:{:03}".format(self.fix.univ,self.fix.dmx) ,1, (200,200,200))
  285. #window.blit(fr,(300,10))
  286. # pointer
  287. fr = font15.render("X:{:03}".format(self._x) ,1, (200,200,200))
  288. window.blit(fr,(10,30))
  289. fr = font15.render("Y:{:03}".format(self._y) ,1, (200,200,200))
  290. window.blit(fr,(10,40))
  291. # crosshair
  292. self.rgb = [0,0,200]
  293. pygame.draw.line(window,self.rgb, (self.x-p,self.y) , (self.x-2,self.y) )
  294. pygame.draw.line(window,self.rgb, (self.x,self.y-p) , (self.x,self.y-2) )
  295. self.rgb = [0,200,0]
  296. pygame.draw.line(window,self.rgb, (self.x+2,self.y) , (self.x+p,self.y) )
  297. pygame.draw.line(window,self.rgb, (self.x,self.y+2) , (self.x,self.y+p) )
  298. self.rgb = [200,0,0]
  299. pointer = POINTER()
  300. NR = 0
  301. running = True
  302. def event():
  303. global NR,running
  304. for event in pygame.event.get():
  305. #print(event.dict)
  306. _button = None
  307. if "button" in event.dict:
  308. _button = event.dict["button"]
  309. _state = None
  310. if "state" in event.dict:
  311. _state = event.state
  312. _key = None
  313. if "key" in event.dict:
  314. _key = event.key
  315. _pos = None
  316. if "pos" in event.dict:
  317. _pos = event.pos
  318. _type = None
  319. if "type" in event.dict:
  320. _type = event.type
  321. _type = event.type
  322. _mod = None
  323. if "mod" in event.dict:
  324. _mod = event.mod
  325. print( " ")
  326. print( "{:.02f}".format( time.time() - START ))
  327. print("button -",_button,end="\t| ")
  328. #print("state -",_state)
  329. print("pos -",_pos)
  330. print("type -",_type, end="\t| ")
  331. print("key -",_key)
  332. print("mod -",_mod)
  333. try:
  334. if _type == 5:
  335. if _button == 1:
  336. NR += 1
  337. if NR > 1:
  338. NR = 0
  339. if _button == 3:
  340. NR -= 1
  341. if NR < 0:
  342. NR = 1
  343. if _pos:
  344. posA = _pos
  345. fix = find_pix(_pos[0]-40,_pos[1]-60)
  346. if fix:
  347. pos = fix.POS(40,60)
  348. rgb = [0,0,0]
  349. pointer.move(pos)
  350. pointer.fix = fix
  351. else:
  352. pointer.on = 0
  353. pointer.row_move(_pos[0],_pos[1])
  354. pointer.cross(_pos[0],_pos[1])
  355. if event.type == pygame.VIDEORESIZE:
  356. window = pygame.display.set_mode((event.w, event.h), pygame.RESIZABLE)
  357. except Exception as e:
  358. print(e)
  359. if event.type==pygame.QUIT:
  360. running=False
  361. fps = 0
  362. frame = 0
  363. frame_t = time.time()
  364. IP = "yyy"
  365. def draw_overlay():
  366. global fps
  367. fr = font.render("FPS:{}".format(fps) ,1, (200,0,255))
  368. window.blit(fr,(10,10))
  369. fr = font.render("ip:{}".format(IP) ,1, (200,0,255))
  370. window.blit(fr,(80,10))
  371. def calc_fps():
  372. global fps,frame,frame_t
  373. t = time.time()
  374. if frame_t+1 < t:
  375. fps = frame #frame_t- t #frame
  376. frame = 1
  377. frame_t = time.time()
  378. # ===== GUI =========
  379. #def draw_circle(surface, x, y, radius, color):
  380. def draw_circle(surface,color, pos, radius):
  381. x,y=pos
  382. pygame.gfxdraw.aacircle(surface, int(x), int(y), radius-1, color)
  383. pygame.gfxdraw.filled_circle(surface, int(x), int(y), radius-1, color)
  384. def rDMX(univ,dmx):
  385. return univ*512+dmx
  386. grid_file = "/tmp/vpu_grid.csv"
  387. grid_file = "/home/user/LibreLight/vpu_grid_hd.csv"
  388. def generate_grid():
  389. log = open(grid_file,"w")
  390. head = "i,univ,dmx,x,y,ch\n"
  391. head = "i,univ,dmx,ch\n"
  392. head = "univ,dmx,x,y,ch\n"
  393. head = "nr,id,info\n"
  394. print("csv:",head)
  395. log.write(head)
  396. dmx = 1-1
  397. ch = 4
  398. y=0
  399. x=0
  400. for i in range((_y)*(_x)):
  401. if x > _x and i%_x == 0:
  402. print("--> -->")
  403. x=0
  404. y+=1
  405. _univ = int(dmx/512)
  406. _dmx = dmx - (_univ)*512
  407. pos=[x,y]
  408. line="{},{},{},{},{},{}\n".format(i+1,_univ,_dmx+1,pos[0],pos[1],ch)
  409. line="{},{},{},{},{}\n".format(_univ,_dmx+1,x,y,ch)
  410. line="{},{},x\n".format(i+1,i+1)
  411. print("wcsv:",[line])
  412. log.write(line)
  413. dmx += ch
  414. x+=1
  415. log.close()
  416. return GRID
  417. def init_grid():
  418. try:
  419. log = open(grid_file,"r")
  420. except:
  421. generate_grid()
  422. log = open(grid_file,"r")
  423. lines = log.readlines()
  424. GRID = []
  425. y=0
  426. x=0
  427. print("CSV header",[lines[0]])
  428. for i,line in enumerate(lines[1:]): #exclude first line
  429. #print("rcsv",[line])
  430. line = line.strip()
  431. line = line.split(",") # csv
  432. if i >= _x and i%_x == 0:
  433. x=0
  434. y+=1
  435. if y >= _y:
  436. break
  437. #i = int(line[0])
  438. _id = int(line[1])
  439. #univ = int(line[0])
  440. #dmx = int(line[1])
  441. #x = int(line[3])
  442. #y = int(line[4])
  443. #ch = int(line[4])
  444. pos = [x,y]
  445. f = Fix(_id,pos,block) #pos,univ,dmx,ch)
  446. #f.x = x
  447. #f.y = y
  448. #f.block = block
  449. GRID.append(f)
  450. x+=1
  451. #print("y, _y",y,_y)
  452. return GRID
  453. def find_pix(x,y):
  454. global GRID
  455. for fix in GRID:
  456. X = 0
  457. Y = 0
  458. pos = fix.POS()
  459. if x > pos[0] and x < pos[0]+pos[2]:
  460. X = 1
  461. if y > pos[1] and y < pos[1]+pos[3]:
  462. Y = 1
  463. if X and Y:
  464. print(pos,x,y)
  465. print("find",X,Y)
  466. return fix
  467. GRID = []
  468. NR = 0
  469. START_UNIV=2
  470. if options.start_univ:
  471. try:
  472. START_UNIV=int(options.start_univ)
  473. except Exception as e:
  474. print("Exception START UNIV",e)
  475. gobo_ch=1
  476. if options.gobo_ch:
  477. try:
  478. gobo_ch=int(options.gobo_ch)
  479. except Exception as e:
  480. print("Exception gobo_ch",e)
  481. if gobo_ch <= 0:
  482. gobo_ch = 1
  483. def main():
  484. global IP,GRID,FUNC
  485. counter = time.time()
  486. GRID = init_grid() #init_gird()
  487. print("GRID LEN:",len(GRID))
  488. s=time.time()
  489. print("run")
  490. r = ""
  491. IP = "xx"
  492. while running:
  493. pygame.display.flip()
  494. event()
  495. window.fill((0,0,0))
  496. calc_fps()
  497. draw_overlay()
  498. ips = read_index()
  499. # ----
  500. ip = select_ip(ips,univ=1) # univ 1 gobo
  501. dataA = read_dmx(ip)
  502. # ----
  503. ip = select_ip(ips,univ=START_UNIV)
  504. IP = ip
  505. data = read_dmx(ip)
  506. ip = select_ip(ips,univ=START_UNIV+1)
  507. data3 = read_dmx(ip)
  508. data.extend(data3)
  509. ip = select_ip(ips,univ=START_UNIV+2)
  510. data3 = read_dmx(ip)
  511. data.extend(data3)
  512. ip = select_ip(ips,univ=START_UNIV+4)
  513. data3 = read_dmx(ip)
  514. data.extend(data3)
  515. #ip = select_ip(ips,univ=START_UNIV+5)
  516. #data3 = read_dmx(ip)
  517. #data.extend(data3)
  518. # GRID loop
  519. try:
  520. ddd = 1023 #univ 3 512
  521. FUNC = data[ddd]
  522. FUNC = dataA[gobo_ch-1]
  523. #print("FUNC", FUNC )#:ddd+512])
  524. #FUNC = 15
  525. except Exception as e:
  526. print("EXC FUNC",e)
  527. i = 0
  528. dmx = 1
  529. h = 1
  530. v = 1
  531. for fix in GRID:
  532. pos = fix.POS(40,60)
  533. rgb = fix.rgb
  534. if 1:
  535. # draw row/col grid number
  536. if fix.pos[0] == 0:
  537. fr = font12.render("{}".format(fix.pos[1]+1) ,1, (200,200,200))
  538. window.blit(fr,(10,pos[1]+3 ))
  539. if fix.pos[1] == 0:
  540. fr = font12.render("{}".format(fix.pos[0]+1) ,1, (200,200,200))
  541. window.blit(fr,(pos[0]+2,35 ))
  542. pygame.draw.rect(window,rgb,pos)
  543. # DRAW SUB-FIXTURE
  544. j = 0
  545. for subfix in fix.sub_fix:#calc(data):
  546. subfix.calc(data)
  547. #fix = subfix
  548. spos = subfix.POS(40,60)
  549. srgb = subfix.rgb
  550. #print(fix.dmx,rgb,pos)
  551. #pygame.draw.circle(window,rgb,(pos[0]+int(pos[2]/2),pos[1]+int(pos[3]/2)),int(pos[3]/2))
  552. #FUNC = 0
  553. if FUNC > 10 and FUNC <= 20: # big dot
  554. draw_circle(window,srgb,(spos[0]+int(spos[2]/2),spos[1]+int(spos[3]/2)),int(spos[3]/2))
  555. elif FUNC > 20 and FUNC <= 30:#small dot
  556. draw_circle(window,srgb,(spos[0]+int(spos[2]/2),spos[1]+int(spos[3]/2)),int(spos[3]/3.5))
  557. elif FUNC > 30 and FUNC <= 40:#donut
  558. draw_circle(window,srgb,(spos[0]+int(spos[2]/2),spos[1]+int(spos[3]/2)),int(spos[3]/2))
  559. draw_circle(window,[0,0,0],(spos[0]+int(spos[2]/2),spos[1]+int(spos[3]/2)),int(spos[3]/3.5))
  560. elif FUNC > 40 and FUNC <= 50: # rec with hole
  561. pygame.draw.rect(window,srgb,spos)
  562. draw_circle(window,[0,0,0],(spos[0]+int(spos[2]/2),spos[1]+int(spos[3]/2)),int(spos[3]/3.5))
  563. elif FUNC > 50 and FUNC <= 60: # rec with big hole
  564. pygame.draw.rect(window,srgb,spos)
  565. draw_circle(window,[0,0,0],(spos[0]+int(spos[2]/2),spos[1]+int(spos[3]/2)),int(spos[3]/2))
  566. elif FUNC > 60 and FUNC <= 70: # rec with donat
  567. pygame.draw.rect(window,srgb,spos)
  568. draw_circle(window,[0,0,0],(spos[0]+int(spos[2]/2),spos[1]+int(spos[3]/2)),int(spos[3]/2))
  569. draw_circle(window,srgb,(spos[0]+int(spos[2]/2),spos[1]+int(spos[3]/2)),int(spos[3]/3.5))
  570. elif FUNC > 70 and FUNC <= 80: # rec boarder
  571. pygame.draw.rect(window,srgb,[spos[0]+1,spos[1]+1,spos[2]-2,spos[3]-2])
  572. elif FUNC > 80 and FUNC <= 90: # rec big boarder
  573. pygame.draw.rect(window,srgb,[spos[0]+2,spos[1]+2,spos[2]-4,spos[3]-4])
  574. elif FUNC > 90 and FUNC <= 100: # rec thin line
  575. pygame.draw.rect(window,srgb,spos)
  576. pygame.draw.rect(window,[0,0,0],[spos[0]+1,spos[1]+1,spos[2]-2,spos[3]-2])
  577. elif FUNC > 100 and FUNC <= 110: # rec big line
  578. pygame.draw.rect(window,srgb,spos)
  579. pygame.draw.rect(window,[0,0,0],[spos[0]+2,spos[1]+2,spos[2]-4,spos[3]-4])
  580. elif FUNC > 110 and FUNC <= 120: # rec with dot
  581. pygame.draw.rect(window,srgb,spos)
  582. pygame.draw.rect(window,[0,0,0],[spos[0]+1,spos[1]+1,spos[2]-2,spos[3]-2])
  583. draw_circle(window,srgb,(spos[0]+int(spos[2]/2),spos[1]+int(spos[3]/2)),int(spos[3]/3.5))
  584. elif FUNC > 120 and FUNC <= 130: # rec inline
  585. pygame.draw.rect(window,srgb,[spos[0]+2,spos[1]+2,spos[2]-4,spos[3]-4])
  586. pygame.draw.rect(window,[0,0,0],[spos[0]+3,spos[1]+3,spos[2]-6,spos[3]-6])
  587. elif FUNC > 130 and FUNC <= 140: # 3 dot (heart)
  588. draw_circle(window,srgb,(spos[0]+int(spos[2]/2)+2,spos[1]+int(spos[3]/2)),int(spos[3]/3.5))
  589. draw_circle(window,srgb,(spos[0]+int(spos[2]/2)-2,spos[1]+int(spos[3]/2)),int(spos[3]/3.5))
  590. draw_circle(window,srgb,(spos[0]+int(spos[2]/2),spos[1]+int(spos[3]/2)+2),int(spos[3]/3.5))
  591. else:
  592. pygame.draw.rect(window,srgb,spos)
  593. # draw row/col grid number
  594. if subfix.pos[0] == 0:
  595. fr = font12.render("{}".format(v ) ,1, (200,200,200))
  596. window.blit(fr,(25,spos[1] ))
  597. v += 1
  598. if subfix.pos[1] == 0:
  599. fr = font12.render("{}".format(1) ,1, (200,200,200))
  600. fr = font12.render("{}".format(h ) ,1, (200,200,200))
  601. h+=1
  602. window.blit(fr,(spos[0],50 ))
  603. if p >= 40:
  604. if NR:
  605. #fr = font15.render("{:02}".format(j+1) ,1, (0,200,255))
  606. fr = font15.render("{:02}".format(subfix._id) ,1, (250,200,5))
  607. window.blit(fr,(spos[0]+2,spos[1]+10))
  608. j += 1
  609. i += 1
  610. # DRAW FIX NUMBER on TOP
  611. i=0
  612. for fix in GRID:
  613. pos = fix.POS(40,60)
  614. rgb = fix.rgb
  615. if NR:
  616. pygame.draw.rect(window,[0,0,0],[pos[0]+2,pos[1]+2,12,9])
  617. #if NR == 1:
  618. # fr = font15.render("{:02}".format(i+1) ,1, (200,0,255))
  619. # window.blit(fr,(pos[0]+2,pos[1]+2))
  620. #elif NR == 2:
  621. if NR:# == 2:
  622. if counter +5 < time.time():
  623. counter = time.time()
  624. try:
  625. GRID = init_grid() #init_gird()
  626. except Exception as e:
  627. print("Except: grid re init",e)
  628. if fix._id != i+1:
  629. fr = font15.render("{:02}".format(fix._id) ,1, (255,255,0))
  630. else:
  631. fr = font15.render("{:02}".format(fix._id) ,1, (100,100,255))
  632. window.blit(fr,(pos[0]+2,pos[1]+2))
  633. i += 1
  634. #color=window.get_at((70, 70))
  635. #print("pix",color)
  636. #surface.set_at((x, y), color)
  637. #from pygame import gfxdraw
  638. #gfxdraw.pixel(surface, x, y, color)
  639. pointer.draw()
  640. pygame.display.flip()
  641. pg.time.wait(30)
  642. if __name__ == "__main__":
  643. main()