Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- from tkinter import *
- from random import randint
- tk = Tk()
- def randomBold():
- blist = []
- for x in range(0,4):
- if randint(1,10) % 2 == 1:
- blist.insert(x,5)
- else:
- blist.insert(x,1)
- return blist
- class Surface:
- def __init__(self,W,H):
- global tk
- self.c = Canvas(tk,width=W,height=H)
- self.c.pack(side=TOP)
- self.w = W
- self.h = H
- def getSurface(self):
- return self.c
- def getWidth(self):
- return self.w
- def getHeight(self):
- return self.h
- class Square:
- def __init__(self,T,L,W,H):
- self.top = T
- self.left = L
- self.width = W
- self.height = H
- def draw(self,S):
- x = int(self.top)
- y = int(self.left)
- w = int(self.width)
- h = int(self.height)
- S.getSurface().create_line(x,y,x+w,y) #top
- S.getSurface().create_line(x,y,x,y+h) #left
- S.getSurface().create_line(x,y+h,x+w,y+h) #bottom
- S.getSurface().create_line(x+w,y,x+w,y+h) #right
- def drawBold(self,S,blist): # is a Surface instance
- x = int(self.top)
- y = int(self.left)
- w = int(self.width)
- h = int(self.height)
- S.getSurface().create_line(x,y,x+w,y,width=blist[0]) #top
- S.getSurface().create_line(x,y,x,y+h,width=blist[1]) #left
- S.getSurface().create_line(x,y+h,x+w,y+h,width=blist[2]) #bottom
- S.getSurface().create_line(x+w,y,x+w,y+h,width=blist[3]) #right
- class Matrix:
- def __init__(self,R,C):
- self.rows = R
- self.cols = C
- def draw(self,S):
- xinc = S.getWidth() // (self.rows)
- yinc = S.getHeight() // (self.cols)
- for x in range(1,int(width+1),xinc):
- for y in range(1,int(height+1),yinc):
- blist = randomBold()
- sq = Square(x,y,x+xinc,yinc)
- #sq.draw(S)
- sq.drawBold(S,blist)
- tk.title("Matrix")
- width = 800
- height = 600
- s = Surface(width,height)
- m = Matrix(10,10)
- m.draw(s)
- tk.mainloop()
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement