Advertisement
here2share

# Tk_basic_math_art.py

Sep 24th, 2021
1,159
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Python 0.79 KB | None | 0 0
  1. # Tk_basic_math_art.py
  2.  
  3. from Tkinter import *
  4. import random, time
  5. max = 1000
  6.  
  7. ww = 200
  8. hh = 300
  9. root = Tk()
  10. root.title("Tk basic math art")
  11. root.geometry("%dx%d+0+0"%(ww,hh))
  12.  
  13. sss = []
  14. COLORS = 'red orange yellow green blue purple'.split()
  15. fg = 'red orange blue purple black'.split()
  16. bg = 'yellow white gray90'.split()
  17.  
  18.  
  19. def rgb2hex(r,g,b):
  20.     return '#%02X%02X%02X'%(r,g,b)
  21.    
  22. def draw():
  23.     canvas.delete()
  24.    
  25.     colors = [random.choice(z) for z in (fg,bg)]
  26.     L = 2
  27.     t = c
  28.     clock = time.time()
  29.     for y in range(hh):
  30.         for x in range(ww):
  31.             t = (x+y+t)%(9+int(c+x/20.0))
  32.             canvas.create_rectangle((x,y,x,y), fill=colors[t%L], outline='')
  33.    
  34.     print time.time()-clock
  35.     canvas.update()
  36. 0
  37.  
  38. canvas = Canvas(root, width=ww, height=hh)
  39. canvas.pack()
  40. c = 1
  41. while 1:
  42.     c += 1
  43.     draw()
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement