here2share

# Tk_basic_math_art_2.py

Sep 24th, 2021
780
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. # Tk_basic_math_art_2.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 2")
  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.             p = int(c+x/20.0)
  32.             p = p+1 if p%2 else p
  33.             t = (x+y+t)%(9+p)
  34.             canvas.create_rectangle((x,y,x,y), fill=colors[t%L], outline='')
  35.    
  36.     print time.time()-clock
  37.     canvas.update()
  38. 0
  39.  
  40. canvas = Canvas(root, width=ww, height=hh)
  41. canvas.pack()
  42. c = 1
  43. while 1:
  44.     c += 1
  45.     draw()
RAW Paste Data