Advertisement
trishLEX

Untitled

Apr 21st, 2017
409
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Python 21.98 KB | None | 0 0
  1. import glfw
  2. from OpenGL.GL import *
  3. from math import atan
  4. from math import pi
  5.  
  6. ###need to fix situation when holes doesn't cross clip
  7.  
  8. class Vertex:
  9.     def __init__(self, point):
  10.         self.coords = point
  11.         #self.isHole = isHole
  12.         self.isIntersectionPoint = False
  13.         self.isEntry = False
  14.  
  15.         #self.numberOfHole = numberOfHole ###numbering holes starts with 1, 0 means simple outline, False means clip point
  16.         #self.isFinalInHole = False
  17.     def __len__(self):
  18.         return 1
  19.  
  20.  
  21. class Polygon:
  22.     isSbjReady = False
  23.     isHolesReady = False
  24.     listOfEntries = []
  25.     listOfExits = []
  26.     def __init__(self):
  27.         self.points = []
  28.         self.sizes = []
  29.         self.size = 0
  30.     def insert(self, x, i):
  31.         for j in x:
  32.             self.points[i].append(j)
  33.         self.sizes[i] += len(x)
  34.     def append(self, x):
  35.         self.points.append(x)
  36.         self.sizes.append(len(x))
  37.         self.size += 1
  38.     def isEmpty(self):
  39.         if self.size == 0 and self.points == [] and self.sizes == []:
  40.             return True
  41.         else:
  42.             return False
  43.  
  44. class Clip:
  45.     isClipReady = False
  46.     def __init__(self):
  47.         self.points = []
  48.         self.size = 0
  49.     def append(self, x):
  50.         self.points.append(x)
  51.         self.size += 1
  52.  
  53.     def isEmpty(self):
  54.         if self.size:
  55.             return False
  56.         else:
  57.             return True
  58.  
  59. class IntersectionShapes:
  60.     isIntersectionMade = False
  61.     def __init__(self):
  62.         self.points = []
  63.         self.sizes = []
  64.         self.size = 0
  65.     def insert(self, x, i):
  66.         for j in x:
  67.             self.points[i].append(j)
  68.         self.sizes[i] += len(x)
  69.     def append(self, x):
  70.         self.points.append(x)
  71.         self.sizes.append(len(x))
  72.         self.size += 1
  73.     def isEmpty(self):
  74.         if self.size == 0 and self.points == [] and self.sizes == []:
  75.             return True
  76.         else:
  77.             return False
  78.  
  79.  
  80. # global isCurrentHoleReady
  81. # isCurrentHoleReady = False
  82. global startPoint
  83. startPoint = False
  84. def mouseCallback(window, button, action, mods):
  85.     global startPoint
  86.     if button == glfw.MOUSE_BUTTON_1 and action:
  87.         mouse = glfw.get_cursor_pos(window)
  88.         mouse = [int(mouse[0]), 480 - int(mouse[1])]
  89.         p = Vertex(mouse)
  90.         if not polygon.isSbjReady and not polygon.isHolesReady and not clip.isClipReady:
  91.             if polygon.isEmpty():
  92.                 if not startPoint:
  93.                     startPoint = True
  94.                     polygon.append([p])
  95.             else:
  96.                 polygon.insert([p], 0)
  97.         #print("isSbjReady", polygon.isSbjReady, "isHolesReady", polygon.isHolesReady, "isClipReady", clip.isClipReady)
  98.         #print(polygon.size)
  99.         if polygon.isSbjReady and not polygon.isHolesReady and not clip.isClipReady:
  100.             if not startPoint:
  101.                 startPoint = True
  102.                 polygon.append([p])
  103.             else:
  104.                 polygon.insert([p], polygon.size - 1)
  105.         if polygon.isSbjReady and polygon.isHolesReady and not clip.isClipReady:
  106.             # if not startPoint:
  107.             #     startPoint = True
  108.             #     clip.append(p)
  109.             # else:
  110.             clip.append(p)
  111.         #print(polygon.size)
  112.         #print(polygon.sizes)
  113.         # for i in range(polygon.size):
  114.         #     for j in range(polygon.sizes[i]):
  115.         #         print(polygon.points[i][j].coords)
  116.  
  117.  
  118. def keyCallback(window, key, scancode, action, mods):
  119.     #global isCurrentHoleReady
  120.     global startPoint
  121.     if key == glfw.KEY_SPACE and action:
  122.         if not polygon.isSbjReady and not polygon.isHolesReady and not clip.isClipReady:
  123.             startPoint = False
  124.             polygon.isSbjReady = True
  125.             print("PRESS SPACE TO SKIP DRAWING HOLES")
  126.         elif polygon.isSbjReady and not polygon.isHolesReady and not clip.isClipReady:
  127.             #isCurrentHoleReady = True
  128.             startPoint = False
  129.             polygon.isHolesReady = True
  130.         elif polygon.isSbjReady and polygon.isHolesReady and not clip.isClipReady:
  131.             #startPoint = False
  132.             clip.isClipReady = True
  133.     if key == glfw.KEY_H and action:
  134.         polygon.isHolesReady = False
  135.     if key == glfw.KEY_ENTER and action:
  136.         makeIntersection()
  137.  
  138.  
  139. def isClipInside():
  140.     maxXofClip = -1
  141.     for i in range(clip.size):
  142.         if clip.points[i].coords[0] > maxXofClip:
  143.             maxXofClip = clip.points[i].coords[0]
  144.     maxXofSbj = -1
  145.     for i in range(polygon.sizes[0]):
  146.         if polygon.points[0][i].coords[0] > maxXofSbj:
  147.             maxXofSbj = polygon.points[0][i].coords[0]
  148.  
  149.     if maxXofClip > maxXofSbj:
  150.         return False
  151.     else:
  152.         return True
  153.  
  154.  
  155. def checkForEntry(point, points):
  156.     maxX = max([i.coords[0] for i in points])
  157.     minX = min([i.coords[0] for i in points])
  158.     maxY = max([i.coords[1] for i in points])
  159.     minY = min([i.coords[1] for i in points])
  160.  
  161.     if point.coords[0] > minX and point.coords[0] < maxX and point.coords[1] > minY and point.coords[1] < maxY:
  162.         return False
  163.     else:
  164.         return True
  165.  
  166.  
  167. def makeIntersection():
  168.     oldSizes = polygon.sizes
  169.     searchForIntersections()
  170.  
  171.     # if oldSizes == polygon.sizes:
  172.     #     if isClipInside():
  173.     #         intersectionShapes.points = [clip.points]
  174.     #         intersectionShapes.size = 1
  175.     #         intersectionShapes.sizes = [clip.size]
  176.     #     else:
  177.     #         intersectionShapes.points = polygon.points
  178.     #         intersectionShapes.sizes = polygon.sizes
  179.     #         intersectionShapes.size = polygon.size
  180.     # else:
  181.     entry = checkForEntry(polygon.points[0][0], clip.points)
  182.  
  183.     for i in range(polygon.size):
  184.         for j in range(polygon.sizes[i]):
  185.             if polygon.points[i][j].isIntersectionPoint:
  186.                 k = clip.points.index(polygon.points[i][j])
  187.                 polygon.points[i][j].isEntry = entry
  188.                 clip.points[k].isEntry = entry
  189.                 l = polygon.points[i][j]
  190.                 if entry:
  191.                     polygon.listOfEntries.append(l)
  192.                 else:
  193.                     polygon.listOfExits.append(l)
  194.                 entry = not entry
  195.  
  196.     print("list of entries", [i.coords for i in polygon.listOfEntries])
  197.     print("polygon coords", [i.coords for i in polygon.points[0]])
  198.     print("clip coords", [i.coords for i in clip.points])
  199.  
  200.     makeIntersectionShapes()
  201.  
  202.  
  203. def makeIntersectionShapes():
  204.     points = []
  205.     size = 0
  206.     goToListOfEntries = False
  207.     startPoint = False
  208.     polygon.listOfEntries.reverse()
  209.     while polygon.listOfEntries != []:
  210.         a = polygon.listOfEntries.pop() ###here may be some problems
  211.         if not startPoint:
  212.             startPoint = a
  213.         # for i in polygon.points:
  214.         #     for j in i:
  215.         #         if a == j:
  216.         #             points.append(a)
  217.         #             size += 1
  218.         #             for x in range(i.index(j), i.index(j) +len(i)):
  219.         #                 points.append(i[x % len(i)])
  220.         for i in range(polygon.size):
  221.             if goToListOfEntries:
  222.                 break
  223.             for j in range(polygon.sizes[i]):
  224.                 if goToListOfEntries:
  225.                     break
  226.                 if a == polygon.points[i][j]:
  227.                     points.append(a)
  228.                     print("points1", [r.coords for r in points])
  229.                     size += 1
  230.                     print("size =", size)
  231.                     for x in range(j + 1, j + polygon.sizes[i]):
  232.                         if goToListOfEntries:
  233.                             break
  234.                         p = polygon.points[i][x % polygon.sizes[i]]
  235.                         print("p", p.coords, "index =", x % polygon.sizes[i], "x =", x)
  236.                         if not p.isIntersectionPoint:
  237.                             points.append(p)
  238.                             size += 1
  239.                             print("points2", [r.coords for r in points])
  240.                             print("size =", size)
  241.                         else:
  242.                             print("GG WP")
  243.                             z = clip.points.index(p)
  244.                             points.append(p)
  245.                             size += 1
  246.                             print("points3", [r.coords for r in points])
  247.                             print("size =", size)
  248.                             print("p index in clip", z)
  249.                             for y in range(z + 1, z + clip.size):
  250.                                 point = clip.points[y % clip.size]
  251.                                 #size += 1
  252.                                 #print(point.coords, "isIntersection?", point.isIntersectionPoint)
  253.                                 if not point.isIntersectionPoint:
  254.                                     points.append(point)
  255.                                     size += 1
  256.                                     print("points4", [r.coords for r in points])
  257.                                     print("size =", size)
  258.                                 else:
  259.                                     goToListOfEntries = True
  260.                                     if point == startPoint:
  261.                                         intersectionShapes.points.append(points)
  262.                                         intersectionShapes.size += 1
  263.                                         intersectionShapes.sizes.append(size)
  264.                                         points = []
  265.                                         size = 0
  266.                                         startPoint = False
  267.                                     break
  268.         if goToListOfEntries:
  269.             goToListOfEntries = False
  270.  
  271.  
  272.  
  273.  
  274. def searchForIntersections():
  275.     newSbjPoints = []
  276.     newClipPoints = []
  277.  
  278.     newSbjSizes = []
  279.     newSbjSize = 0
  280.     newClipSize = 0
  281.  
  282.     for i in range(polygon.size):
  283.         points = []
  284.         size = 0
  285.         for k in range(polygon.sizes[i]):
  286.             points.append(polygon.points[i][k])
  287.             size += 1
  288.             intersectionPoints = []
  289.             intersectionPointsCount = 0
  290.             for j in range(clip.size):
  291.                 if clip.points[j] not in newClipPoints:
  292.                     newClipPoints.append(clip.points[j])
  293.                     newClipSize += 1
  294.                 I = intersectionFound([polygon.points[i][k].coords, polygon.points[i][(k + 1) % polygon.sizes[i]].coords], [clip.points[j].coords, clip.points[(j + 1) % clip.size].coords])
  295.                 if I:
  296.                     intersectionPointsCount += 1
  297.                     p = Vertex(I)
  298.                     p.isIntersectionPoint = True
  299.                     intersectionPoints.append(p)
  300.                     intersectionPointsCount += 1
  301.                     newClipPoints.append(p)
  302.                     newClipSize += 1
  303.             intersectionPoints = makeOrder(intersectionPoints, polygon.points[i][k], polygon.points[i][(k + 1) % polygon.sizes[i]])
  304.             if intersectionPoints != []:
  305.                 for l in intersectionPoints:
  306.                     points.append(l)
  307.                     size += 1
  308.         newSbjPoints.append(points)
  309.         newSbjSize += 1
  310.         newSbjSizes.append(size)
  311.  
  312.     #print(polygon.sizes)
  313.  
  314.     global center
  315.     center = findCenterOfMass(newClipPoints)
  316.     newClipPoints.sort(key=sort, reverse=True)
  317.     #newClipPoints = sortNew(newClipPoints)
  318.  
  319.     newClipSize = 0
  320.     newClipPoints = []
  321.  
  322.     for j in range(clip.size):
  323.         newClipPoints.append(clip.points[j])
  324.         newClipSize += 1
  325.         intersectionPoints = []
  326.         intersectionPointsCount = 0
  327.         for i in range(polygon.size):
  328.             for k in range(polygon.sizes[i]):
  329.                 I = intersectionFound([polygon.points[i][k].coords, polygon.points[i][(k + 1) % polygon.sizes[i]].coords], [clip.points[j].coords, clip.points[(j + 1) % clip.size].coords])
  330.                 if I:
  331.                     intersectionPointsCount += 1
  332.                     #p = Vertex(I)
  333.                     #p.isIntersectionPoint = True
  334.                     for m in newSbjPoints:
  335.                         for n in m:
  336.                             if I == n.coords:
  337.                                 p = n
  338.                     #print(p.coords)
  339.                     intersectionPoints.append(p)
  340.                     intersectionPointsCount += 1
  341.         intersectionPoints = makeOrder(intersectionPoints, clip.points[j], clip.points[(j + 1) % clip.size])
  342.         if intersectionPoints != []:
  343.             for l in intersectionPoints:
  344.                 newClipPoints.append(l)
  345.                 newClipSize += 1
  346.  
  347.  
  348.     polygon.points = newSbjPoints
  349.     polygon.sizes = newSbjSizes
  350.     polygon.size = newSbjSize
  351.  
  352.     clip.points = newClipPoints
  353.     clip.size = newClipSize
  354.  
  355.     #for i in polygon.points[0]:
  356.     #    print(i.coords)
  357.  
  358. # def sortNew(points):
  359. #     edges = []
  360. #     size = 0
  361. #     for i in points:
  362. #         if not i.isIntersectionPoint:
  363. #             edges.append(i)
  364. #             size += 1
  365. #     res = []
  366. #     for i in range(size):
  367. #         intersectionPoints = []
  368. #         sx = sign(edges[i].coords[0], edges[(i + 1) % size].coords[0])
  369. #         sy = sign(edges[i].coords[1], edges[(i + 1) % size].coords[1])
  370. #         for j in points:
  371. #             if j.isIntersectionPoint:
  372. #                 if sx > 0 and sy > 0:
  373. #                     if edges[i].coords[0] < j.coords[0] < edges[(i + 1) % size].coords[0] and edges[i].coords[1] < j.coords[1] < edges[(i + 1) % size].coords[1]:
  374. #                         intersectionPoints.append(j)
  375. #                 elif sx > 0 and sy < 0:
  376. #                     if edges[i].coords[0] < j.coords[0] < edges[(i + 1) % size].coords[0] and edges[i].coords[1] > j.coords[1] > edges[(i + 1) % size].coords[1]:
  377. #                         intersectionPoints.append(j)
  378. #                 elif sx < 0 and sy > 0:
  379. #                     if edges[i].coords[0] > j.coords[0] > edges[(i + 1) % size].coords[0] and edges[i].coords[1] < j.coords[1] < edges[(i + 1) % size].coords[1]:
  380. #                         intersectionPoints.append(j)
  381. #                 elif sx < 0 and sy < 0:
  382. #                     if edges[i].coords[0] > j.coords[0] > edges[(i + 1) % size].coords[0] and edges[i].coords[1] > j.coords[1] > edges[(i + 1) % size].coords[1]:
  383. #                         intersectionPoints.append(j)
  384. #                 # elif sx == 0 and sy > 0:
  385. #                 #     if edges[i].coords[0] == j.coords[0] == edges[(i + 1) % size].coords[0] and edges[i].coords[1] < j.coords[1] < edges[(i + 1) % size].coords[1]:
  386. #                 #         intersectionPoints.append(j)
  387. #                 # elif sx == 0 and sy < 0:
  388. #                 #     if edges[i].coords[0] == j.coords[0] == edges[(i + 1) % size].coords[0] and edges[i].coords[1] > j.coords[1] > edges[(i + 1) % size].coords[1]:
  389. #                 #         intersectionPoints.append(j)
  390. #                 # elif sx > 0 and sy == 0:
  391. #                 #     if edges[i].coords[0] < j.coords[0] < edges[(i + 1) % size].coords[0] and edges[i].coords[1] == j.coords[1] == edges[(i + 1) % size].coords[1]:
  392. #                 #         intersectionPoints.append(j)
  393. #                 # elif sx < 0 and sy == 0:
  394. #                 #     if edges[i].coords[0] > j.coords[0] > edges[(i + 1) % size].coords[0] and edges[i].coords[1] == j.coords[1] == edges[(i + 1) % size].coords[1]:
  395. #                 #         intersectionPoints.append(j)
  396. #
  397. #         intersectionPoints = makeOrder(intersectionPoints, edges[i], edges[(i + 1) % size])
  398. #         res.append(edges[i])
  399. #         for k in intersectionPoints:
  400. #             res.append(k)
  401. #     return res
  402.  
  403. def findCenterOfMass(points):
  404.     m = n = 0
  405.     count = 0
  406.     for i in points:
  407.         m += i.coords[0]
  408.         n += i.coords[1]
  409.         count += 1
  410.     return [m / count, n / count]
  411.  
  412. def sort(p):
  413.     point = [p.coords[0] - center[0], p.coords[1] - center[1]]
  414.     phi = atan(point[1] / point[0])
  415.     if point[0] < 0 and point[1] > 0 or point[0] < 0 and point[1] < 0:
  416.         phi += pi
  417.     if point[0] > 0 and point[1] < 0:
  418.         phi += 2 * pi
  419.     return phi
  420.  
  421.  
  422. def intersectionFound(edge1, edge2):
  423.     if checkForBelonging(edge1[0], edge2) or checkForBelonging(edge1[1], edge2) or checkForBelonging(edge2[0], edge1) or checkForBelonging(edge2[1], edge1):
  424.         #print("I'm here")
  425.         return False
  426.     #print("edge1 =", edge1, "edge2 =", edge2)
  427.     A = edge1[0]
  428.     C = edge2[0]
  429.     #print("A =", A, "C =", C)
  430.     c = [C[0] - A[0], C[1] - A[1]]
  431.     #print("c =", c)
  432.     b = [edge1[1][0] - edge1[0][0], edge1[1][1] - edge1[0][1]]
  433.     d = [edge2[1][0] - edge2[0][0], edge2[1][1] - edge2[0][1]]
  434.     #print("b =", b, "d =", d)
  435.     dVert = [-d[1], d[0]]
  436.     bVert = [-b[1], b[0]]
  437.     #print("dVert =", dVert)
  438.     m = dVert[0] * c[0] + dVert[1] * c[1]
  439.     n = dVert[0] * b[0] + dVert[1] * b[1]
  440.     #print("числитель:", m, "знаменатель:", n)
  441.     if n == 0:
  442.         return False
  443.     t = m / n
  444.     #print("t =", t)
  445.     q = bVert[0] * c[0] + bVert[1] * c[1]
  446.     u = q / n
  447.     #print("u =", u)
  448.     if t < 0 or t > 1 or u < 0 or u > 1:
  449.         return False
  450.     pr = [b[0] * t, b[1] * t]
  451.     #print("t * b =", pr)
  452.     I = [A[0] + pr[0], A[1] + pr[1]]
  453.     #print("I =", I)
  454.     return I
  455.  
  456.  
  457. def checkForBelonging(point, edge): ###edge = [[x1, y1], [x2, y2]]
  458.     # print("point =", point, "edge =", edge)
  459.     maxX = max(edge[0][0], edge[1][0])
  460.     minX = min(edge[0][0], edge[1][0])
  461.     maxY = max(edge[0][1], edge[1][1])
  462.     minY = min(edge[0][1], edge[1][1])
  463.  
  464.     if point[0] <= maxX and point[0] >= minX and point[1] <= maxY and point[1] >= minY:
  465.         if not ((point[0] - edge[0][0]) * (edge[1][1] - edge[0][1]) - (point[1] - edge[0][1]) * (
  466.             edge[1][0] - edge[0][0])):
  467.             return True
  468.         else:
  469.             return False
  470.     else:
  471.         return False
  472.  
  473.  
  474. def sign(a, b):
  475.     if a < b:
  476.         return 1
  477.     elif a == b:
  478.         return 0
  479.     else:
  480.         return -1
  481.  
  482.  
  483. def makeOrder(points, point1, point2):
  484.     intersectionPoints = points
  485.     # if point1.coords[0] < point2.coords[0]:
  486.     #     sx = 1
  487.     # elif point1.coords[0] == point2.coords[0]:
  488.     #     sx = 0
  489.     # else:
  490.     #     sx = -1
  491.     # if point1.coords[1] < point2.coords[1]:
  492.     #     sy = 1
  493.     # elif point1.coords[1] == point2.coords[1]:
  494.     #     sy = 0
  495.     # else:
  496.     #     sy = -1
  497.     sx = sign(point1.coords[0], point2.coords[0])
  498.     sy = sign(point1.coords[1], point2.coords[1])
  499.     if sx > 0:
  500.         intersectionPoints.sort(key=lambda x: x.coords[0])
  501.     elif sx < 0:
  502.         intersectionPoints.sort(key=lambda x: -x.coords[0])
  503.     else:
  504.         if sy > 0:
  505.             intersectionPoints.sort(key=lambda x: x.coords[1])
  506.         else:
  507.             intersectionPoints.sort(key=lambda x: -x.coords[1])
  508.     return intersectionPoints
  509.  
  510.  
  511. def background():
  512.     glClearColor(1.0, 1.0, 1.0, 1.0)
  513.     glClear(GL_COLOR_BUFFER_BIT)
  514.  
  515.  
  516. def chngCoordf(point):
  517.     width = 640
  518.     height = 480
  519.  
  520.     x = point[0] * 2 / width - 1
  521.     y = point[1] * 2 / height - 1
  522.  
  523.     return x, y
  524.  
  525.  
  526. def drawShape(points, pointsCount, color):
  527.     glBegin(GL_POLYGON)
  528.  
  529.     glColor3f(color[0], color[1], color[2])
  530.  
  531.     for i in range(pointsCount):
  532.         x, y = chngCoordf(points[i].coords)
  533.         glVertex(x, y)
  534.  
  535.     glEnd()
  536.  
  537.  
  538. def drawLines(points, count, color):
  539.     glBegin(GL_LINE_STRIP)
  540.     glColor3f(color[0], color[1], color[2])
  541.     for i in range(count):
  542.         x, y = chngCoordf(points[i].coords)
  543.         glVertex2f(x, y)
  544.     glEnd()
  545.  
  546. def drawLine(point1, point2, color):
  547.     x1, y1 = chngCoordf(point1.coords)
  548.     x2, y2 = chngCoordf(point2.coords)
  549.     glBegin(GL_LINES)
  550.  
  551.     glColor3f(color[0], color[1], color[2])
  552.     glVertex2f(x1, y1)
  553.     glVertex2f(x2, y2)
  554.  
  555.     glEnd()
  556.  
  557. def draw():
  558.     if not polygon.isEmpty():
  559.         if polygon.size == 1:
  560.             if polygon.isSbjReady:
  561.                 drawShape(polygon.points[0], polygon.sizes[0], [0.0, 0.0, 0.0])
  562.             else:
  563.                 drawLines(polygon.points[0], polygon.sizes[0], [0.0, 0.0, 0.0])
  564.         else:
  565.             drawShape(polygon.points[0], polygon.sizes[0], [0.0, 0.0, 0.0])
  566.             if polygon.isHolesReady:
  567.                 for i in range(1, polygon.size):
  568.                     drawShape(polygon.points[i], polygon.sizes[i], [1.0, 1.0, 1.0])
  569.             else:
  570.                 for i in range(1, polygon.size - 1):
  571.                     drawShape(polygon.points[i], polygon.sizes[i], [1.0, 1.0, 1.0])
  572.                 for i in range(polygon.size - 1, polygon.size):
  573.                     drawLines(polygon.points[i], polygon.sizes[i], [1.0, 1.0, 1.0])
  574.     if not clip.isEmpty():
  575.         if clip.isClipReady:
  576.             for i in range(clip.size):
  577.                 drawLine(clip.points[i], clip.points[(i + 1) % clip.size], [0, 0, 1.0])
  578.         else:
  579.             for i in range(clip.size):
  580.                 drawLines(clip.points, clip.size, [0.0, 0.0, 1.0])
  581.     if not intersectionShapes.isEmpty():
  582.         for i in range(intersectionShapes.size):
  583.             #print("shapes coords", [j.coords for j in intersectionShapes.points[i]])
  584.             #print("shape", [s.coords for s in intersectionShapes.points[i]], "sizes", intersectionShapes.sizes)
  585.             drawShape(intersectionShapes.points[i], intersectionShapes.sizes[i], [1.0, 0, 0])
  586.  
  587.  
  588. class Drawer:
  589.     window = False
  590.  
  591.     def __init__(self):
  592.         if not glfw.init():
  593.             return
  594.  
  595.         self.window = glfw.create_window(640, 480, "Lab5", None, None)
  596.         if not self.window:
  597.             glfw.terminate()
  598.             return
  599.  
  600.         glfw.make_context_current(self.window)
  601.  
  602.         glfw.set_mouse_button_callback(self.window, mouseCallback)
  603.         glfw.set_key_callback(self.window, keyCallback)
  604.         #glfw.set_window_size_callback(self.window, sizeCallback)
  605.  
  606.  
  607.     def startLoop(self):
  608.         while not glfw.window_should_close(self.window):
  609.             background()
  610.             draw()
  611.  
  612.             glfw.swap_buffers(self.window)
  613.             glfw.poll_events()
  614.  
  615.         glfw.terminate()
  616.  
  617. polygon = Polygon()
  618. clip = Clip()
  619. intersectionShapes = IntersectionShapes()
  620. drawer = Drawer()
  621. drawer.startLoop()
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement