Python-畫圖

畫圖

蟒蛇繪製,和函數封裝
去掉註釋便可運行python

# DrawPython

'''
import turtle
# 繪製座標系
turtle.setup(650,350,200,200)
畫筆控制
turtle.penup()
# 向當前方向前進
turtle.fd(-250)
畫筆控制
turtle.pendown()
turtle.pensize(25)
turtle.pencolor("purple")
# 改變繪製方向
turtle.seth(-40)
# circle3:畫圓第一個參數:半徑  第二個參數:弧度
for i in range(4):
    turtle.circle(40,80)
    turtle.circle(-40,80)
turtle.circle(40,80/2)
turtle.fd(40)
turtle.circle(16,180)
turtle.fd(40*2/3)

'''



'''
# 代碼改進

from turtle import *
setup(650,350,200,200)
penup()
fd(-250)
pendown()
pensize(25)
pencolor("green")
seth(-40)
for i in range(4):
    circle(40,80)
    circle(-40,80)
circle(40,80/2)
fd(40)
circle(16,180)
fd(40*2/3)

'''





# 函數封裝
'''

import turtle
def drawSnake(radius, angle, length):
    turtle.seth(-40)
    for i in range(length):
        turtle.circle(radius, angle)
        turtle.circle(-radius, angle)
    turtle.circle(radius, angle/2)
    turtle.fd(40)
    turtle.circle(16, 180)
    turtle.fd(40* 2/3)
turtle.setup(650, 350, 200, 200)
turtle.penup()
turtle.fd(-250)
turtle.pendown()
turtle.pensize(25)
turtle.pencolor("purple")
drawSnake(40, 80, 4)
turtle.done()

'''
相關文章
相關標籤/搜索