Welcome, guest | Sign In | My Account | Store | Cart

EDITED: A small animated graphics demo in Tkinter, displaying a 1990's style Rotozoom, more interesting than the TV snow I posted previously. The Tkinter management part is just the same. The code is a little longer as some trig tables must be precalculated for speed. The window size corresponds to the resolution of the old DOS screen 13, as I originally coded the demo for Qbasic.

Python, 38 lines
 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
#rotozoom graphics raster demo Tkinter
#by Antoni Gual 

import tkinter
from math import sin,cos
from random  import randint
x,y=320,200 
  
class App:
    def __init__(self, t):
       self.img = tkinter.PhotoImage(width=x,height=y) 
       self.c = tkinter.Label(t,image=self.img);self.c.pack()
       t.after_idle(self.do_rotozoom)
       self.ang=0
       
    def do_rotozoom(self):
       self.ang=(self.ang+1)%100
       cs1=cs[self.ang]
       ss1=ss[self.ang]
       self.img.put((" ".join((("{"+" ".join(clr[((i*cs1-j*ss1) & (j*cs1+i*ss1))//256] 
          for i in range(-160,159)))+"}" for j in range(-100,99)))))
       t.after(20,self.do_rotozoom)     

#precalculate trig
cs,ss,ang=[],[],0
for i in range(100):
    aa=abs(sin(ang))*255
    cs.append(int(cos(ang)*aa))
    ss.append(int(sin(ang)*aa))
    ang+=0.062832
#precalculate a b/w color table   
clr=[]
for i in range(256):
    clr.append( "#{:06x}".format(i*0x10101))
    
t=tkinter.Tk()
a = App(t )
t.mainloop()