def main(): global cell_x, cell_y, conta_x, conta_y game2d.canvas_init((canvas_x, canvas_y)) rosso = verde = blu = 0 colonne = int(input("Ok e quante colonne devo disegnare?")) righe = int(input("Quante righe devo disegnare?")) #Determino di quanto devo incrementare la posizione dei quadri e tolgo 1 px per il margine incremento_x = canvas_x // colonne incremento_y = canvas_y // righe #Incrementi usati per avere sempre il quadrato (0,255,0) in basso sx il quad(0,0,255) in alto a dx e il quad(0,255,255) incremento_blu = 255 // (colonne - 1) incremento_verde = 255 // (righe - 1) for conta_y in range(canvas_y // incremento_y): for conta_x in range(canvas_x // incremento_x): game2d.draw_rect((rosso, verde, blu), (cell_x, cell_y, incremento_x, incremento_y)) cell_x += incremento_x + 1 blu += incremento_blu conta_x += 1 cell_x = 0 conta_x = blu = 0 cell_y += incremento_y + 1 verde += incremento_verde conta_y += 1
def update(): DX = 5 DY = 5 global x global y game2d.canvas_fill((255, 255, 255)) game2d.draw_rect((0, 0, 255), (x, y, 100, 100)) if x < 1100: x += DX if y < 700: y += DY
def sierpiski(livello, x0, y0, w, h): ws = w // 2 hs = h // 2 if livello == 0 or ws == 0 or hs == 0: return for x in range(2): for y in range(2): xs = x0 + x * ws ys = y0 + y * hs if x == 1 and y == 0: game2d.draw_rect((255, 255, 255), (xs, ys, ws, hs)) else: sierpiski(livello - 1, xs, ys, ws, hs)
def update(): global dx global dy global x global y game2d.canvas_fill((255, 255, 255)) game2d.draw_rect((0,0,255),(x,y,SIDE,SIDE)) if ((x+dx)<0): x=0 elif((x+dx)>(WIDTH-SIDE)): x=(WIDTH-SIDE) else: x+=dx if ((y+dy)<0): y=0 elif ((y+dy)>(HEIGHT-SIDE)): y=(HEIGHT-SIDE) else: y+=dy
def draw_tile(color: (int, int, int), pos: (int, int)): x, y = pos g2d.draw_rect(color, (x * TILE, y * TILE, TILE - 1, TILE - 1))
#!/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 game2d as g2d grays = [] val = int(input('gray? ')) while 0 <= val < 256: grays.append(val) val = int(input('gray? ')) m = int(input('repetitions? ')) side = 400.0 delta = side / (len(grays) * m) g2d.init_canvas((int(side), int(side))) for i in range(m): for val in grays: g2d.draw_rect((val, val, val), (0, 0, int(side), int(side))) side -= delta g2d.main_loop()