def update_buttons(self): global solved 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 '#' not in value: center = x * W + W // 2, y * H + H // 2 if '!' in value: g2d.set_color((0, 0, 200)) g2d.fill_circle(center, 14) g2d.set_color((255, 255, 255)) g2d.fill_circle(center, 12) g2d.set_color((0, 0, 0)) g2d.draw_text_centered(value[:-1], center, H // 2) else: g2d.fill_rect((x * W, y * H, W, H)) g2d.update_canvas() if self._game.finished() and not solved: g2d.alert(self._game.message()) g2d.close_canvas()
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): g2d.set_color((0,0,0)) value = self._game.value_at(x, y) if self._game.checkblack(x,y): g2d.fill_rect((x * W, y * H, W, H)) center = x * W + W//2, y * H + H // 2 if self._game.checkcircle(x,y): g2d.fill_circle((center), W // 2) g2d.set_color((255,255,255)) g2d.fill_circle((center), W // 2 - 1) g2d.set_color((0,0,0)) g2d.draw_text_centered(value, center, H//2) g2d.update_canvas() if self._game.finished(): g2d.alert(self._game.message()) g2d.close_canvas()
def drawline(origin: int, size: int, gridsize: int, pos: int): """ Disegna una linea in base all origine, dimensione delle caselle e la riga/colonna date """ g2d.draw_line( (origin + size * pos, origin), (origin + size * pos, origin + size * gridsize)) # Linea verticale g2d.draw_line( (origin, origin + size * pos), (origin + size * gridsize, origin + size * pos)) # Linea orizzontale
def update_buttons(self): g2d.fill_canvas((255, 255, 255)) rows, cols = self._game.rows(), self._game.cols() for y in range(1, rows): g2d.draw_line((0, 0, 0), (0, y * H), (cols * W, y * H)) for x in range(1, cols): g2d.draw_line((0, 0, 0), (x * W, 0), (x * W, rows * H)) for y in range(rows): for x in range(cols): g2d.draw_text_centered(self._game.get_val(x, y), (0, 0, 0), (x * W + W // 2, y * H + H // 2), H // 2) g2d.update_canvas()
def htree(rect: (int, int, int, int), level: int): x, y, w, h = rect if level == 0 or w < 3 or h < 3: return if level % 2 == 0: rect1 = x, y, w / 2, h rect2 = x + w / 2, y, w / 2, h else: rect1 = x, y, w, h / 2 rect2 = x, y + h / 2, w, h / 2 g2d.draw_line(center(rect1), center(rect2)) htree(rect1, level - 1) htree(rect2, level - 1)
def htree(rect: (int, int, int, int), level: int): x, y, w, h = rect if level == 0 or w < 3 or h < 3: #terminazione return if level % 2 == 0: #livello pari dimezzo larghezza rect1 = x, y, w / 2, h #primo rettangolo sn rect2 = x + w / 2, y, w / 2, h #secondo rettangolo ds #print(level,'sn',rect1,'ds',rect2) #debug else: #livello dispari dimezzo altezza rect1 = x, y, w, h / 2 #alto rect2 = x, y + h / 2, w, h / 2 #basso #print(level,'up',rect1,'down',rect2) #debug g2d.draw_line(center(rect1), center(rect2)) htree(rect1, level - 1) htree(rect2, level - 1)
def update_buttons(self): g2d.clear_canvas() g2d.set_color((0, 0, 0)) rows, cols = self._game.rows(), self._game.cols() 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()
def update_buttons(self): g2d.clear_canvas() g2d.set_color((0, 0, 0)) rows, cols = self._game.rows(), self._game.cols() 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()
def update_buttons(self): g2d.fill_canvas((255, 255, 255)) rows, cols, flag = self._game.rows(), self._game.cols(), 0 cellevuote = 0 for y in range(1, rows): g2d.draw_line((0, 0, 0), (0, y * H), (cols * W, y * H)) for x in range(1, cols + 1): g2d.draw_line((0, 0, 0), (x * W, 0), (x * W, rows * H)) for y in range(rows): for x in range(cols): if (self._game.get_valpos(y, x) == 0): g2d.draw_text_centered(" ", (0, 0, 0), (x * W + W // 2, y * H + H // 2), H // 2) cellevuote = cellevuote + 1 elif (self._game.get_valpos(y, x) == 2): g2d.draw_image(flag1, (x * W + W // 8, y * H + H // 8)) #g2d.draw_text_centered("<|", (0, 0, 0),(x * W + W//2, y * H + H//2), H//2) flag = flag + 1 elif (self._game.get_val(y, x) == -1): g2d.draw_image(bomb, (x * W + W // 8, y * H + H // 8)) else: g2d.draw_text_centered(str(self._game.get_val(y, x)), (0, 0, 0), (x * W + W // 2, y * H + H // 2), H // 2) g2d.draw_text_centered("MINE RIMANENTI DA SEGNALARE", (0, 0, 0), ((x * W) + 160, H // 2), H // 2) g2d.draw_text_centered(str(self._game.mines() - flag), (0, 0, 0), ((x * W) + 160, H), H // 2) g2d.draw_text_centered("CELLE VUOTE RIMANENTI", (0, 0, 0), ((x * W) + 160, H * 2), H // 2) g2d.draw_text_centered(str((cellevuote + flag) - self._game.mines()), (0, 0, 0), ((x * W) + 160, H * 3), H // 2) g2d.update_canvas() if (self._game.finished() == True): g2d.alert(self._game.message()) g2d.exit() g2d.draw_text_centered(self._game.message(), (0, 0, 255), (cols * W // 2, rows * H // 2), H // 2)
#!/usr/bin/env python3 ''' @author Michele Tomaiuolo - http://www.ce.unipr.it/people/tomamic @license This software is free - http://www.gnu.org/licenses/gpl.html ''' import g2d from math import pi, sin, cos R = 200 g2d.init_canvas((2*R, 2*R)) g2d.set_color((0, 0, 0)) i, angle, r = 0, 0.0, R - 20 while i < 12: angle = i * 2 * pi / 12 pt1 = R + int(r*cos(angle)), R + int(r*sin(angle)) pt2 = R + int(R*cos(angle)), R + int(R*sin(angle)) g2d.draw_line(pt1, pt2) i += 1 i, angle, r = 0, 0.0, R - 5 while i < 60: angle = i * 2 * pi / 60 pt1 = R + int(r*cos(angle)), R + int(r*sin(angle)) pt2 = R + int(R*cos(angle)), R + int(R*sin(angle)) g2d.draw_line(pt1, pt2) i += 1 g2d.main_loop()
#!/usr/bin/env python3 ''' @author Michele Tomaiuolo - http://www.ce.unipr.it/people/tomamic @license This software is free - http://www.gnu.org/licenses/gpl.html ''' import g2d from math import pi, sin, cos R = 200 g2d.init_canvas((2 * R, 2 * R)) g2d.set_color((0, 0, 0)) i, angle, r = 0, 0.0, R - 20 while i < 12: angle = i * 2 * pi / 12 pt1 = R + int(r * cos(angle)), R + int(r * sin(angle)) pt2 = R + int(R * cos(angle)), R + int(R * sin(angle)) g2d.draw_line(pt1, pt2) i += 1 i, angle, r = 0, 0.0, R - 5 while i < 60: angle = i * 2 * pi / 60 pt1 = R + int(r * cos(angle)), R + int(r * sin(angle)) pt2 = R + int(R * cos(angle)), R + int(R * sin(angle)) g2d.draw_line(pt1, pt2) i += 1 g2d.main_loop()
centro = dim / 2 # centro dell'orologio r = 100 # raggio interno tacche l1 = 10 # lunghezza prime tacche l2 = 5 # lunghezza tacche minuti g2d.init_canvas((dim, dim)) g2d.set_color(colore) angolo = 0 while angolo < 360: # coordinate x = centro + r * sin(angolo * pi / 180) y = centro + r * cos(angolo * pi / 180) x2 = centro + (r + l1) * sin(angolo * pi / 180) y2 = centro + (r + l1) * cos(angolo * pi / 180) # disegno g2d.draw_line((x, y), (x2, y2)) angolo = angolo + 30 colore = 255, 0, 0 # colore seconde tacche g2d.set_color(colore) angolo = 0 while angolo < 360: # coordinate x = centro + r * sin(angolo * pi / 180) y = centro + r * cos(angolo * pi / 180) x2 = centro + (r + l2) * sin(angolo * pi / 180) y2 = centro + (r + l2) * cos(angolo * pi / 180) # disegno if angolo % 30 != 0: # non sovrascrive tacche precedenti g2d.draw_line((x, y), (x2, y2)) angolo = angolo + 6
#!/usr/bin/env python3 ''' @author Michele Tomaiuolo - http://www.ce.unipr.it/people/tomamic @license This software is free - http://www.gnu.org/licenses/gpl.html ''' import g2d g2d.init_canvas((600, 400)) # width, height g2d.set_color((255, 255, 0)) # red + green = yellow g2d.fill_rect((150, 100, 250, 200)) # left, top, width, height g2d.set_color((0, 255, 0)) g2d.draw_line((150, 100), (400, 300)) # point1, point2 g2d.set_color((0, 0, 255)) g2d.fill_circle((400, 300), 20) # center, radius g2d.set_color((255, 0, 0)) g2d.draw_text("Hello", (150, 100), 40) # text, left-top, font-size g2d.main_loop() # manage the window/canvas