python中turtle库绘图

turtle(龟)绘图

蟒蛇

#form turtle import *  调用里面的库
#import turtle
import turtle as t
t.setup()     #定义画布的大小setup(400,400,0,0)长宽,以及画布对于整个屏幕的定位
t.penup()     #提起画笔
t.fd(-200)              #移动箭头,向后移动200
t.pendown()             #开始作画
t.right(20)             #相对定位,针对箭头
t.seth(-20)             #绝对定位,针对于原点
t.pencolor("red")
t.pensize(25)
for i in range(6):    #循环
    t.circle(50,40)
    t.circle(-50,40)
t.circle(30,180)
t.circle(50,40)
t.circle(-50,40)
t.done()                #结束
#t.goto(100,100)   针对于远点进行定位移动






金鸡独立

import turtle as t
t.begin_fill()
t.setup()
t.pu()
t.seth(-90)
t.fd(200)
t.pd()
t.pensize(10)
t.seth(0)
#身体
t.circle(150,120)
t.circle(150,-120)
t.circle(200,-80)
t.fillcolor('gold')
t.end_fill()
t.begin_fill()
#尾巴
t.seth(0)
t.right(160)
t.fd(15)
t.seth(0)
t.left(70)
t.fd(15)
t.seth(0)
t.right(160)
t.fd(15)
t.seth(0)
t.left(70)
t.fd(20)
t.seth(0)
t.right(160)
t.fd(15)
t.seth(0)
t.left(70)
t.fd(25)
t.circle(-30,20)

t.seth(0)
t.right(30)
t.circle(100,120)
t.circle(-150,40)
t.circle(-100,180)


#嘴巴
t.seth(0)
t.right(140)
t.fd(40)
t.left(120)
t.fd(45)
t.seth(0)
t.left(30)
t.fd(50)
t.left(150)
t.fd(60)
t.fd(-60)
t.right(30)
t.fd(50)



#眼睛
t.pu()
t.left(-20)
t.fd(100)
t.pd()
t.circle(10,360)

#翅膀
t.pu()
t.seth(0)
t.right(100)
t.fd(120)
t.pd()
t.left(105)

t.circle(-50,100)
t.circle(-150,100)
t.seth(0)
t.left(180)
for i in range(3):
    t.circle(-20,180)
    t.left(180)


t.fillcolor('gold')
t.end_fill()
# 腿
t.left(110)
t.pu()
t.fd(190)
t.pd()

t.right(15)
t.fd(50)
t.left(65)
t.fd(30)
t.fd(-30)
t.right(90)
t.fd(20)
t.fd(-20)
t.right(90)
t.fd(10)
t.done()

八角形

import turtle as t
t.setup()
t.pu()
t.pd()
t.pensize(10)
for i in range(8):
    t.fd(300)
    t.left(135)
t.fillcolor('red')
t.done()

八边形

import turtle as t
t.setup()
t.pu()
t.pd()
t.pensize(10)
for i in range(8):    
    t.fd(150)    
    t.left(45)
t.done()

原文地址:https://www.cnblogs.com/SkyOceanchen/p/11190296.html