Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- from Tkinter import *
- def butts(x,y):
- WINDOW_WIDTH = 800
- WINDOW_HEIGHT = 600
- def fxrange(min,max,delta=1):
- r = min
- while r <= max:
- yield r
- r += delta
- def drawGrid(c, x1, y1, x2, y2, x, y):
- """Draws a complete grid (x by y) on Canvas c within the bounding box."""
- # calculate the spacing between each line (vertical and horizontal)
- sv = float((x2 - x1)) / float(x)
- sh = float((y2 - y1)) / float(y)
- # Draw the lines
- for i in fxrange(x1, x2, sv):
- c.create_line(i, y1, i, y2)
- for i in fxrange(y1, y2, sh):
- c.create_line(x1, i, x2, i)
- def drawDots(c, x1, y1, x2, y2, x, y, size=10):
- """Draws a complete grid (x by y) of dots on Canvas c within the bounding box."""
- # calculate the spacing between each line (vertical and horizontal)
- sx = float((x2 - x1)) / float(x)
- sy = float((y2 - y1)) / float(y)
- for tx in fxrange(x1, x2, sx):
- for ty in fxrange(y1, y2, sy):
- # calculate the bounding box of the circle
- box_x1 = tx - (float(size) / 2)
- box_y1 = ty - (float(size) / 2)
- box_x2 = tx + (float(size) / 2)
- box_y2 = ty + (float(size) / 2)
- # draw the circle
- c.create_oval(box_x1, box_y1, box_x2, box_y2)
- master = Tk()
- w = Canvas(master, width=WINDOW_WIDTH, height=WINDOW_HEIGHT)
- w.pack()
- drawGrid(w, 15, 15, 200, 200, 4, 6)
- drawDots(w, 15, 15, 200, 200, 4, 6)
- mainloop()
- butts(4,5)
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement