def createSpiral(arm1, arm2, color):
	"""arm1 and arm2 are pairs of (length, velocity)"""
	
	canvas.begin_path()
	canvas.move_to(512, 684)
	x, y = 0, 0
	len1, step1 = arm1
	len2, step2 = arm2
	global lines
	lines = []
	previousPositions = []

	while step1 > 10 or step2 > 10:
		step1 /= 2
		step2 /= 2

	global run
	run = 1
	iteration = 1
	inarow = 0
	while run:
		
		iteration += 10
		
		point1 = rotate((0,len1), x)
		point2 = map(sum,zip(rotate((0, len2), y), point1))
		p2 = map(sum, zip(point2, (512, 384)))
		#Detection of whether pattern is repeating itself
		if point2 not in previousPositions:
			previousPositions.append(point2)
			inarow = 0
		else:
			inarow += 1

		if inarow >= 5:
			print "Pattern is detected to be repeating itself"
			run = 0


		if x == 0:
			oldpoint2 = point2
		else:
			canvas.add_line(p2[0], p2[1])
		#lines.append( canvas.add_line(point1[0], point1[1]) )
		#lines.append( canvas.add_line(point2[0], point2[1]) )
		oldpoint2 = point2

		x += step1
		if x > 360: x -= 360
		y += step2
		if y > 360: y -= 360

		#for line in lines:
		#	canvas.delete(line)
		lines = []
		time.sleep(0.005)
	canvas.close_path()
	canvas.set_line_width(1)
	canvas.draw_path()
def createSpiral(arm1, arm2, color):
	"""arm1 and arm2 are pairs of (length, velocity)"""
	
	canvas.begin_path()
	canvas.move_to(512, 684)
	x, y = 0, 0
	len1, step1 = arm1
	len2, step2 = arm2
	global lines
	lines = []
	previousPositions = []

	while step1 > 10 or step2 > 10:
		step1 /= 2
		step2 /= 2

	global run
	run = 1
	iteration = 1
	inarow = 0
	while run:
		
		iteration += 10
		
		point1 = rotate((0,len1), x)
		point2 = map(sum,zip(rotate((0, len2), y), point1))
		p2 = map(sum, zip(point2, (512, 384)))
		#Detection of whether pattern is repeating itself
		if point2 not in previousPositions:
			previousPositions.append(point2)
			inarow = 0
		else:
			inarow += 1

		if inarow >= 5:
			print("Pattern is detected to be repeating itself")
			run = 0


		if x == 0:
			oldpoint2 = point2
		else:
			canvas.add_line(p2[0], p2[1])
		#lines.append( canvas.add_line(point1[0], point1[1]) )
		#lines.append( canvas.add_line(point2[0], point2[1]) )
		oldpoint2 = point2

		x += step1
		if x > 360: x -= 360
		y += step2
		if y > 360: y -= 360

		#for line in lines:
		#	canvas.delete(line)
		lines = []
		time.sleep(0.005)
	canvas.close_path()
	canvas.set_line_width(1)
	canvas.draw_path()
Esempio n. 3
0
def draw_tree(x, y, trunk_thickness, leaf_h, tree_w, trunk_h):
    canvas.begin_path()
    canvas.move_to(x - tree_w / 2, y + trunk_h)
    canvas.add_line(x + tree_w / 2, y + trunk_h)
    canvas.add_line(x, y + trunk_h + leaf_h)
    canvas.close_path()
    canvas.set_fill_color(0.25, 0.50, 0.00)
    canvas.fill_path()
    canvas.set_stroke_color(0.50, 0.25, 0.00)
    canvas.set_line_width(trunk_thickness)
    canvas.draw_line(x, y + trunk_h, x, y)
Esempio n. 4
0
def fill_triangles(x, y, size, theme):
    # fill upper triangle
    canvas.set_fill_color(*shade_of(random.choice(theme.colors)))
    canvas.begin_path()
    canvas.move_to(x, y)
    canvas.add_line(x, y + size)
    canvas.add_line(x + size, y + size)
    canvas.add_line(x, y)
    canvas.fill_path()

    # fill lower triangle
    canvas.set_fill_color(*shade_of(random.choice(theme.colors)))
    canvas.begin_path()
    canvas.move_to(x, y)
    canvas.add_line(x + size, y + size)
    canvas.add_line(x + size, y)
    canvas.add_line(x, y)
    canvas.fill_path()
Esempio n. 5
0
def fill_triangles(x, y, size, theme):
	# fill upper triangle
	canvas.set_fill_color(*shade_of(random.choice(theme.colors)))
	canvas.begin_path()
	canvas.move_to(x, y)
	canvas.add_line(x, y + size)
	canvas.add_line(x + size, y + size)
	canvas.add_line(x, y)
	canvas.fill_path()
	
	# fill lower triangle
	canvas.set_fill_color(*shade_of(random.choice(theme.colors)))
	canvas.begin_path()
	canvas.move_to(x, y)
	canvas.add_line(x + size, y + size)
	canvas.add_line(x + size, y)
	canvas.add_line(x, y)
	canvas.fill_path()
Esempio n. 6
0
def draw_heart(scale = 18):  # 18 = full canvas
    #print(scale)  # useful for debugging
    first_time = True
    (xorigin, yorigin) = canvas.get_size()
    xorigin *= 0.5    # in the center
    yorigin *= 0.588  # north of center
    detail = 100
    canvas.begin_path()
    for t in range(int(2 * math.pi * detail)):
        t *= detail
        x = scale * (16 * math.sin(t) ** 3)
        y = scale * (13 * math.cos(t) - 5*math.cos(2*t) - 2*math.cos(3*t) - math.cos(4 * t))
        if first_time:  # hide the seams
            canvas.move_to(x + xorigin, y + yorigin)
            first_time = False
        canvas.add_line(x + xorigin, y + yorigin)
    canvas.set_line_width(1)
    canvas.close_path()
    canvas.draw_path()  # try commenting out this line...
    canvas.set_fill_color(1, 0, 0)
    canvas.fill_path()  # how do I fill just the inner part?
Esempio n. 7
0
def draw_heart(scale = 18):  # 18 = full canvas
    #print(scale)  # useful for debugging
    first_time = True
    (xorigin, yorigin) = canvas.get_size()
    xorigin *= 0.5    # in the center
    yorigin *= 0.588  # north of center
    detail = 100
    canvas.begin_path()
    for t in xrange(int(2 * math.pi * detail)):
        t *= detail
        x = scale * (16 * math.sin(t) ** 3)
        y = scale * (13 * math.cos(t) - 5*math.cos(2*t) - 2*math.cos(3*t) - math.cos(4 * t))
        if first_time:  # hide the seams
            canvas.move_to(x + xorigin, y + yorigin)
            first_time = False
        canvas.add_line(x + xorigin, y + yorigin)
    canvas.set_line_width(1)
    canvas.close_path()
    canvas.draw_path()  # try commenting out this line...
    canvas.set_fill_color(1, 0, 0)
    canvas.fill_path()  # how do I fill just the inner part?
Esempio n. 8
0
import canvas

canvas.set_size(512, 512)

from_point = (10, 10)
cp1 = (40, 200)  #control point 1
cp2 = (350, 50)  #control point 2
to_point = (300, 300)

# Draw the actual curve:
canvas.begin_path()
canvas.move_to(from_point[0], from_point[1])
canvas.add_curve(cp1[0], cp1[1], cp2[0], cp2[1], to_point[0], to_point[1])
canvas.set_line_width(2)
canvas.draw_path()

# Draw the red dots and lines to illustrate what's happening:
canvas.set_stroke_color(1, 0, 0)
canvas.set_fill_color(1, 0, 0)

# Draw straight lines between the control points and the end points:
canvas.draw_line(from_point[0], from_point[1], cp1[0], cp1[1])
canvas.draw_line(to_point[0], to_point[1], cp2[0], cp2[1])

# Draw red squares on all the points:
canvas.fill_rect(from_point[0] - 4, from_point[1] - 4, 8, 8)
canvas.fill_rect(to_point[0] - 4, to_point[1] - 4, 8, 8)
canvas.fill_rect(cp1[0] - 4, cp1[1] - 4, 8, 8)
canvas.fill_rect(cp2[0] - 4, cp2[1] - 4, 8, 8)
Esempio n. 9
0
# https://gist.github.com/omz/5087533

import canvas

canvas.set_size(512, 512)

from_point = (10, 10)
cp1 = (40, 200) #control point 1
cp2 = (350, 50) #control point 2
to_point = (300, 300)

# Draw the actual curve:
canvas.begin_path()
canvas.move_to(from_point[0], from_point[1])
canvas.add_curve(cp1[0], cp1[1], cp2[0], cp2[1], to_point[0], to_point[1])
canvas.set_line_width(2)
canvas.draw_path()

# Draw the red dots and lines to illustrate what's happening:
canvas.set_stroke_color(1, 0, 0)
canvas.set_fill_color(1, 0, 0)

# Draw straight lines between the control points and the end points:
canvas.draw_line(from_point[0], from_point[1], cp1[0], cp1[1])
canvas.draw_line(to_point[0], to_point[1], cp2[0], cp2[1])

# Draw red squares on all the points:
canvas.fill_rect(from_point[0]-4, from_point[1]-4, 8, 8)
canvas.fill_rect(to_point[0]-4, to_point[1]-4, 8, 8)
canvas.fill_rect(cp1[0]-4, cp1[1]-4, 8, 8)
canvas.fill_rect(cp2[0]-4, cp2[1]-4, 8, 8)