Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- from Tkinter import *
- def butts(Bx1, By1, Bx2, By2, x, y, dotSize):
- x-=1;y-=1
- 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=dotSize):
- """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
- ts = float(size) / 2
- box_x1 = tx - ts
- box_y1 = ty - ts
- box_x2 = tx + ts
- box_y2 = ty + ts
- # draw the circle
- c.create_oval(box_x1, box_y1, box_x2, box_y2, fill="black")
- master = Tk()
- w = Canvas(master, width=WINDOW_WIDTH, height=WINDOW_HEIGHT)
- w.pack()
- drawGrid(w, Bx1, By1, Bx2, By2, x, y)
- drawDots(w, Bx1, By1, Bx2, By2, x, y)
- mainloop()
- butts(10, 10, 600, 600, 50, 50, 7)
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement