简体   繁体   中英

Draw the Khan Academy logo using Python turtle graphics

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.

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.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM