def createHexagon(side):

    hex = GPolygon()
    hex.addVertex(-side, 0)
    angle = 60
    for i in range(6):
        hex.addPolarEdge(side, angle)
        angle -= 60
    return hex
Пример #2
0
def drawTriangle(edge, dx, dy, whole):

    tri = GPolygon()
    x = -edge / 2
    y = edge / (2 * math.sqrt(3))
    print(x, y)
    tri.addVertex(x, y)
    tri.addPolarEdge(edge, 0)
    tri.addPolarEdge(edge, 120)
    tri.addPolarEdge(edge, -120)
    whole.add(tri, dx - edge / 2, dy - edge * (math.sqrt(3) / 2))
Пример #3
0
def createHexagon(side):
    """
    Creates a GCompound representing a regular hexagon with the specified
    side length.  The reference point is the center.
    """
    hex = GPolygon()
    hex.addVertex(-side, 0)
    angle = 60
    for i in range(6):
        hex.addPolarEdge(side, angle)
        angle -= 60
    return hex
Пример #4
0
def drawDiamond(height,theta,color,diamondAngle):  #draws diamond of given height and color, with its' right edge on line with angle theta
    l=((.5*height)*cos((radians(.5*diamondAngle))))
    diamond=GPolygon()
    t=theta+diamondAngle
    diamond.addVertex(0,0)
    diamond.addPolarEdge(l,t)
    t=t-diamondAngle
    diamond.addPolarEdge(l,t)
    t=t-(180-diamondAngle)
    diamond.addPolarEdge(l,t)
    diamond.setFillColor(color)
    diamond.setFilled(True)
    return diamond 
Пример #5
0
def drawTriangle(edge, x, y, whole):

    tri = GPolygon()
    tri.addVertex(x, y)
    tri.addVertex(x + edge, y)
    tri.addVertex(x + edge / 2, y - edge * math.sqrt(3) / 2)
    whole.add(tri)
Пример #6
0
 def __init__(self, color, level, puzzle):
     """Creates a piece with the indicated color and initial level"""
     GCompound.__init__(self)
     self._level = level
     self._puzzle = puzzle
     self.setColor(color)
     frame = GRect(PIECE_WIDTH, PIECE_HEIGHT)
     frame.setFilled(True)
     frame.setColor(PIECE_COLOR)
     self.add(frame, -PIECE_WIDTH / 2, 0)
     poly = GPolygon()
     dw = PIECE_WIDTH / puzzle.getNLevels()
     w0 = (level - 1) * dw
     w1 = level * dw
     poly.addVertex(-w0 / 2, 0)
     poly.addVertex(w0 / 2, 0)
     poly.addVertex(w1 / 2, PIECE_HEIGHT)
     poly.addVertex(-w1 / 2, PIECE_HEIGHT)
     poly.setFilled(True)
     poly.setColor(color)
     self.add(poly)
     border = GRect(PIECE_WIDTH, PIECE_HEIGHT)
     border.setColor(BORDER_COLOR)
     self.add(border, -PIECE_WIDTH / 2, 0)
Пример #7
0
def drawTriangle(size):
    t = GPolygon()
    t.addVertex(0, -(size / (2 * sqrt(3))))
    t.addPolarEdge(size, 300)
    t.addPolarEdge(size, 180)
    return t
Пример #8
0
 def createNose():
     nose = GPolygon()
     nose.addVertex(0, NOSE_TIP)
     nose.addEdge(NOSE_WIDTH * -.5, NOSE_HEIGHT)
     nose.addEdge(NOSE_WIDTH, 0)
     snowman.add(nose)
Пример #9
0
 def _createBackground(self):
     frame = GRect(0, 0, self._frameWidth, self._frameHeight)
     frame.setFilled(True)
     frame.setColor(FRAME_COLOR)
     self.add(frame)
     x1 = self._frameWidth / 2
     x0 = x1 - PIECE_WIDTH - COLUMN_SEP
     x2 = x1 + PIECE_WIDTH + COLUMN_SEP
     y0 = TOP_MARGIN + PIECE_HEIGHT / 2
     y1 = self._frameHeight - BOTTOM_MARGIN - PIECE_HEIGHT / 2
     h = CHANNEL_WIDTH / 2
     poly = GPolygon()
     poly.addVertex(x0 - h, y1 + h)
     poly.addVertex(x0 - h, y0 - h)
     poly.addVertex(x2 + h, y0 - h)
     poly.addVertex(x2 + h, y1 + h)
     poly.addVertex(x2 - h, y1 + h)
     poly.addVertex(x2 - h, y0 + h)
     poly.addVertex(x1 + h, y0 + h)
     poly.addVertex(x1 + h, y1 + h)
     poly.addVertex(x1 - h, y1 + h)
     poly.addVertex(x1 - h, y0 + h)
     poly.addVertex(x0 + h, y0 + h)
     poly.addVertex(x0 + h, y1 + h)
     poly.addVertex(x0 - h, y1 + h)
     poly.setFilled(True)
     poly.setColor(CHANNEL_COLOR)
     self.add(poly)