View difference between Paste ID: xtQpCaPc and rfwwviny
SHOW: | | - or go back to the newest paste.
1
from Tkinter import *
2
3-
def butts(x,y):
3+
def butts(Bx1, By1, Bx2, By2, x, y, dotSize):
4
	x-=1;y-=1
5
	WINDOW_WIDTH = 800
6
	WINDOW_HEIGHT = 600
7
	def fxrange(min,max,delta=1):
8
		r = min
9
		while r <= max:
10
			yield r
11
			r += delta
12
	def drawGrid(c, x1, y1, x2, y2, x, y):
13
		"""Draws a complete grid (x by y) on Canvas c within the bounding box."""
14
		# calculate the spacing between each line (vertical and horizontal)
15
		sv = float((x2 - x1)) / float(x)
16
		sh = float((y2 - y1)) / float(y)
17
		
18
		# Draw the lines
19
		for i in fxrange(x1, x2, sv):
20
			c.create_line(i, y1, i, y2)
21
		for i in fxrange(y1, y2, sh):
22-
	def drawDots(c, x1, y1, x2, y2, x, y, size=10):
22+
23
	def drawDots(c, x1, y1, x2, y2, x, y, size=dotSize):
24
		"""Draws a complete grid (x by y) of dots on Canvas c within the bounding box."""
25-
		sx = float((x2 - x1)) / float(x)
25+
26-
		sy = float((y2 - y1)) / float(y)
26+
		sx = float(x2 - x1) / float(x)
27
		sy = float(y2 - y1) / float(y)
28
		
29
		for tx in fxrange(x1, x2, sx):
30
			for ty in fxrange(y1, y2, sy):
31-
				box_x1 = tx - (float(size) / 2)
31+
32-
				box_y1 = ty - (float(size) / 2)
32+
				ts = float(size) / 2
33-
				box_x2 = tx + (float(size) / 2)
33+
				box_x1 = tx - ts
34-
				box_y2 = ty + (float(size) / 2)
34+
				box_y1 = ty - ts
35
				box_x2 = tx + ts
36
				box_y2 = ty + ts
37-
				c.create_oval(box_x1, box_y1, box_x2, box_y2)
37+
38
				# draw the circle
39
				c.create_oval(box_x1, box_y1, box_x2, box_y2, fill="black")
40
	master = Tk()
41-
	drawGrid(w, 15, 15, 200, 200, 4, 6)
41+
42-
	drawDots(w, 15, 15, 200, 200, 4, 6)
42+
43
	drawGrid(w, Bx1, By1, Bx2, By2, x, y)
44
	drawDots(w, Bx1, By1, Bx2, By2, x, y)
45-
butts(4,5)
45+
46
47
butts(10, 10, 600, 600, 50, 50, 7)