Advertisement
here2share

# Tk_speed_of_graphics3.py

Apr 23rd, 2020
621
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Python 0.93 KB | None | 0 0
  1. # Tk_speed_of_graphics3.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 3 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.     xy = xy[1:]+[xy[0]] # animate without random()
  28.     img.putdata(tuple(xy))
  29.     imgTk = ImageTk.PhotoImage(img)
  30.     w.create_image(0, 0, anchor=NW, image=imgTk)
  31.     root.update()
  32.     c = c - 1
  33. #
  34. t = int((clock()-start)*((2560*1440)/((wi*he)*1.0)))
  35. if t:
  36.     print("Needs To Be At Least %dx Faster"%t)
  37. else:
  38.     print("Congratulation... Minimal Speed Exceeded!")
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement