Advertisement
here2share

# Tk_speed_of_graphics2.py

Apr 23rd, 2020
538
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Python 0.97 KB | None | 0 0
  1. # Tk_speed_of_graphics2.py
  2.  
  3. from Tkinter import *
  4. from PIL import Image, ImageTk
  5. import random
  6. from time import clock
  7.  
  8. root = Tk()
  9. root.title("Speed of Graphics 2 on 500x500 per Pixel")
  10. root.geometry("500x500")
  11. wi = 500
  12. he = 500
  13. w = Canvas(root, width=wi, height=he)
  14. w.pack()
  15.  
  16. def data_process(y):
  17.     xy.extend([(y/2,random.randrange(255),0) for x in range(wi)]) # set the color accordingly
  18. #
  19. xy = []
  20. for y in range(he):
  21.     data_process(y)
  22.  
  23. img = Image.new( 'RGB', (wi,he))
  24. c = 40 # Should be at least 40 frames per second for a 2560x1440 screen
  25. start = clock()
  26. while c:
  27.     for y in range(he):
  28.         t = y*wi
  29.         t2 = xy[t:t+wi]
  30.         random.shuffle(t2)
  31.         xy[t:t+wi] = t2
  32.     img.putdata(tuple(xy))
  33.     imgTk = ImageTk.PhotoImage(img)
  34.     w.create_image(0, 0, anchor=NW, image=imgTk)
  35.     root.update()
  36.     c = c - 1
  37. #
  38. t = int((clock()-start)*((2560*1440)/((wi*he)*1.0)))
  39. if t:
  40.     print("Needs To Be At Least %dx Faster"%t)
  41. else:
  42.     print("Congratulation... Minimal Speed Exceeded!")
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement