#-------------------------------------------------------------------- # animat4.py - by C.Fin 3/2008 - For Python 2 #-------------------------------------------------------------------- import Tkinter from random import randint #--------------------------------------------------------------------- class Screensaver: def __init__ (self,canvas,numrighe): self.vx=[0]*4 self.vy=[0]*4 self.x=[0]*4 self.y=[0]*4 self.linea=[None]*4*numrighe self.lineapunt=0 self.max_linea_punt=numrighe-1 self.minx=2 self.miny=2 self.maxx=int(canvas["width"]) self.maxy=int(canvas["height"]) self.tela=canvas for p in xrange(4): self.vx[p]=randint(5,15) self.vy[p]=randint(5,10) self.x[p]=randint(self.minx,self.maxx) self.y[p]=randint(self.miny,self.maxy) for p in xrange(numrighe): for i in xrange(3): self.linea[i+p*4]=canvas.create_line( self.x[i],self.y[i],self.x[1+i],self.y[1+i], dash=1,width=1,fill="yellow") self.linea[3+p*4]=canvas.create_line( self.x[3],self.y[3],self.x[0],self.y[0], dash=1,width=1,fill="yellow") def disegna(self): for i in xrange(4): x2=self.x[i]+self.vx[i] y2=self.y[i]+self.vy[i] if x2>self.maxx: x2=self.maxx ; self.vx[i]=-randint(5,15) if y2>self.maxy: y2=self.maxy ; self.vy[i]=-randint(5,15) if x2self.max_linea_punt: self.lineapunt=0 #--------------------------------------------------------------------- class Applicazione: def __init__ (self): self.form1=Tkinter.Tk() self.form1.title("Animazione4") self.form1.resizable(0,0) self.canvas1=Tkinter.Canvas( self.form1, width=500,height=400, bg="black") self.canvas1.pack() self.screensaver=Screensaver(self.canvas1,30) self.animazione() def animazione(self): self.screensaver.disegna() self.canvas1.after(10, self.animazione) #--------------------------------------------------------------------- applicazione=Applicazione() applicazione.form1.mainloop()