Advertisement
Guest User

Untitled

a guest
Mar 19th, 2018
69
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 2.10 KB | None | 0 0
  1. from tkinter import *
  2. from random import randint
  3. tk = Tk()
  4.  
  5. def randomBold():
  6. blist = []
  7. for x in range(0,4):
  8. if randint(1,10) % 2 == 1:
  9. blist.insert(x,5)
  10. else:
  11. blist.insert(x,1)
  12. return blist
  13.  
  14. class Surface:
  15. def __init__(self,W,H):
  16. global tk
  17. self.c = Canvas(tk,width=W,height=H)
  18. self.c.pack(side=TOP)
  19. self.w = W
  20. self.h = H
  21. def getSurface(self):
  22. return self.c
  23. def getWidth(self):
  24. return self.w
  25. def getHeight(self):
  26. return self.h
  27.  
  28. class Square:
  29. def __init__(self,T,L,W,H):
  30. self.top = T
  31. self.left = L
  32. self.width = W
  33. self.height = H
  34. def draw(self,S):
  35. x = int(self.top)
  36. y = int(self.left)
  37. w = int(self.width)
  38. h = int(self.height)
  39. S.getSurface().create_line(x,y,x+w,y) #top
  40. S.getSurface().create_line(x,y,x,y+h) #left
  41. S.getSurface().create_line(x,y+h,x+w,y+h) #bottom
  42. S.getSurface().create_line(x+w,y,x+w,y+h) #right
  43. def drawBold(self,S,blist): # is a Surface instance
  44. x = int(self.top)
  45. y = int(self.left)
  46. w = int(self.width)
  47. h = int(self.height)
  48. S.getSurface().create_line(x,y,x+w,y,width=blist[0]) #top
  49. S.getSurface().create_line(x,y,x,y+h,width=blist[1]) #left
  50. S.getSurface().create_line(x,y+h,x+w,y+h,width=blist[2]) #bottom
  51. S.getSurface().create_line(x+w,y,x+w,y+h,width=blist[3]) #right
  52.  
  53. class Matrix:
  54. def __init__(self,R,C):
  55. self.rows = R
  56. self.cols = C
  57. def draw(self,S):
  58. xinc = S.getWidth() // (self.rows)
  59. yinc = S.getHeight() // (self.cols)
  60. for x in range(1,int(width+1),xinc):
  61. for y in range(1,int(height+1),yinc):
  62. blist = randomBold()
  63. sq = Square(x,y,x+xinc,yinc)
  64. #sq.draw(S)
  65. sq.drawBold(S,blist)
  66.  
  67. tk.title("Matrix")
  68. width = 800
  69. height = 600
  70. s = Surface(width,height)
  71. m = Matrix(10,10)
  72. m.draw(s)
  73.  
  74. tk.mainloop()
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement