コード例 #1
0
 def drawPlusEvent(self, event):
 
     if event.type == pygame.MOUSEBUTTONDOWN:
         
         for but in self._buttonList:
             if but.isInside(event.pos):
                 self._mode = but.textVar
                 return
         
         
         if event.button == 3:
             self._isPlus = False
             self._plusLine1 = None
             self._plusLine2 = None
             return
         
         if self._isPlus:
             
             self._lines.append(self._plusLine1)
             self._lines.append(self._plusLine2)
             self._lastAction.append(["Line", 1])
             self._lastAction.append(["Line", 1])
             self._isSaved = False
         
         
     if event.type == pygame.MOUSEMOTION:
         
         if event.pos[1] < self._h // 20 + (self._w + self._h) // 20:
             self._plusLine1 = None 
             self._plusLine2 = None
             self._isPlus = False
             return
         
         self._isPlus = True
         
         e = event.pos
         
         x1 = e[0] + 10
         y1 = e[1]
         x2 = e[0] - 10
         y2 = e[1]
         
         x3 = e[0]
         y3 = e[1] + 10
         x4 = e[0]
         y4 = e[1] - 10
         
         l1 = Line((x1, y1), (x2, y2))
         l2 = Line((x3, y3), (x4, y4))
         
         self._plusLine1 = l1 
         self._plusLine2 = l2
         
     if event.type == pygame.KEYDOWN:
         if pygame.key.get_pressed()[pygame.K_SPACE]:
             self._isPlust = False
             self._plusLine1 = None 
             self._plusLine2 = None
コード例 #2
0
    def getGraphics(self, plain, converter):
        wires = plain.findall("wire")
        polygons = plain.findall("polygon")
        texts = plain.findall("text")
        circles = plain.findall("circle")

        for wire in wires:
            self.plain.append(Line(wire, converter))
        for polygon in polygons:
            self.plain.append(Polyline(polygon, converter))
        for text in texts:
            self.plain.append(Text(text, converter))
        for circle in circles:
            self.plain.append(Circle(circle, converter))
コード例 #3
0
 def drawContEvent(self, event):
 
     if event.type == pygame.MOUSEBUTTONDOWN:
         
         for but in self._buttonList:
             if but.isInside(event.pos):
                 self._mode = but.textVar
                 return
             
             
         if event.button == 3:
             self._isP1 = False
             self._isP2 = False
             
             self._firstPos = None
             self._secondPos = None
             
             return
         
         if not self._isP1:
             self._firstPos = event.pos
             self._isP1 = True
         else:
             k = Line(self._firstPos, self._secondPos)
             self._lines.append(k)
             self._lastAction.append(["Line", 1])
             self._isSaved = False
             
             self._isP2 = False
             
             self._firstPos = self._secondPos
             self._secondPos = None
         
     if event.type == pygame.MOUSEMOTION and self._isP1:
         self._secondPos = event.pos
         self._isP2 = True
         
     if event.type == pygame.KEYDOWN:
         if pygame.key.get_pressed()[pygame.K_SPACE]:
             self._firstPos = None
             self._secondPos = None
             
             self._isP1 = False
             self._isP2 = False
コード例 #4
0
    def createHexLines(self):
        
        if not self._isHex: return 

        c = list(self._centerHex)
        
        k1 = (self._w + self._h) // 20
        k2 = k1 / 2
        
        pos1 = (c[0] - k1, c[1] + k2)
        pos2 = (c[0], c[1] + k1)
        pos3 = (c[0] + k1, c[1] + k2)
        pos4 = (c[0] + k1, c[1] - k2)
        pos5 = (c[0], c[1] - k1)
        pos6 = (c[0] - k1, c[1] - k2)
        
        k1 = Line(pos1, pos2)
        k2 = Line(pos2, pos3)
        k3 = Line(pos3, pos4)
        k4 = Line(pos4, pos5)
        k5 = Line(pos5, pos6)
        k6 = Line(pos6, pos1)
        
        return [k1, k2, k3, k4, k5, k6]
コード例 #5
0
ファイル: test_shapes.py プロジェクト: zf6578/RTree
 def test_shape_union(self):
     shape_1 = Circle(np.array([1, 1]), 1)
     shape_2 = Line(np.array([-2, -2]), np.array([-1, -1]))
     shape_union = ShapeUnion(shape_1, shape_2)
     self.assertEqual(shape_union.bounding_box, None)
コード例 #6
0
ファイル: test_shapes.py プロジェクト: zf6578/RTree
 def test_Line(self):
     line_bb = Line(np.array([0, 0]), np.array([1, 1])).bounding_box
     self.assertEqual(line_bb.xlower, 0)
     self.assertEqual(line_bb.yupper, 1)
コード例 #7
0
import matplotlib.pyplot as plt
import numpy as np
from Shapes import Point, Arc, Circle, Grid, Line, RotationMatrix


plt.figure()
plt.clf()			

pt0 = Point(0, 0)
pt1 = Point(1, 1)
pt2 = Point(2, 0)
pt0.plot()
pt1.plot()
pt2.plot()

arc = Arc(pt0, 1, 0, 2*np.pi)
arc.plot(arrow='->')

Line(pt0, pt1).plot(arrow='<->')
Line(pt0, pt2).plot(arrow='->')

circle = Circle(pt0, 2)
circle.plot()
plt.axis('equal')


grid = Grid(pt0, pt1, 5)
#grid.plot(color='k', lw=1)

plt.show()
コード例 #8
0
 def drawDoubleArrowEvent(self, event):
 
     if event.type == pygame.MOUSEBUTTONDOWN:
         
         if event.button == 3:
             self._isP1 = False
             self._isP2 = False
             
             self._firstPos = None
             self._secondPos = None
             
             return
         
         for but in self._buttonList:
             if but.isInside(event.pos):
                 self._mode = but.textVar
                 return
         
         if not self._isP1:
             self._firstPos = event.pos
             self._isP1 = True
         else:
             k = Line(self._firstPos, self._secondPos)
             
             
             x1 = self._firstPos[0]
             x2 = self._secondPos[0]
             
         
             pos1, pos2 = self.getArowPos(x1, x2)
             pos3, pos4 = self.getArowPos(x2, x1)
             
             k1 = Line(self._secondPos, pos1)
             k2 = Line(self._secondPos, pos2)
             
             k3 = Line(self._firstPos, pos3)
             k4 = Line(self._firstPos, pos4)
             
             self._lines.append(k)
             self._lastAction.append(["Line", 1])
             self._lines.append(k1)
             self._lastAction.append(["Line", 1])
             self._lines.append(k2)
             self._lastAction.append(["Line", 1])
             self._lines.append(k3)
             self._lastAction.append(["Line", 1])
             self._lines.append(k4)
             self._lastAction.append(["Line", 1])
             
             self._isSaved = False
             
             
             self._isP1 = False
             self._isP2 = False
             
             self._firstPos = None
             self._secondPos = None
         
     if event.type == pygame.MOUSEMOTION and self._isP1:
         
         sP = list(event.pos)
         sP[1] = self._firstPos[1]
         
         e = list(event.pos)
         e[1] = self._firstPos[1]
         
         self._secondPos = tuple(e)
         self._isP2 = True
コード例 #9
0
 def drawArrowEvent(self, event):
 
     if event.type == pygame.MOUSEBUTTONDOWN:
         
         if event.button == 3:
             self._isP1 = False
             self._isP2 = False
             
             self._firstPos = None
             self._secondPos = None
             
             return
         
         for but in self._buttonList:
             if but.isInside(event.pos):
                 self._mode = but.textVar
                 return
         
         if not self._isP1:
             self._firstPos = event.pos
             self._isP1 = True
         else:
             k = Line(self._firstPos, self._secondPos)
             
             
             x1 = self._firstPos[0]
             x2 = self._secondPos[0]
             
             if x1 < x2:
                 x3 = x2 - self._w // 50
                 y3 = self._secondPos[1] + 10
                 x4 = x2 - self._w // 50
                 y4 = self._secondPos[1] - 10
             
             else:
                 x3 = x2 + self._w // 50
                 y3 = self._secondPos[1] - 10
                 x4 = x2 + self._w // 50
                 y4 = self._secondPos[1] + 10
             pos1, pos2 = (x3, y3), (x4, y4)
             
             k1 = Line(self._secondPos, pos1)
             k2 = Line(self._secondPos, pos2)
             
             self._lines.append(k)
             self._lastAction.append(["Line", 1])
             self._lines.append(k1)
             self._lastAction.append(["Line", 1])
             self._lines.append(k2)
             self._lastAction.append(["Line", 1])
             
             self._isSaved = False
             
             
             self._isP1 = False
             self._isP2 = False
             
             self._firstPos = None
             self._secondPos = None
         
     if event.type == pygame.MOUSEMOTION and self._isP1:
         
         sP = list(event.pos)
         sP[1] = self._firstPos[1]
         
         e = list(event.pos)
         e[1] = self._firstPos[1]
         
         self._secondPos = tuple(e)
         self._isP2 = True
コード例 #10
0
shader = compileProgram(compileShader(vertex_src, GL_VERTEX_SHADER), compileShader(fragment_src, GL_FRAGMENT_SHADER))
model_loc = glGetUniformLocation(shader, "model")
proj_loc = glGetUniformLocation(shader, "projection")
view_loc = glGetUniformLocation(shader, "view")
switcher_loc = glGetUniformLocation(shader, "switcher")

textures = glGenTextures(2)

cube_texture = load_texture("/home/melvin/Documents/Python/OpenGL/Attila/textures/crate.jpg", textures[0])
quad_texture = load_texture("/home/melvin/Documents/Python/OpenGL/Attila/textures/brick.jpg", textures[1])

################
my_cube = Cube(cube_vertices, cube_indices, 0, 1, 12, model_loc, textures[0])
my_cube.move(1, 0, 0)
################
my_ground = Line(ground_vertices, ground_indices, 0, 2, 12, model_loc)
################

glUseProgram(shader)
glClearColor(0.2, 0.2, 0.2, 1)
glEnable(GL_DEPTH_TEST)
glEnable(GL_BLEND)
glBlendFunc(GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA)

projection = pyrr.matrix44.create_perspective_projection_matrix(45, 1280/720, 0.1, 100)

# eye, target, up
view = pyrr.matrix44.create_look_at(pyrr.Vector3([0, 2, 5]), pyrr.Vector3([0, 0, 0]), pyrr.Vector3([0, 1, 0]))

glUniformMatrix4fv(proj_loc, 1, GL_FALSE, projection)
glUniformMatrix4fv(view_loc, 1, GL_FALSE, view)
コード例 #11
0
    def load(self):

        Filename = 'save'

        try:
            File = open(Filename, 'r')
        except IOError:
            open(Filename, 'w').close()
            File = open(Filename, 'r')

        while True:

            name = ""
            keys = []
            lines = []
            text = []

            line = File.readline()
            if not line: break

            name = line[:-1]

            line = File.readline()
            if not line: break
            nrK = int(line)

            for i in range(nrK):
                line = File.readline()
                if not line: break
                key = line[:-1]
                keys.append(key)

            line = File.readline()
            if not line: break
            nrs = line.split('|')
            nrL = int(nrs[0])
            nrT = int(nrs[1])

            for i in range(nrL):
                line = File.readline()
                if not line: break

                ls = line.split('|')
                pos1 = (float(ls[0]), float(ls[1]))
                pos2 = (float(ls[2]), float(ls[3]))
                l = Line(pos1, pos2)
                lines.append(l)

            for i in range(nrT):
                line = File.readline()
                if not line: break

                ls = line.split('|')
                pos1 = (float(ls[0]), float(ls[1]))
                string = ls[2][:-1]
                t = TextBox(pos1, string)
                text.append(t)

            line = File.readline()
            if not line: break

            cDate = line[:-1]

            f = Formula(name, lines, text, keys, cDate=cDate)
            self._repo.append(f)