Exemplo n.º 1
0
def draw_triangle(x, y, size, num_remaining):
    if num_remaining > 0:
        canvas.set_fill_color(*shade_of(random.choice(palette.colors)))
        canvas.set_stroke_color(*shade_of(random.choice(palette.colors)))
        canvas.set_line_width(random.random() * 0.5 + 0.5)
        step = math.sqrt(size**2 - (size / 2.0)**2)
        canvas.move_to(x - step, y - (size / 2.0))
        canvas.add_line(x, y + size)
        canvas.add_line(x + step, y - (size / 2.0))
        canvas.add_line(x - step, y - (size / 2.0))
        canvas.fill_path()
        canvas.draw_line(x - step, y - (size / 2.0), x, y + size)
        canvas.draw_line(x, y + size, x + step, y - (size / 2.0))
        canvas.draw_line(x + step, y - (size / 2.0), x - step,
                         y - (size / 2.0))
        canvas.draw_line(x, y, x - (step / 2.0), y + (size / 4.0))
        canvas.draw_line(x, y, x + (step / 2.0), y + (size / 4.0))
        canvas.draw_line(x, y, x, y - (size / 2.0))
        canvas.draw_line(x - (step / 2.0), y + (size / 4.0), x + (step / 2.0),
                         y + (size / 4.0))
        canvas.draw_line(x + (step / 2.0), y + (size / 4.0), x,
                         y - (size / 2.0))
        canvas.draw_line(x, y - (size / 2.0), x - (step / 2.0),
                         y + (size / 4.0))
        draw_triangle(random.random() * width,
                      random.random() * height,
                      random.random() * triangle_side, num_remaining - 1)
def draw_heart(outline = False):
	first = True
	for t in xrange(int(2*pi * detail)):
		t = t * detail
		# heart equation
		x = 16*(sin(t) ** 3)
		y = 13*cos(t) - 5*cos(2*t) - 2*cos(3*t) - cos(4*t)
		# scale result
		x = origin + x * scale
		y = origin + y * scale + scale*2
		# hide first line
		if first:
			canvas.move_to(x, y)
			first = False
		else:
			canvas.add_line(x, y)
	# set color
	canvas.set_fill_color(1,0.5,0.5)
	canvas.set_stroke_color(0.5,0,0)
	canvas.set_line_width(detail/2)
	# draw heart
	if outline:
		canvas.draw_path()
	else:
		canvas.close_path()
		canvas.fill_path()
Exemplo 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)
Exemplo 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()
Exemplo 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()
Exemplo n.º 6
0
def draw_triangle(x, y, size, num_remaining):
	r, g, b = random.choice(palette)
	canvas.set_fill_color(r, g, b, random.random() * 0.75 + 0.25)
	r, g, b = random.choice(palette)
	canvas.set_stroke_color(r, g, b, random.random() * 0.5 + 0.5)
	canvas.set_line_width(random.random() * 2.5 + 0.5)
	step = math.sqrt(size**2 - (size / 2.0)**2)
	canvas.move_to(x - step, y - (size / 2.0))
	canvas.add_line(x, y + size)
	canvas.add_line(x + step, y - (size / 2.0))
	canvas.add_line(x - step, y - (size / 2.0))
	canvas.fill_path()
	canvas.draw_line(x - step, y - (size / 2.0), x, y + size)
	canvas.draw_line(x, y + size, x + step, y - (size / 2.0))
	canvas.draw_line(x + step, y - (size / 2.0), x - step, y - (size / 2.0))
	canvas.draw_line(x, y, x - (step / 2.0), y + (size / 4.0))
	canvas.draw_line(x, y, x + (step / 2.0), y + (size / 4.0))
	canvas.draw_line(x, y, x, y - (size / 2.0))
	canvas.draw_line(x - (step / 2.0), y + (size / 4.0), x + (step / 2.0), y + (size / 4.0))
	canvas.draw_line(x + (step / 2.0), y + (size / 4.0), x, y - (size / 2.0))
	canvas.draw_line(x, y - (size / 2.0), x - (step / 2.0), y + (size / 4.0))
Exemplo 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 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?
Exemplo n.º 8
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?
Exemplo n.º 9
0
def draw_triangle(x, y, size, num_remaining):
	if num_remaining > 0:
		canvas.set_fill_color(*shade_of(random.choice(palette.colors)))
		canvas.set_stroke_color(*shade_of(random.choice(palette.colors)))
		canvas.set_line_width(random.random() * 0.5 + 0.5)
		step = math.sqrt(size**2 - (size / 2.0)**2)
		canvas.move_to(x - step, y - (size / 2.0))
		canvas.add_line(x, y + size)
		canvas.add_line(x + step, y - (size / 2.0))
		canvas.add_line(x - step, y - (size / 2.0))
		canvas.fill_path()
		canvas.draw_line(x - step, y - (size / 2.0), x, y + size)
		canvas.draw_line(x, y + size, x + step, y - (size / 2.0))
		canvas.draw_line(x + step, y - (size / 2.0), x - step, y - (size / 2.0))
		canvas.draw_line(x, y, x - (step / 2.0), y + (size / 4.0))
		canvas.draw_line(x, y, x + (step / 2.0), y + (size / 4.0))
		canvas.draw_line(x, y, x, y - (size / 2.0))
		canvas.draw_line(x - (step / 2.0), y + (size / 4.0), x + (step / 2.0), y + (size / 4.0))
		canvas.draw_line(x + (step / 2.0), y + (size / 4.0), x, y - (size / 2.0))
		canvas.draw_line(x, y - (size / 2.0), x - (step / 2.0), y + (size / 4.0))
		draw_triangle(random.random() * width, random.random() * height, random.random() * triangle_side, num_remaining - 1)
Exemplo n.º 10
0
def draw_triangle(x, y, size, num_remaining):
    r, g, b = random.choice(palette)
    canvas.set_fill_color(r, g, b, random.random() * 0.75 + 0.25)
    r, g, b = random.choice(palette)
    canvas.set_stroke_color(r, g, b, random.random() * 0.5 + 0.5)
    canvas.set_line_width(random.random() * 2.5 + 0.5)
    step = math.sqrt(size**2 - (size / 2.0)**2)
    canvas.move_to(x - step, y - (size / 2.0))
    canvas.add_line(x, y + size)
    canvas.add_line(x + step, y - (size / 2.0))
    canvas.add_line(x - step, y - (size / 2.0))
    canvas.fill_path()
    canvas.draw_line(x - step, y - (size / 2.0), x, y + size)
    canvas.draw_line(x, y + size, x + step, y - (size / 2.0))
    canvas.draw_line(x + step, y - (size / 2.0), x - step, y - (size / 2.0))
    canvas.draw_line(x, y, x - (step / 2.0), y + (size / 4.0))
    canvas.draw_line(x, y, x + (step / 2.0), y + (size / 4.0))
    canvas.draw_line(x, y, x, y - (size / 2.0))
    canvas.draw_line(x - (step / 2.0), y + (size / 4.0), x + (step / 2.0),
                     y + (size / 4.0))
    canvas.draw_line(x + (step / 2.0), y + (size / 4.0), x, y - (size / 2.0))
    canvas.draw_line(x, y - (size / 2.0), x - (step / 2.0), y + (size / 4.0))
Exemplo n.º 11
0
import canvas
w = h = 512
canvas.set_size(w, h)
canvas.move_to(w * 0.45, h * 0.1)
canvas.add_line(w * 0.8, h * 0.55)
canvas.add_line(w * 0.55, h * 0.65)
canvas.add_line(w * 0.65, h * 0.85)
canvas.add_line(w * 0.3, h * 0.55)
canvas.add_line(w * 0.55, h * 0.45)
canvas.close_path()
canvas.set_line_width(3)
canvas.draw_path()
canvas.fill_path()
Exemplo n.º 12
0
import canvas
w = h = 512
canvas.set_size(w, h)
canvas.move_to(w*0.45, h*0.1)
canvas.add_line(w*0.8, h*0.55)
canvas.add_line(w*0.55, h*0.65)
canvas.add_line(w*0.65, h*0.85)
canvas.add_line(w*0.3, h*0.55)
canvas.add_line(w*0.55, h*0.45)
canvas.close_path()
canvas.set_line_width(3)
canvas.draw_path()
canvas.fill_path()