Reputation: 19
I am trying to draw the Khan Academy logo using turtle graphics in Python but I got stuck when trying to draw the blossoms. Should I do that using a function and how is that done exactly? Or should I draw 2 half circles to achieve it?
I have already started trying with half circles but cannot figure it out.
# circle
t.color("white")
t.up()
t.goto(-25,0)
t.down()
t.begin_fill()
t.circle(60)
t.end_fill()
# blossom
t.up()
t.goto(-25,-150)
t.down()
t.rt(45)
The output should be similar to the Khan Academy logo.
Upvotes: 0
Views: 973
Reputation: 41905
I have already started trying with half circles but still can not figure it out.
You drew a circle, but your half circle attempts are missing in your code above. You should provide as much of your attempts as possible.
This logo can be drawn using just turtle's circle()
method. But, you need to fully understand all three arguments:
circle(radius, extent=None, steps=None)
In particular, what it means to use a negative radius
. (Learning what a negative extent
does wouldn't hurt either.)
I was able to simply eyeball the logo to come up with:
from turtle import Screen, Turtle
RADIUS = 100
screen = Screen()
screen.colormode(255)
turtle = Turtle(visible=False)
turtle.speed('fastest') # because I have no patience
turtle.penup() # we'll use fill instead of lines
turtle.color(20, 191, 150) # greenish color
turtle.sety(-RADIUS) # center hexagon
turtle.begin_fill()
turtle.circle(RADIUS, steps=6) # draw hexagon
turtle.end_fill()
turtle.color('white') # interior color
turtle.sety(2 * RADIUS / 11) # position circle (head)
turtle.begin_fill()
turtle.circle(2 * RADIUS / 9) # draw circle (head)
turtle.end_fill()
turtle.forward(5 * RADIUS / 8)
turtle.right(85)
turtle.begin_fill()
turtle.circle(-13 * RADIUS / 20, 190)
turtle.right(85)
turtle.circle(-13 * RADIUS / 20, 90)
turtle.left(180)
turtle.circle(-13 * RADIUS / 20, 90)
turtle.end_fill()
screen.exitonclick()
What I recommend you do is review the Wikipedia entry for Hexagon and figure out all the useful interior points of a hexagon that might help you design a solution based on geometry. You know it can be done, now do it well.
Upvotes: 1