Example #1
0
 def __init__(self, num_sides, radius):
     GPolygon.__init__(self)
     dx = -radius
     dy = 0
     self.addVertex(dx, dy)
     da = 360 / num_sides
     edge = math.sin(da / 2 * math.pi / 180) * radius * 2
     angle = 0
     for i in range(num_sides):
         self.addPolarEdge(edge, angle)
         angle -= da
Example #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))
Example #3
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)
Example #4
0
    def __init__(self, nSides, radius):
        '''
		Creates a regular polygon with its reference point at the center.
		The nSides parameter indicates the number of sides and radius
		parameter indicates the distance from the reference point to any 
		vertex.
		'''
        GPolygon.__init__(self)
        edge = 2 * radius * math.sin((math.pi / nSides))
        d_ang = 360 / nSides
        self.addVertex(edge / 2, radius)
        angle = 180
        for i in range(nSides):
            self.addPolarEdge(edge, angle)
            angle -= d_ang
    def __init__(self, nSides, radius):
        """
        Initializes the Regular Polygon of the given perameters. The reference point is the center of the shape.
        """
        GPolygon.__init__(self)
        self.nSides = nSides
        self.radius = radius

        theta = radians(360 / self.nSides)
        interiorTheta = radians(((self.nSides - 2) * 180) / self.nSides)
        sideLen = 2 * self.radius * sin(theta / 2)
        self.addVertex(-sideLen / 2, self.radius * cos(theta / 2))

        newTheta = 0
        for i in range(self.nSides - 1):
            self.addPolarEdge(sideLen, degrees(newTheta))
            newTheta += (pi - interiorTheta)
def createHexagon(side):

    hex = GPolygon()
    hex.addVertex(-side, 0)
    angle = 60
    for i in range(6):
        hex.addPolarEdge(side, angle)
        angle -= 60
    return hex
def create_hexagon(side):
    """
    Creates a GPolygon representing a regular hexagon with the reference
    point at the center.
    """
    hex = GPolygon()
    hex.add_vertex(-side, 0)
    angle = 60
    for i in range(6):
        hex.add_polar_edge(side, angle)
        angle -= 60
    return hex
Example #8
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
Example #9
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 
Example #10
0
def drawTriangle(size):
    t = GPolygon()
    t.addVertex(0, -(size / (2 * sqrt(3))))
    t.addPolarEdge(size, 300)
    t.addPolarEdge(size, 180)
    return t
Example #11
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)
Example #12
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)
Example #13
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)