文章目录
- 前言
- 一、第一种画法
- 二、第二种画法
- 总结
前言
今天我们来画一朵玫瑰花。
一、第一种画法
这应该是最好看玫瑰花了。
from turtle import *
#设置绘制起点
setup (700,700)
#画笔颜色
pencolor("red")
hideturtle()
penup()
goto(0,280)
pendown()
left(135)
speed(0)
#左侧弧形绘制
a=0.2
for i in range (80):
if i < 50:
pensize(a)
forward(2)
a+=0.15
if i<10:
left(0.7)
elif 10<i<24:
left(1)
elif 24<i<40:
left(3)
elif 40<i<50:
left(4)
elif i >=50:
pensize(a)
forward(2.2)
a-=0.25
if 50<i<65:
left(6.7)
elif 65<i<80:
left(2)
setheading(0)
penup()
goto(40,305)
pendown()
left(145)
#右侧弧形绘制
a=0.1
for i in range (100):
if i < 60:
pensize(a)
forward(3)
a+=0.15
if i<10:
left(0.8)
elif 10<i<24:
left(0.8)
elif 24<i<40:
left(1.7)
elif 40<i<60:
left(2.2)
elif i >=60:
pensize(a)
forward(2.4)
a-=0.15
if 60<i<85:
left(3.2)
elif 85<i<90:
left(4)
setheading(0)
penup()
goto(45,320)
pendown()
left(10)
a=0.1
for i in range (100):
if i < 60:
pensize(a)
forward(3)
a+=0.15
if i<17:
right(3.2)
elif 17<i<20:
right(3.5)
elif 20<i<40:
right(6.8)
elif 40<i<50:
right(0.6)
elif 50<i<60:
left(1)
elif i >=60:
pensize(a)
forward(2.4)
a-=0.16
if 60<i<85:
left(0.4)
elif 85<i<90:
left(1)
setheading(0)
penup()
goto(-135,265)
pendown()
left(160)
a=0.1
for i in range (120):
if i < 60:
pensize(a)
forward(3)
a+=0.15
if i<10:
left(2)
elif 10<i<15:
left(8)
elif 15<i<35:
left(6)
elif 35<i<40:
left(4)
elif 40<i<60:
left(1)
elif i >=60:
pensize(a)
forward(3)
a-=0.15
if 60<i<90:
right(0.4)
elif 90<i<120:
right(0.8)
setheading(0)
penup()
goto(80,250)
pendown()
left(245)
a=0.2
for i in range (80):
if i < 40:
pensize(a)
forward(1.2)
a+=0.15
if i<15:
left(0.6)
elif 15<i<40:
left(0.3)
elif i >=40:
pensize(a)
forward(1.2)
a-=0.15
if 40<i<65:
left(0.6)
elif 65<i<80:
left(0.35)
setheading(0)
penup()
goto(-150,195)
pendown()
left(300)
a=0.2
for i in range (80):
if i < 40:
pensize(a)
forward(1.2)
a+=0.16
if i<15:
right(0.6)
elif 15<i<40:
right(0.3)
elif i >=40:
pensize(a)
forward(1.2)
a-=0.16
if 40<i<65:
right(0.6)
elif 65<i<80:
right(0.35)
setheading(0)
penup()
goto(-205,225)
pendown()
left(194)
a=0.1
for i in range (100):
if i < 50:
pensize(a)
forward(3)
a+=0.15
if i<10:
left(7)
elif 10<i<30:
left(3)
elif 30<i<50:
left(0.1)
elif i >=50:
pensize(a)
forward(3)
a-=0.15
if 50<i<80:
right(0.3)
elif 80<i<100:
right(0.6)
setheading(0)
penup()
goto(110,280)
pendown()
left(6)
a=0.1
for i in range (120):
if i < 60:
pensize(a)
forward(3)
a+=0.15
if i<10:
right(4.5)
elif 10<i<30:
right(5)
elif 30<i<60:
right(0.1)
elif i >=60:
pensize(a)
forward(3)
a-=0.15
if 50<i<80:
left(0.6)
elif 80<i<100:
left(0.9)
setheading(0)
penup()
goto(-160,110)
pendown()
left(283)
a=0.2
for i in range (80):
if i < 40:
pensize(a)
forward(2.4)
a+=0.15
if i<10:
right(0.6)
elif 15<i<40:
right(0.1)
elif i >=40:
pensize(a)
forward(2.4)
a-=0.15
if 40<i<65:
left(2)
elif 65<i<80:
left(3)
setheading(0)
penup()
goto(90,155)
pendown()
left(258)
a=0.2
for i in range (80):
if i < 40:
pensize(a)
forward(3)
a+=0.15
if i<10:
left(0.8)
elif 15<i<40:
left(0.1)
elif i >=40:
pensize(a)
forward(3)
a-=0.15
if 40<i<65:
right(2)
elif 65<i<80:
right(3)
setheading(0)
penup()
goto(-60,-45)
pendown()
right(9)
a=0.2
for i in range (40):
if i < 20:
pensize(a)
forward(1.3)
a+=0.15
if i<5:
left(0.7)
elif 5<i<20:
left(0.4)
elif i >=20:
pensize(a)
forward(1.3)
a-=0.15
if 20<i<35:
left(0.7)
elif 35<i<40:
left(0.4)
setheading(0)
penup()
goto(-70,-55)
pencolor("green")
pendown()
right(170)
a=0.2
for i in range (80):
if i <40 :
pensize(a)
forward(2)
a+=0.15
if i<25:
right(0.5)
elif 25<i<40:
right(1)
elif i >=40:
pensize(a)
forward(2.5)
a-=0.15
if 40<i<55:
right(1)
elif 55<i<70:
right(2)
elif 70<i<80:
right(1)
setheading(270)
left(30)
a=0.2
for i in range (80):
if i <40 :
pensize(a)
forward(2.5)
a+=0.15
if i<25:
left(0.5)
elif 25<i<40:
left(1)
elif i >=40:
pensize(a)
forward(3)
a-=0.15
if 40<i<55:
left(2)
elif 55<i<70:
left(1.3)
elif 70<i<80:
left(1)
setheading(270)
penup()
goto(20,-55)
pendown()
left(65)
a=0.2
for i in range (60):
if i <30 :
pensize(a)
forward(2)
a+=0.15
if i<15:
left(1)
elif 15<i<30:
left(2)
elif i >=30:
pensize(a)
forward(2.5)
a-=0.15
if 30<i<45:
left(2)
elif 45<i<50:
left(2.5)
elif 50<i<60:
left(1.5)
setheading(270)
right(17)
a=0.2
for i in range (80):
if i <40 :
pensize(a)
forward(2.2)
a+=0.15
if i<25:
right(1)
elif 25<i<40:
right(2)
elif i >=40:
pensize(a)
forward(2.5)
a-=0.15
if 40<i<55:
right(2)
elif 55<i<70:
right(1.5)
elif 70<i<80:
right(0.6)
setheading(0)
penup()
pencolor("brown")
goto(-49,-90)
pendown()
right(89)
a=1
for i in range (120):
if i < 60:
pensize(a)
forward(3.5)
a+=0.08
elif i >=60:
pensize(a)
forward(3.5)
a-=0.08
setheading(0)
penup()
goto(-16,-70)
pendown()
right(91)
a=1
for i in range (120):
if i < 60:
pensize(a)
forward(3.5)
a+=0.08
elif i >=60:
pensize(a)
forward(3.5)
a-=0.08
setheading(0)
speed(1)
penup()
goto(-16,-150)
pendown()
pensize(3)
left(35)
forward(15)
setheading(0)
right(115)
forward(34)
setheading(180)
penup()
goto(-49,-250)
pendown()
pensize(3)
right(35)
forward(15)
setheading(180)
left(115)
forward(34)
input()
done
二、第二种画法
第二种就稍逊一筹了,但也挺好看。文章来源:https://www.uudwc.com/A/R62bA/
import turtle
# 设置初始位置
turtle.penup()
turtle.left(90)
turtle.fd(200)
turtle.pendown()
turtle.right(90)
# 花蕊
turtle.fillcolor("red")
turtle.begin_fill()
turtle.circle(10,180)
turtle.circle(25,110)
turtle.left(50)
turtle.circle(60,45)
turtle.circle(20,170)
turtle.right(24)
turtle.fd(30)
turtle.left(10)
turtle.circle(30,110)
turtle.fd(20)
turtle.left(40)
turtle.circle(90,70)
turtle.circle(30,150)
turtle.right(30)
turtle.fd(15)
turtle.circle(80,90)
turtle.left(15)
turtle.fd(45)
turtle.right(165)
turtle.fd(20)
turtle.left(155)
turtle.circle(150,80)
turtle.left(50)
turtle.circle(150,90)
turtle.end_fill()
# 花瓣1
turtle.left(150)
turtle.circle(-90,70)
turtle.left(20)
turtle.circle(75,105)
turtle.setheading(60)
turtle.circle(80,98)
turtle.circle(-90,40)
# 花瓣2
turtle.left(180)
turtle.circle(90,40)
turtle.circle(-80,98)
turtle.setheading(-83)
# 叶子1
turtle.fd(30)
turtle.left(90)
turtle.fd(25)
turtle.left(45)
turtle.fillcolor("green")
turtle.begin_fill()
turtle.circle(-80,90)
turtle.right(90)
turtle.circle(-80,90)
turtle.end_fill()
turtle.right(135)
turtle.fd(60)
turtle.left(180)
turtle.fd(85)
turtle.left(90)
turtle.fd(80)
# 叶子2
turtle.right(90)
turtle.right(45)
turtle.fillcolor("green")
turtle.begin_fill()
turtle.circle(80,90)
turtle.left(90)
turtle.circle(80,90)
turtle.end_fill()
turtle.left(135)
turtle.fd(60)
turtle.left(180)
turtle.fd(60)
turtle.right(90)
turtle.circle(200,60)
总结
所画玫瑰花的库用的只是turtle,但代码却很多。文章来源地址https://www.uudwc.com/A/R62bA/