import tkinter as tk
import random
def desenhar_vela(canvas, x, y, largura, altura):
canvas.create_rectangle(x, y, x + largura, y + altura, fill="white", outline="black")
return x + largura / 2, y
def piscar_chama(canvas, cx, cy):
canvas.delete("chama")
tamanho_x = random.randint(5, 10)
tamanho_y = random.randint(10, 20)
cor = random.choice(["yellow", "gold", "orange"])
canvas.create_oval(cx - tamanho_x, cy - tamanho_y, cx + tamanho_x, cy, fill=cor, outline="orange", tag="chama")
canvas.after(200, piscar_chama, canvas, cx, cy)
root = tk.Tk()
root.title("Vela com Chama Piscando")
canvas = tk.Canvas(root, width=200, height=300, bg="skyblue")
canvas.pack()
cx, cy = desenhar_vela(canvas, 80, 150, 40, 100)
piscar_chama(canvas, cx, cy)
root.mainloop()
Comentários
Enviar um comentário