def main():
    g2d.init_canvas((600, 600))
    g2d.set_color((255, 0, 0))

    koch_curve((0, 300), 600, 0)

    g2d.main_loop()
def main():
    width, height = 512, 512
    g2d.init_canvas((width, height))

    g2d.set_color((0, 0, 0))  #sfondo nero
    g2d.fill_rect((0, 0, width, height))
    g2d.set_color((255, 255, 255))

    sierp(0, 0, width, height)
    g2d.main_loop()
예제 #3
0
    def update_buttons(self):
        g2d.clear_canvas()
        g2d.set_color((0, 0, 0))
        cols, rows = self._game.cols(), self._game.rows()

        for y in range(1, rows):
            g2d.draw_line((0, y * H), (cols * W, y * H))
        for x in range(1, cols):
            g2d.draw_line((x * W, 0), (x * W, rows * H))

        for y in range(rows):
            for x in range(cols):
                value = self._game.value_at(x, y)
                if value == "":
                    g2d.set_color((204, 204, 204))
                elif value == "W":
                    g2d.set_color((255, 255, 255))
                elif value == "B":
                    g2d.set_color((0, 0, 0))
                g2d.fill_rect((x * W + 1, y * H + 1, W - 1, H - 1))
        g2d.update_canvas()

        if self._game.finished():
            g2d.alert(self._game.message())
            g2d.close_canvas()
예제 #4
0
 def update_buttons(self):
     g2d.clear_canvas()
     g2d.set_color((0, 0, 0))
     cols, rows = self._game.cols(), self._game.rows()
     for y in range(1, rows):
         g2d.draw_line((0, y * H), (cols * W, y * H))
     for x in range(1, cols):
         g2d.draw_line((x * W, 0), (x * W, rows * H))
     for y in range(rows):
         for x in range(cols):
             value = self._game.value_at(x, y)
             center = x * W + W // 2, y * H + H // 2
             g2d.draw_text_centered(value, center, H // 2)
     g2d.update_canvas()
     if self._game.finished():
         g2d.alert(self._game.message())
         g2d.close_canvas()
예제 #5
0
 def fill(self):
     g2d.set_color((99, 92, 92))
     g2d.fill_rect((self._x, self._y, self._w, self._h))
import g2d_pyg as g2d


def triangle(x, y, w, h, level):
    # caso base
    if level == 0 or w < 5 or h < 5:
        return

    w2 = w / 2
    h2 = h / 2

    # coloro solo il secondo quadrante
    g2d.fill_rect((x + w2, y, w2, h2))

    # applicazione della ricorsione su ogni quandrante rimanente
    triangle(x, y, w2, h2, level - 1)
    triangle(x, y + h2, w2, h2, level - 1)
    triangle(x + w2, y + h2, w2, h2, level - 1)


w, h = 512, 512  #uso una potenza di 2 per non avere degli errori grafici
level = 5
g2d.init_canvas((w, h))

g2d.set_color((0, 0, 0))
g2d.fill_rect((0, 0, w, h))

g2d.set_color((255, 255, 255))
triangle(0, 0, w, h, level)

g2d.main_loop()