[英]Draw the Khan Academy logo using Python turtle graphics
我正在嘗試使用 Python 中的海龜圖形繪制可汗學院徽標,但在嘗試繪制花朵時卡住了。 我應該使用函數來做到這一點嗎?這是如何做到的? 或者我應該畫2個半圓來實現它?
我已經開始嘗試使用半圓,但無法弄清楚。
# 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)
輸出應該類似於可汗學院的標志。
我已經開始嘗試使用半圓,但仍然無法弄清楚。
您畫了一個圓圈,但上面的代碼中缺少您的半圈嘗試。 您應該提供盡可能多的嘗試。
這個標志可以只使用烏龜的circle()
方法繪制。 但是,您需要完全理解所有三個論點:
circle(radius, extent=None, steps=None)
特別是,使用負radius
意味着什么。 (了解負extent
作用也不會受到傷害。)
我能夠簡單地觀察徽標以提出:
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()
我建議您查看Wikipedia 中的 Hexagon 條目,找出六邊形的所有有用內點,這可能有助於您設計基於幾何的解決方案。 你知道它可以做到,現在把它做好。
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.