python turtle模塊(二) 畫圓


注意點:
1、turtle.pu() 與turtle.penup()用法一樣 抬起畫筆
2、turtle.fd(r) 參數是距離值,移動多少距離,penddown時可以划線 penup時可以移動
3、turtle.left(90) 逆時針轉動90度,turtle.right(90)是順時針轉動90度,注意是在當前角度上轉動90度
4、turtle.seth(60) 參數是畫筆的角度

#!/usr/bin/env python
# -*- coding: UTF-8 -*-
import turtle


def draw_a_circle(radius):

    turtle.pendown()
    turtle.circle(radius)


if __name__=="__main__":

    r = 50

    # 設置畫布
    turtle.setup(1000, 1000, -r, 0)

    # 畫第一個圓
    draw_a_circle(r)

    # 畫第二個圓,紅色,與第一個圓完全重合
    turtle.pu()
    turtle.fd(0)
    turtle.pencolor("red")
    draw_a_circle(r)

    # 畫第三個圓,與第二個圓相交
    turtle.pu()
    turtle.fd(r)
    turtle.pencolor("green")
    draw_a_circle(r)

    # 畫第四個圓,與第三個圓相切
    turtle.pu()
    turtle.fd(2*r)
    turtle.pencolor("red")
    draw_a_circle(r)

    # 畫第五個圓,與第四個圓相離
    turtle.pu()
    turtle.fd(2.5 * r)
    turtle.pencolor("red")
    draw_a_circle(r)

    # 畫第6個圓
    turtle.right(90)
    turtle.pencolor("green")
    draw_a_circle(r)

    # 畫第7個圓
    turtle.left(180)
    turtle.pencolor("green")
    draw_a_circle(r)

    # 畫第8個圓
    turtle.left(90)
    turtle.pencolor("green")
    draw_a_circle(r)

    # 畫第9個圓
    turtle.settiltangle(60)
    turtle.pencolor("red")
    draw_a_circle(r)

    # 畫一條直線 角度60
    turtle.seth(60)
    turtle.pencolor("red")
    turtle.fd(100)

    # 圖形完成后,不會立即退出,需要用戶點擊關閉按鈕才會退出
    turtle.exitonclick()


免責聲明!

本站轉載的文章為個人學習借鑒使用,本站對版權不負任何法律責任。如果侵犯了您的隱私權益,請聯系本站郵箱yoyou2525@163.com刪除。



 
粵ICP備18138465號   © 2018-2025 CODEPRJ.COM