Skip to content

Instantly share code, notes, and snippets.

@SpaceVoyager
Created June 20, 2015 19:38
Show Gist options
  • Save SpaceVoyager/3e2a9c242e1798e622d0 to your computer and use it in GitHub Desktop.
Save SpaceVoyager/3e2a9c242e1798e622d0 to your computer and use it in GitHub Desktop.
draw_filled_semicircle.py
import canvas
# This functions draws a filled semicircle with center at (center_x, center_y)
# and radius = radius
# Note that it actually draws 64 curve segments to approximate the semicircle
# You can use this function to draw the top part of a mushroom
def draw_filled_semicircle(center_x, center_y, radius):
import math
canvas.move_to(center_x-radius, center_y)
n = 64
for i in range(n):
canvas.add_quad_curve(center_x - math.cos(math.pi*i/n)*radius,
math.sin(math.pi*i/n)*radius + center_y,
center_x - math.cos(math.pi*(i+1)/n)*radius,
math.sin(math.pi*(i+1)/n)*radius + center_y)
canvas.close_path()
canvas.fill_path()
canvas.set_size(1000, 600)
canvas.set_fill_color(1.00, 0.40, 0.40)
# draw a semicircle with center at (500, 200) and radius of 300
draw_filled_semicircle(500, 200, 200)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment