Exemplo n.º 1
0
 def createEye(pos):
     eye = GOval(EYE_SIZE, EYE_SIZE)
     eye.setFilled(True)
     if pos == 'left':
         snowman.add(eye, L_EYE_X, EYE_Y)
     else:
         snowman.add(eye, R_EYE_X, EYE_Y)
Exemplo n.º 2
0
def ball():

    ball = GOval(GWINDOW_WIDTH//2 - (BALL_SIZE//2), 300, BALL_SIZE, BALL_SIZE)
    ball.setFilled(True)
    ball.setColor("black")
    
    gw.add(ball)
Exemplo n.º 3
0
def createSun(color):
    
    sun_radius = WINDOW_HEIGHT//5
    sun = GOval(WINDOW_WIDTH//2 - sun_radius, WINDOW_HEIGHT//2-sun_radius, 
                sun_radius*2, sun_radius*2)
    sun.setColor(color)
    sun.setFilled(True)
    
    return sun 
Exemplo n.º 4
0
def createFilledCircle(x, y, r, fill='black', border=None):
    circle = GOval(x - r, y - r, 2 * r, 2 * r)
    circle.setFilled(True)
    if border is None:
        circle.setColor(fill)
    else:
        circle.setColor(border)
        circle.setFillColor(fill)
    return circle
Exemplo n.º 5
0
 def __init__(self, name):
     """Creates a new node with the specified name."""
     GCompound.__init__(self)
     self._name = name
     r = ArpanetNode.SIZE / 2
     oval = GOval(-r, -r, 2 * r, 2 * r)
     oval.setFilled(True)
     self.add(oval)
     self._routingTable = None
     self._active = True
     self._neighbors = set()
Exemplo n.º 6
0
def createButton(s):# makes a button with the string s
    button=GCompound()
    buttonSize=75
    label=GLabel(s)
    label.setColor("white")
    label.setFont("8px 'Sans-Serif'")
    c=GOval(-(label.getWidth()+20)//2,-buttonSize//2,label.getWidth()+20,buttonSize)
    c.setFillColor("black")
    c.setFilled(True)
    button.add(c)
    button.add(label,-label.getWidth()//2,0)
    return button
Exemplo n.º 7
0
def DrawBangladeshFlag():
    
    gw = GWindow(WINDOW_WIDTH, WINDOW_HEIGHT)
    rect = GRect(0, 0, WINDOW_WIDTH, WINDOW_HEIGHT)
    rect.setFilled(True)
    rect.setColor("ForestGreen")
    gw.add(rect)
    

    circ = GOval(200, 100, 200, 200)
    circ.setFilled(True)
    circ.setColor("DarkRed")
    gw.add(circ)
Exemplo n.º 8
0
def background():

    gw = GWindow(GWINDOW_WIDTH, GWINDOW_HEIGHT)
    rect = GRect(-10, -10, 720, 520)
    rect.setColor("cyan")
    rect.setFilled(True)
    gw.add(rect)

    for i in range(8):
        arc = GOval(-100, 100 + 30 * i, 900, 500)
        arc.setFilled(True)
        arc.setColor(colors[i])
        gw.add(arc)
Exemplo n.º 9
0
def create_filled_circle(x, y, r, fill="Black", border=None):
    """
    Creates a circle of radius r centered at the point (x, y) with the
    specified fill color.  If border is specified, the border appears
    in that color.
    """
    circle = GOval(x - r, y - r, 2 * r, 2 * r)
    circle.setFilled(True)
    if border is None:
        circle.setColor(fill)
    else:
        circle.setColor(border)
        circle.setFillColor(fill)
    return circle
Exemplo n.º 10
0
 def __init__(self):
    GCompound.__init__(self)
    self.digit = ""
    outer = GOval(-20, -20, 40, 40)
    outer.setFilled(True)
    outer.setFillColor("red")
    outer.setColor("red")
    self.add(outer)
    outer = GOval(-16, -16, 32, 32)
    outer.setFilled(True)
    outer.setFillColor("white")
    outer.setColor("white")
    self.add(outer)
    strikethrough = GLine(15, -15, -15, 15)
    strikethrough.setLineWidth(6)
    strikethrough.setColor("red")
    self.add(strikethrough)
Exemplo n.º 11
0
        def step():
            nonlocal vx, vy, ball, bricks_hit, balls_left, x_text, y_text
            collider = getCollidingObject()
            if ball.getX() < 0 or ball.getX() > GWINDOW_WIDTH - BALL_SIZE:
                vx *= -1
            elif ball.getY() < 0:
                vy *= -1
            elif ball.getY() > GWINDOW_HEIGHT - BALL_SIZE:
                timer.stop()
                gw.remove(ball)
                balls_left -= 1
                if balls_left > 0:
                    ball = GOval((GWINDOW_WIDTH - BALL_SIZE) / 2,
                                 (GWINDOW_HEIGHT - BALL_SIZE) / 2, BALL_SIZE,
                                 BALL_SIZE)
                    ball.setFilled(True)
                    gw.add(ball)
                    gw.add(instruct)
                else:
                    msg = GLabel('You Lose.')
                    msg.setColor('red')
                    msg.setFont('bold 36px sans-serif')
                    x = (GWINDOW_WIDTH - msg.getWidth()) / 2
                    y = (GWINDOW_HEIGHT - msg.getHeight()) / 2
                    gw.add(msg, x, y)
            if collider == paddle:
                vy *= -1
            elif not (collider == paddle or collider == gw.getElementAt(
                    x_text, y_text)) and collider is not None:
                vy *= -1
                gw.remove(collider)
                bricks_hit += 1
                if bricks_hit == N_COLS * N_ROWS:
                    timer.stop()
                    msg = GLabel('You Win!')
                    msg.setColor('green')
                    msg.setFont('bold 36px sans-serif')
                    x = (GWINDOW_WIDTH - msg.getWidth()) / 2
                    y = (GWINDOW_HEIGHT - msg.getHeight()) / 2
                    gw.add(msg, x, y)
            ball.move(vx, vy)

            gw.remove(gw.getElementAt(x_text, y_text))
            lives = GLabel('Lives: ' + str(balls_left))
            gw.add(lives, x_text, y_text)
Exemplo n.º 12
0
def DrawMaldivesFlag():
    sun_radius = WINDOW_HEIGHT//5
    gw = GWindow(WINDOW_WIDTH, WINDOW_HEIGHT)
    
    gw.add(createBackground("Crimson"))
    
    rect = GRect(WINDOW_WIDTH//8, WINDOW_HEIGHT//8, 3*WINDOW_WIDTH//4, 3*WINDOW_HEIGHT//4)
    rect.setColor("darkgreen")
    rect.setFilled(True)
    gw.add(rect)
    
    gw.add(createSun("white"))
    
    circ=GOval(WINDOW_WIDTH//2 - (sun_radius-20), WINDOW_HEIGHT//2-(sun_radius), 
                sun_radius*2, sun_radius*2)
    circ.setColor("darkgreen")
    circ.setFilled(True)
    gw.add(circ)
Exemplo n.º 13
0
class Circle(GCompound):
    def __init__(self, diameter, color, filled=True):
        super().__init__()
        self.oval = GOval(-diameter // 2, -diameter // 2, diameter, diameter)
        self.oval.setFillColor(color)
        self.oval.setColor(color)
        self.oval.setFilled(filled)
        self.diameter = diameter
        self.add(self.oval)

    def set_color(self, color):
        self.oval.setColor(color)
        self.oval.setFillColor(color)

    def get_radius(self):
        return self.diameter / 2

    def get_center(self):
        return (self.getX(), self.getY())
Exemplo n.º 14
0
def filledCircle(x, y, diameter, color):
    circle = GOval(x, y, diameter, diameter)
    circle.setFilled(True)
    circle.setFillColor(color)
    return circle
Exemplo n.º 15
0
def createFilledCircle(x, y, r, color):
    circle = GOval(x - r, y - r, 2 * r, 2 * r)
    circle.setColor(color)
    circle.setFilled(True)
    return circle
Exemplo n.º 16
0
def DrawJapanFlag():
    gw = GWindow(WINDOW_WIDTH, WINDOW_HEIGHT)
    circ = GOval(200, 100, 200, 200)
    circ.setFilled(True)
    circ.setColor("DarkRed")
    gw.add(circ)
Exemplo n.º 17
0
def Breakout():
    """
	The main program for the Breakout game.
	"""
    def mousemoveAction(e):
        paddle_X = paddle.getX()
        dx = e.getX() - paddle_X
        if 0 <= dx + paddle_X <= GWINDOW_WIDTH - PADDLE_WIDTH:
            paddle.move(dx, 0)
        elif 0 > dx + paddle_X:
            paddle.setLocation(0, PADDLE_Y)
        else:
            paddle.setLocation(GWINDOW_WIDTH - PADDLE_WIDTH, PADDLE_Y)

    def AnimatedBall():
        def step():
            nonlocal vx, vy, ball, bricks_hit, balls_left, x_text, y_text
            collider = getCollidingObject()
            if ball.getX() < 0 or ball.getX() > GWINDOW_WIDTH - BALL_SIZE:
                vx *= -1
            elif ball.getY() < 0:
                vy *= -1
            elif ball.getY() > GWINDOW_HEIGHT - BALL_SIZE:
                timer.stop()
                gw.remove(ball)
                balls_left -= 1
                if balls_left > 0:
                    ball = GOval((GWINDOW_WIDTH - BALL_SIZE) / 2,
                                 (GWINDOW_HEIGHT - BALL_SIZE) / 2, BALL_SIZE,
                                 BALL_SIZE)
                    ball.setFilled(True)
                    gw.add(ball)
                    gw.add(instruct)
                else:
                    msg = GLabel('You Lose.')
                    msg.setColor('red')
                    msg.setFont('bold 36px sans-serif')
                    x = (GWINDOW_WIDTH - msg.getWidth()) / 2
                    y = (GWINDOW_HEIGHT - msg.getHeight()) / 2
                    gw.add(msg, x, y)
            if collider == paddle:
                vy *= -1
            elif not (collider == paddle or collider == gw.getElementAt(
                    x_text, y_text)) and collider is not None:
                vy *= -1
                gw.remove(collider)
                bricks_hit += 1
                if bricks_hit == N_COLS * N_ROWS:
                    timer.stop()
                    msg = GLabel('You Win!')
                    msg.setColor('green')
                    msg.setFont('bold 36px sans-serif')
                    x = (GWINDOW_WIDTH - msg.getWidth()) / 2
                    y = (GWINDOW_HEIGHT - msg.getHeight()) / 2
                    gw.add(msg, x, y)
            ball.move(vx, vy)

            gw.remove(gw.getElementAt(x_text, y_text))
            lives = GLabel('Lives: ' + str(balls_left))
            gw.add(lives, x_text, y_text)

        vx = random.choice([-1, 1]) * random.uniform(MIN_X_VELOCITY,
                                                     MAX_X_VELOCITY)
        vy = INITIAL_Y_VELOCITY
        x_text = 20
        y_text = GWINDOW_HEIGHT - 10
        timer = gw.createTimer(step, TIME_STEP)
        timer.setRepeats(True)
        timer.start()

    def clickAction(e):
        gw.remove(instruct)
        AnimatedBall()

    def getCollidingObject():
        loc = gw.getElementAt(ball.getX(), ball.getY())
        if loc is not None:
            return loc
        else:
            loc = gw.getElementAt(ball.getX() + BALL_SIZE, ball.getY())
            if loc is not None:
                return loc
            else:
                loc = gw.getElementAt(ball.getX(), ball.getY() + BALL_SIZE)
                if loc is not None:
                    return loc
                else:
                    loc = gw.getElementAt(ball.getX() + BALL_SIZE,
                                          ball.getY() + BALL_SIZE)
                    return loc

    random.seed()
    gw = GWindow(GWINDOW_WIDTH, GWINDOW_HEIGHT)

    colors = [
        'red', 'red', 'orange', 'orange', 'green', 'green', 'cyan', 'cyan',
        'blue', 'blue'
    ]
    for row in range(N_ROWS):
        for col in range(N_COLS):
            rect = GRect(
                ((GWINDOW_WIDTH -
                  ((N_COLS * (BRICK_WIDTH + BRICK_SEP)) - BRICK_SEP)) / 2) +
                (row * (BRICK_WIDTH + BRICK_SEP)),
                (TOP_FRACTION * GWINDOW_HEIGHT) +
                (col * (BRICK_HEIGHT + BRICK_SEP)), BRICK_WIDTH, BRICK_HEIGHT)
            rect.setFilled(True)
            rect.setColor(colors[col])
            gw.add(rect)

    paddle = GRect((GWINDOW_WIDTH - PADDLE_WIDTH) / 2, PADDLE_Y, PADDLE_WIDTH,
                   PADDLE_HEIGHT)
    paddle.setFilled(True)
    gw.add(paddle)
    gw.addEventListener('mousemove', mousemoveAction)

    ball = GOval((GWINDOW_WIDTH - BALL_SIZE) / 2,
                 (GWINDOW_HEIGHT - BALL_SIZE) / 2, BALL_SIZE, BALL_SIZE)
    ball.setFilled(True)
    gw.add(ball)
    gw.addEventListener('click', clickAction)

    instruct = GLabel('Click to Start!')
    instruct.setFont('bold 24px sans-serif')
    x_inst = (GWINDOW_WIDTH - instruct.getWidth()) / 2
    y_inst = ((GWINDOW_HEIGHT - instruct.getHeight()) / 2) + (3 * BALL_SIZE)
    gw.add(instruct, x_inst, y_inst)

    balls_left = N_BALLS
    bricks_hit = 0
Exemplo n.º 18
0
def rainbow():
    gw = GWindow(500, 250)
    rect = GRect(0, 0, 500, 250)
    rect.setColor('cyan')
    rect.setFilled(True)
    gw.add(rect)

    red = GOval(X, Y, W, H)
    red.setColor('Red')
    red.setFilled(True)

    orange = GOval(X, 2 * Y, W, H)
    orange.setColor('Orange')
    orange.setFilled(True)

    yellow = GOval(X, 3 * Y, W, H)
    yellow.setColor('Yellow')
    yellow.setFilled(True)

    green = GOval(X, 4 * Y, W, H)
    green.setColor('Green')
    green.setFilled(True)

    blue = GOval(X, 5 * Y, W, H)
    blue.setColor('blue')
    blue.setFilled(True)

    indigo = GOval(X, 6 * Y, W, H)
    indigo.setColor('indigo')
    indigo.setFilled(True)

    violet = GOval(X, 7 * Y, W, H)
    violet.setColor('violet')
    violet.setFilled(True)

    end = GOval(X, 8 * Y, W, H)
    end.setColor('cyan')
    end.setFilled(True)

    gw.add(red)
    gw.add(orange)
    gw.add(yellow)
    gw.add(green)
    gw.add(blue)
    gw.add(indigo)
    gw.add(violet)
    gw.add(end)