def ball(): ball = GOval(GWINDOW_WIDTH//2 - (BALL_SIZE//2), 300, BALL_SIZE, BALL_SIZE) ball.setFilled(True) ball.setColor("black") gw.add(ball)
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
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
def __init__(self, letter): GCompound.__init__(self) lamp = GOval(LAMP_RADIUS * 2, LAMP_RADIUS * 2) lamp.setColor(LAMP_BORDER_COLOR) lamp.setFillColor(LAMP_BGCOLOR) self.add(lamp, -LAMP_RADIUS, -LAMP_RADIUS) # create design for lamps self.ch = GLabel(letter) self.ch.setColor(LAMP_OFF_COLOR) self.ch.setFont(LAMP_FONT) self.add(self.ch, -self.ch.getWidth() / 2, LAMP_LABEL_DY)
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)
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)
def __init__(self, letter): GCompound.__init__(self) key = GOval(KEY_RADIUS * 2, KEY_RADIUS * 2) key.setLineWidth(KEY_BORDER) key.setColor(KEY_BORDER_COLOR) key.setFillColor(KEY_BGCOLOR) self.add(key, -KEY_RADIUS, -KEY_RADIUS) # create design for keys self.ch = GLabel(letter) self.ch.setColor(KEY_UP_COLOR) self.ch.setFont(KEY_FONT) self.add(self.ch, -self.ch.getWidth() / 2, KEY_LABEL_DY)
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
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)
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)
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())
def fireworks(): def step(): nonlocal dx, dy, dot, x, y, timer_2 if dot.getY() < y: timer.stop() timer_2.start() dot.move(dx, dy) def animateDot(): nonlocal current_size, desired_size if current_size < desired_size: current_size += DELTA_RADIUS x = dot.getX() - DELTA_RADIUS / 2 y = dot.getY() - DELTA_RADIUS / 2 dot.setBounds(x, y, current_size, current_size) random.seed() colors = ['red', 'orange', 'yellow', 'green', 'cyan', 'blue', 'violet'] gw = GWindow(GWINDOW_WIDTH, GWINDOW_HEIGHT) dot = GOval((GWINDOW_WIDTH - START_SIZE) / 2, GWINDOW_HEIGHT, START_SIZE, START_SIZE) dot.setColor(random.choice(colors)) gw.add(dot) y = random.uniform(0, GWINDOW_HEIGHT / 2) x = random.uniform(0, GWINDOW_WIDTH) dy = (y - dot.getY()) / FLIGHT_TIME dx = (x - dot.getX()) / FLIGHT_TIME current_size = START_SIZE desired_size = DELTA_RADIUS * EXPANSION_TIME timer = gw.createTimer(step, FLIGHT_TIME) timer.setRepeats(True) timer.start() timer_2 = gw.createTimer(animateDot, EXPANSION_TIME) timer_2.setRepeats(True)
def DrawJapanFlag(): gw = GWindow(WINDOW_WIDTH, WINDOW_HEIGHT) circ = GOval(200, 100, 200, 200) circ.setFilled(True) circ.setColor("DarkRed") gw.add(circ)
def createFilledCircle(x, y, r, color): circle = GOval(x - r, y - r, 2 * r, 2 * r) circle.setColor(color) circle.setFilled(True) return circle
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)