由于初次接触并使用python的turtle库绘图,所以绘图没什么算法,只是按照自己的想法一笔一划绘制自己想要的图案。有兴趣的朋友可以自己试着绘画自己喜欢的人或物。
绘图平台:www.python123.io;画布大小:1280*720。
利用函数绘制每个字母,然后调整每个字母的位置以达到绘制一张大图的目的。
代码:
#Python--logo
import turtle
#定义函数,绘制字母p
def chr_p(x,y):
turtle.pensize(20)
turtle.color(255,97,0)
turtle.pu()
turtle.goto(x,y)
turtle.pd()
turtle.seth(270)
turtle.fd(150)
turtle.pu()
turtle.goto(x,y)
turtle.pd()
turtle.left(90)
turtle.fd(60)
turtle.circle(-20,180)
turtle.fd(60)
#end p()
#定义函数,绘制字母y
def chr_y(x,y):
turtle.pensize(10)
turtle.color(0,255,0)
turtle.pu()
turtle.goto(x,y)
turtle.pd()
turtle.seth(270)
turtle.fd(40)
turtle.circle(25,180)
turtle.fd(40)
turtle.bk(80)
turtle.seth(270)
a=0.2
for i in range(60):
if 0<=i<20 or 40<=i<60:
a=a+0.08
turtle.rt(2)
turtle.fd(a)
else:
a=a-0.08
turtle.rt(2)
turtle.fd(a)
#end y()
#定义函数,绘制字母t
def chr_t(x,y):
turtle.pensize(10)
turtle.color(56,94,15)
turtle.pu()
turtle.goto(x,y)
turtle.pd()
turtle.seth(0)
turtle.fd(60)
turtle.pu()
turtle.goto(x+30,y+20)
turtle.pd()
turtle.right(90)
turtle.fd(100)
turtle.circle(25,90)
#turtle.fd(10)
#end t()
#定义函数,绘制字母h
def chr_h(x,y):
turtle.pensize(10)
turtle.color(176,224,230)
turtle.pu()
turtle.goto(x,y)
turtle.pd()
turtle.seth(270)
turtle.fd(150)
turtle.bk(60)
turtle.left(90)
turtle.fd(30)
turtle.circle(-20,90)
turtle.fd(40)
#end h()
#定义函数,绘制字母o
def chr_o(x,y):
turtle.pensize(10)
turtle.color(0,255,127)
turtle.pu()
turtle.goto(x,y)
turtle.pd()
turtle.circle(-30,360)
#end o()
#定义函数,绘制字母n
def chr_n(x,y):
turtle.pensize(10)
turtle.color(160,82,45)
turtle.pu()
turtle.goto(x,y)
turtle.pd()
turtle.seth(270)
turtle.fd(60)
turtle.pu()
turtle.goto(x,y)
turtle.pd()
turtle.left(180)
turtle.circle(-30,180)
turtle.fd(60)
#end n()
#定义函数,绘制字母T
def chr_T(x,y):
turtle.pensize(10)
turtle.color(255,0,0)
turtle.pu()
turtle.goto(x,y)
turtle.pd()
turtle.seth(0)
turtle.fd(35)
turtle.pu()
turtle.goto(x+15,y)
turtle.pd()
turtle.right(90)
turtle.fd(35)
#end T()
#定义函数,绘制字母M
def chr_M(x,y):
turtle.pensize(10)
turtle.color(255,125,64)
turtle.pu()
turtle.goto(x,y)
turtle.pd()
turtle.seth(270)
turtle.fd(35)
turtle.pu()
turtle.goto(x,y)
turtle.pd()
turtle.left(45)
turtle.fd(25)
turtle.left(90)
turtle.fd(25)
turtle.seth(270)
turtle.fd(35)
#end M()
#定义函数,绘制蟒蛇图案1
def py1(x,y):
turtle.pensize(5)
turtle.pencolor(192,192,192)
turtle.fillcolor(0,0,255)
turtle.pu()
turtle.goto(x,y)
turtle.pd()
turtle.begin_fill()
turtle.seth(0)
turtle.fd(150)
turtle.seth(270)
turtle.fd(20)
turtle.right(90)
turtle.fd(180)
turtle.circle(50,90)
turtle.fd(100)
turtle.circle(80,90)
turtle.left(90)
turtle.fd(100)
turtle.circle(-50,90)
turtle.fd(120)
turtle.circle(50,90)
turtle.fd(100)
turtle.circle(55,90)
turtle.fd(60)
turtle.circle(105,90)
turtle.end_fill()
turtle.fillcolor(225,225,225)
turtle.pu()
turtle.goto(x+80,y+30)
turtle.pd()
turtle.begin_fill()
turtle.circle(15,360)
turtle.end_fill()
#end py1()
#定义函数,绘制蟒蛇图案2
def py2(x,y):
turtle.pensize(5)
turtle.pencolor(192,192,192)
turtle.fillcolor(255,215,0)
turtle.pu()
turtle.goto(x,y)
turtle.pd()
turtle.begin_fill()
turtle.seth(270)
turtle.fd(100)
turtle.circle(-55,90)
turtle.fd(120)
turtle.circle(50,90)
turtle.fd(100)
turtle.circle(50,90)
turtle.fd(60)
turtle.circle(110,90)
turtle.left(90)
turtle.fd(150)
turtle.right(90)
turtle.fd(20)
turtle.right(90)
turtle.fd(180)
turtle.circle(50,90)
turtle.fd(100)
turtle.circle(76,90)
turtle.end_fill()
turtle.fillcolor(225,225,225)
turtle.pu()
turtle.goto(x-80,y-270)
turtle.pd()
turtle.begin_fill()
turtle.circle(15,360)
turtle.end_fill()
#end py2()
def main():
turtle.colormode(255)
x=-100
y=60
py1(x-400,y+45)
py2(x-165,y+90)
chr_p(x,y-30)
chr_y(x+100,y-80)
chr_t(x+180,y-60)
chr_h(x+260,y-20)
chr_o(x+400,y-130)
chr_n(x+440,y-110)
chr_T(x+500,y+50)
chr_M(x+550,y+50)
main()
运行后得到的图案:

网友评论