Advertisement
Vermiculus

Untitled

Jul 20th, 2012
66
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Python 1.37 KB | None | 0 0
  1. from Tkinter import *
  2.  
  3. def butts(x,y):
  4.     WINDOW_WIDTH = 800
  5.     WINDOW_HEIGHT = 600
  6.     def fxrange(min,max,delta=1):
  7.         r = min
  8.         while r <= max:
  9.             yield r
  10.             r += delta
  11.     def drawGrid(c, x1, y1, x2, y2, x, y):
  12.         """Draws a complete grid (x by y) on Canvas c within the bounding box."""
  13.         # calculate the spacing between each line (vertical and horizontal)
  14.         sv = float((x2 - x1)) / float(x)
  15.         sh = float((y2 - y1)) / float(y)
  16.        
  17.         # Draw the lines
  18.         for i in fxrange(x1, x2, sv):
  19.             c.create_line(i, y1, i, y2)
  20.         for i in fxrange(y1, y2, sh):
  21.             c.create_line(x1, i, x2, i)
  22.     def drawDots(c, x1, y1, x2, y2, x, y, size=10):
  23.         """Draws a complete grid (x by y) of dots on Canvas c within the bounding box."""
  24.         # calculate the spacing between each line (vertical and horizontal)
  25.         sx = float((x2 - x1)) / float(x)
  26.         sy = float((y2 - y1)) / float(y)
  27.        
  28.         for tx in fxrange(x1, x2, sx):
  29.             for ty in fxrange(y1, y2, sy):
  30.                 # calculate the bounding box of the circle
  31.                 box_x1 = tx - (float(size) / 2)
  32.                 box_y1 = ty - (float(size) / 2)
  33.                 box_x2 = tx + (float(size) / 2)
  34.                 box_y2 = ty + (float(size) / 2)
  35.                
  36.                 # draw the circle
  37.                 c.create_oval(box_x1, box_y1, box_x2, box_y2)
  38.     master = Tk()
  39.     w = Canvas(master, width=WINDOW_WIDTH, height=WINDOW_HEIGHT)
  40.     w.pack()
  41.     drawGrid(w, 15, 15, 200, 200, 4, 6)
  42.     drawDots(w, 15, 15, 200, 200, 4, 6)
  43.     mainloop()
  44.  
  45. butts(4,5)
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement