Created
June 20, 2015 19:38
-
-
Save SpaceVoyager/3e2a9c242e1798e622d0 to your computer and use it in GitHub Desktop.
draw_filled_semicircle.py
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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