Advertisement
here2share

# Tk_tablecloth_ripple.py

Oct 2nd, 2019
251
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Python 0.89 KB | None | 0 0
  1. # Tk_tablecloth_ripple.py
  2.  
  3. from Tkinter import *
  4. from PIL import Image, ImageTk
  5. from math import *
  6. import random
  7.  
  8. root = Tk()
  9. root.title("Tk Tablecloth Ripple")
  10. root.geometry("500x500")
  11. wi = 500
  12. he = 500
  13. w = Canvas(root, width=wi, height=he)
  14. w.pack()
  15.  
  16. img = Image.new( 'RGB', (wi,he))
  17. cols = {}
  18. xy = []
  19.  
  20. DIM = 500  
  21.  
  22. def r(i, j):
  23.     s=3./(j+120)
  24.     y=(j+sin((i*i+sqrt(j))/100./DIM)*100)*s
  25.     return (int((i+DIM)*s+y)%2+int((DIM*2-i)*s+y)%2)*127
  26.  
  27. def g(i, j):
  28.     s=3./(j+120)
  29.     y=(j+sin((i*i+sqrt(j))/100./DIM)*100)*s
  30.     return (int(5*((i+DIM)*s+y))%2+int(5*((DIM*2-i)*s+y))%2)*127
  31.  
  32. def b(i, j):
  33.     s=3./(j+120)
  34.     y=(j+sin((i*i+sqrt(j))/100./DIM)*100)*s
  35.     return (int(20*((i+DIM)*s+y))%2+int(20*((DIM*2-i)*s+y))%2)*127
  36.  
  37. for y in range(DIM):
  38.     for x in range(DIM):
  39.         c = '#%02x%02x%02x' % (int(r(x, y)),int(g(x, y)),int(b(x, y)))
  40.         w.create_line((x, y, x+1,y+2),fill=c)
  41.     root.update()
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement