python画椭圆turtle_如何用Python画一只肥肥的柯基狗狗——turtle库绘制椭圆与弧线实践...

from turtle import *

pensize(5)

speed(0)

##color('#F4A460')#橘黄

##color('#FFE4E1')#肉粉

##【背景圆】

color('#B088FF')#浅紫

pu()

goto(0,-200)

pd()

begin_fill()

circle(200)

end_fill()

##定义画弧函数

def Arc(initial_degree,range_num,step,rotate_degree):

seth(initial_degree)

for n in range(range_num):

fd(step)

rt(rotate_degree)#

##定义填充矩形函数

def Rect(x,y,height,width):

pu()

goto(x,y)

pd()

begin_fill()

goto(x+width,y)

goto(x+width,y+height)

goto(x,y+height)

goto(x,y)

end_fill()

##定义绘制填充等边三角形函数

def Triangle(x,y,side_length):#等边三角形底边左角

pu()

goto(x,y)

pd()

begin_fill()

seth(0)

fd(side_length)

rt(120)#lt()是正立三角形

fd(side_length)

rt(120)#lt()是正立三角形

fd(side_length)

end_fill()

#中轴线——辅助绘图线

#color("green")

#Rect(-200,0,1,400)#x轴

#Rect(0,-200,400,1)#y轴

##【图层1——面部轮廓】

color('#F4A460')#橘黄

#左耳

pu()

goto(-83.13,-10.94)

pd()

begin_fill()

Arc(120,145,1,1/4)

goto(-30,50)

end_fill()

#右耳

pu()

goto(83.13,-10.94)#(88.13,10.94)

pd()

begin_fill()

Arc(60,145,1,-1/4)

goto(30,50)

end_fill()

#腮帮

#右腮帮

pu()

goto(83.13,-10.94)#0

pd()

begin_fill()

Arc(-35,135,1,9/11)#1

#print(pos())

#下巴

#pencolor("yellow")

Arc(-145,70,1,3/10)#右半下颌2

#print(pos())

#pencolor("red")

Arc(-175,40,1,1/5)#下巴连接线3

#print(pos())

#pencolor("pink")

Arc(168,70,1,3/10)#左半下颌4

#print(pos())

#左腮帮

#pencolor("grey")

Arc(146,135,1,9/11)#5

#print(pos())

#两耳连接

pu()

goto(-30,50)

Arc(15,80,1,1/2)

end_fill()

##【图层2——耳部轮廓】

color('pink')#FFC0CB

#左耳

pu()

goto(-42,50)

pd()

begin_fill()

Arc(-164,55,1,-7/8)

Arc(120,100,1,1/3)

goto(-42,50)

end_fill()

#右耳

pu()

goto(42,50)

pd()

begin_fill()

Arc(-16,55,1,7/8)#(81.13,15.94)

#print(pos())

Arc(60,100,1,-1/3)#(104.15,111.82)

#print(pos())

goto(42,50)

end_fill()

##【图层3——眼部轮廓】

#左黑眼豆豆

pu()

goto(-46,-8)

pd()

color("black")

seth(180)

len = 0.3

begin_fill()

for k in range(2): # 双弧绘制椭圆

for j in range(60):

if j < 30:

len += 0.04

else:

len -= 0.04

fd(len)

lt(3)

end_fill()

#左眼白光

color("white")

Rect(-43,-38,6,2)

#右黑眼豆豆

pu()

goto(46,-8)

pd()

color("black")

seth(180)

len = 0.3

begin_fill()

for k in range(2): # 将相同的动作重复做一遍

for j in range(60):

if j < 30:

len += 0.04

else:

len -= 0.04

fd(len)

lt(3)

end_fill()

#右眼白光

color("white")

Rect(40,-38,6,2)

##【图层4——白鼻子轮廓】

pu()

goto(10,50)

pd()

goto(-10,50)

color("white")

begin_fill()

Arc(-82,140,1,1/7)#结束角度A=-82-140*1/7=-102

Arc(-112,20,1.1,-1.2)#结束角度B=-112+20*1.2=-88

#setx(-xcor())

goto(-xcor(),ycor())

seth

Arc(88,20,1.1,-1.2)#求A的y轴对称角度

Arc(102,140,1,1/7)#求8的y轴对称角度

goto(10,50)

end_fill()

pd()

#圆嘴

pu()

goto(0,-150)

seth(0)

pd()

begin_fill()

circle(35)

end_fill()

#黑鼻头

color("black")

Triangle(-10,-120,20)

end_fill()

hideturtle()

done()

好的,让我们来绘制一只狗狗吧!我们将使用Python中的turtle来实现这个目标。 首先,我们需要导入turtle,并创建一个板。 ```python import turtle # 创建一个板 canvas = turtle.Screen() canvas.title("小狗狗") ``` 接下来,我们需要创建一个笔,并设置一些基本属性,例如颜色、笔宽等。 ```python # 创建一个笔 pen = turtle.Turtle() # 设置笔属性 pen.pensize(5) pen.color("black") ``` 现在,我们可以开始绘制狗狗了!我们将分多个步骤来完成这个过程。 第一步,绘制狗狗的头部。 ```python # 绘制头部 pen.penup() pen.goto(0, 100) pen.pendown() pen.circle(50) ``` 第二步,绘制狗狗的眼睛和嘴巴。 ```python # 绘制眼睛 pen.penup() pen.goto(-20, 120) pen.pendown() pen.fillcolor("white") pen.begin_fill() pen.circle(10) pen.end_fill() pen.penup() pen.goto(20, 120) pen.pendown() pen.begin_fill() pen.circle(10) pen.end_fill() pen.fillcolor("black") pen.penup() pen.goto(-20, 130) pen.pendown() pen.begin_fill() pen.circle(5) pen.end_fill() pen.penup() pen.goto(20, 130) pen.pendown() pen.begin_fill() pen.circle(5) pen.end_fill() # 绘制嘴巴 pen.penup() pen.goto(0, 90) pen.pendown() pen.right(90) pen.circle(25, 180) ``` 第三步,绘制狗狗的身体。 ```python # 绘制身体 pen.penup() pen.goto(0, 50) pen.pendown() pen.right(90) pen.forward(100) pen.right(90) pen.forward(80) pen.right(90) pen.forward(100) ``` 第四步,绘制狗狗的四条腿。 ```python # 绘制四条腿 pen.penup() pen.goto(-40, 50) pen.pendown() pen.right(45) pen.forward(40) pen.right(180) pen.forward(40) pen.right(90) pen.forward(40) pen.penup() pen.goto(40, 50) pen.pendown() pen.right(180) pen.right(45) pen.forward(40) pen.right(180) pen.forward(40) pen.right(90) pen.forward(40) ``` 最后,我们需要隐藏笔并保持板打开。 ```python # 隐藏笔并保持板打开 pen.hideturtle() canvas.mainloop() ``` 现在,你可以运行这个脚本,看看我们绘制的小狗狗长什么样子了!
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值