#! /usr/bin/env python #------------------------------------------------------------------------------ # Orologio con scia in dissolvenza - By C.Fin 2013 - For Python2&3 #------------------------------------------------------------------------------ try: import Tkinter as tk except ImportError: import tkinter as tk import time import math #------------------------------------------------------------------------------ WID, HEI = 400, 400 # dimensioni finestra XC, YC = WID//2, HEI//2 # centro finestra RADIUS = WID / 2 * 0.85 # raggio effetto grafico POINTS = 15 # punti sulla scia RP = 5 # raggio dei punti FNT = ("Sans", 46, "") # font per l'orologio #------------------------------------------------------------------------------ class App: def __init__(self): self.form = tk.Tk() self.form.resizable(False, False) self.form.title("Orologio05 - By C.Fin 2012") x = (self.form.winfo_screenwidth() / 2) - (WID / 2) y = (self.form.winfo_screenheight() / 2) - (HEI / 2) self.form.geometry("%dx%d+%d+%d" % (WID, HEI, x, y)) self.canvas = tk.Canvas( self.form, highlightthickness=0, width=WID, height=HEI, bg="black") self.canvas.pack() self.deg = 0 # anglo di partenza self.lp, self.lp2 = [], [] # liste coordinate punti def draw(self): self.form.after(50, self.draw) rad = math.radians(self.deg) x = XC + RADIUS * math.cos(rad) y = YC + RADIUS * math.sin(rad) self.lp.append([x, y]) if len(self.lp) > POINTS: del self.lp[0] x = XC + RADIUS * math.cos(rad+math.pi) y = YC + RADIUS * math.sin(rad+math.pi) self.lp2.append([x, y]) if len(self.lp2) > POINTS: del self.lp2[0] self.canvas.delete("all") for i,p in enumerate(self.lp): x, y = p[0], p[1] c = "#0000%02X" % (float(i+1) / POINTS * 255) self.canvas.create_oval(x-RP, y-RP, x+RP, y+RP, fill=c) for i,p in enumerate(self.lp2): x, y = p[0], p[1] c = "#0000%02X" % (float(i+1) / POINTS * 255) self.canvas.create_oval(x-RP, y-RP, x+RP, y+RP, fill=c) hour = time.strftime("%H:%M:%S", time.localtime()) self.canvas.create_text(XC, YC, text=hour, fill="green", font=FNT) self.deg = (self.deg + 6) % 360 def start(self): self.draw() self.form.mainloop() #------------------------------------------------------------------------------ app = App() app.start()