Пример #1
0
def parallelVerticalLines(numLines, length, distanceBetween, color):
    #setFill(color)
    #aLine = zg.Line(zg.Point(10, 10), zg.Point(10, 10 + length))
    #aLine.draw(win)
    for x in range(numLines):
        aLine = zg.Line(zg.Point(10 + distanceBetween * x, 10),
                        zg.Point(10 + distanceBetween * x, 10 + length))
        aLine.setOutline(color)
        aLine.draw(win)
Пример #2
0
def drawBoard(row, column, windowSizeX, windowSizeY, PPS):
    global win
    win = zg.GraphWin("Name Jeff", windowSizeX, windowSizeY)

    for i in range(1, row):

        line = zg.Line(zg.Point(PPS * i, 0), zg.Point(PPS * i, windowSizeY))
        line.draw(win)

    for i in range(1, column):

        line = zg.Line(zg.Point(0, PPS * i), zg.Point(windowSizeX, PPS * i))
        line.draw(win)
    def __init__(self, centerPoint, width, height):

        x1 = centerPoint.getX() - width / 2
        y1 = centerPoint.getY() - height / 2
        x2 = centerPoint.getX() + width / 2
        y2 = centerPoint.getY() + height / 2

        p1 = zg.Point(x1, y1)
        p2 = zg.Point(x2, y2)

        zg.Rectangle.__init__(self, p1, p2)

        self._fill = None
        self._outline = 'black'
Пример #4
0
def winFound(winner):
    winner = winner.upper()
    print(winner, "WON!")
    winText = zg.Text(zg.Point(windowSizeX / 2, windowSizeY / 2),
                      winner + " WON!")
    winText.setSize(30)
    winText.setStyle("bold")
    winText.setTextColor("red")
    winText.draw(win)

    global hasWinner
    hasWinner = True
Пример #5
0
def wiggle():
    """
    Draws circles that start at the center of a graphics window.
    Each circle moves randomly ("wiggles")
    until it hits an edge of the window.
    """
    width = 400
    height = 300
    window = zg.GraphWin('Wiggles', width, height)

    center = zg.Point(width / 2, height / 2)
    radius = 20
    circle = zg.Circle(center, radius)
    circle.setFill('green')
    circle.draw(window)

    for k in range(500):
        delta_x = random.randrange(-12, 13)  # between -12 and 12
        delta_y = random.randrange(-5, 13)  # between -5 and 12

        circle.move(delta_x, delta_y)
        time.sleep(5 / (k + 5))  # units are seconds so starts at 1 sec

        x = circle.getCenter().x
        y = circle.getCenter().y
        if x < 0 or x > width or y < 0 or y > height:
            circle = zg.Circle(center, radius)  # A new circle
            color = zg.color_rgb(
                random.randrange(255),  # red
                random.randrange(255),  # green
                random.randrange(255))  # blue
            circle.setFill(color)
            circle.draw(window)

    message = 'Click the mouse anywhere in here to exit'
    message_box = zg.Text(zg.Point(width / 2, 20), message)
    message_box.draw(window)

    window.getMouse()
    window.close()
    def __init__(self, center, numberOfButtons, orientation, width, height,
                 win):
        '''
        auto arrangement is horizontal 
        center is center of first button
        '''
        x = center.getX()
        y = center.getY()

        self._numberOfButtons = numberOfButtons
        self._win = win
        self._reaction = None

        labels = [None, None, None, None, None]
        if orientation == 'horizontal':
            self._b1 = Button(center, width, height, labels[0], self._win)
            self._b2 = Button(zg.Point(x + width, y), width, height, labels[1],
                              self._win)
            self._b3 = Button(zg.Point(x + width * 2, y), width, height,
                              labels[2], self._win)
            self._b4 = Button(zg.Point(x + width * 3, y), width, height,
                              labels[3], self._win)
            self._b5 = Button(zg.Point(x + width * 4, y), width, height,
                              labels[4], self._win)

        elif orientation == 'vertical':
            self._b1 = Button(center, width, height, labels[0], self._win)
            self._b2 = Button(zg.Point(x, y + height), width, height,
                              labels[1], self._win)
            self._b3 = Button(zg.Point(x, y + height * 2), width, height,
                              labels[2], self._win)
            self._b4 = Button(zg.Point(x, y + height * 3), width, height,
                              labels[3], self._win)
            self._b5 = Button(zg.Point(x, y + height * 4), width, height,
                              labels[4], self._win)

        self._buttons = [self._b1, self._b2, self._b3, self._b4, self._b5]
Пример #7
0
def drawO(row, column):
    center = zg.Point((row * PPS) + (PPS / 2), (column * PPS) + (PPS / 2))
    zg.Circle(center, PPS / 2 - inset).draw(win)
Пример #8
0
def drawX(row, column):
    zg.Line(zg.Point((row * PPS) + inset, column * PPS + inset),
            zg.Point((row + 1) * PPS - inset,
                     (column + 1) * PPS - inset)).draw(win)
    zg.Line(zg.Point((row + 1) * PPS - inset, column * PPS + inset),
            zg.Point(row * PPS + inset, (column + 1) * PPS - inset)).draw(win)
Пример #9
0
# "lowerLeftPoint" and the largest, all-containing triangle has a width of "width". The pattern is similar to
# "tri2" and "tri3" except there are n layers of triangles within triangles.    When n is 1, it draws an equilateral
# triangle.  When n is 2, it draws a tri2 figure, etc.
# EXTRA CHALLENGES: Can you avoid writing functions like "tri4", "tri5", etc?
#                   Can you avoid calling tri2 and tri3?
def triN(n, lowerLeftPoint, width):
    pass


# This is the part that tests the various functions
# You should not change any of the code that comes after this comment.

parallelVerticalLines(10, 100, 20, 'blue')
parallelVerticalLines(5, 50, 17, 'red')

concentricCircles(12, zg.Point(200, 200), 10)
concentricCircles(5, zg.Point(350, 80), 8)

equilateralTriangle(zg.Point(20, 300), 100)
equilateralTriangle(zg.Point(520, 150), 50)

tri2(zg.Point(650, 350), 100)
tri3(zg.Point(600, 200), 150)

# wait for a mouse click
win.getMouse()

for i in range(1, 9):
    triN(i, zg.Point(150, 575), 600)
    time.sleep(1.5)
Пример #10
0
# Set ratios and draw boxes

y1 = height/20
y2 = y1 + height/13.3333333

for row in range(10):

    x1 = width/26.94736842105
    x2 = x1 + width/25.6

    y1 += height/13.3333333
    y2 += height/13.3333333

    for col in range(10):

        grid[row][col] = z.Rectangle(z.Point(x1, y1), z.Point(x2, y2))

        x1 += width/25.6
        x2 += width/25.6

for row in grid:
    for col in row:

        col.draw(win)

# Get click and subtract proper amount
while True:

    click = win.getMouse()

    x = click.getX()
    def __init__(self, p1, width):

        p2 = zg.Point(p1.getX() + width / 2, p1.getY() + width)
        p3 = zg.Point(p1.getX() - width / 2, p1.getY() + width)
        Triangle.__init__(self, p1, p2, p3)