先放两张图


首先看到这个问题比较懵,只能想到用turtle库一步一步的画,后来老师说可以用其他方式,比如循环,就从网上搜了一些类似的东西,并且请教了一些同学。
开始了磕磕绊绊的敲代码。
因为两个人聚不到一块,上机课也是写老师留的作业,于是写了两个版本。通过网上交流。
一朵玫瑰的是我画的,主要是轮廓不好画,就是利用for循环画出花的大致轮廓。然后再用turtle画出其他的东西。
import turtle as t
t.setup(1000,1000,0,0)
t.speed(0)
t.penup()
t.goto(0,-100)
t.seth(90)
t.fd(340)
t.seth(0)
t.pendown()
t.speed(5)
t.begin_fill()
t.fillcolor(‘red‘)
t.circle(50,30)
for i in range(10):
t.fd(1)
t.left(10)
t.circle(40,40)
for i in range(6):
t.fd(1)
t.left(3)
t.circle(80,40)
for i in range(20):
t.fd(0.5)
t.left(5)
t.circle(80,45)
for i in range(10):
t.fd(2)
t.left(1)
t.circle(80,25)
for i in range(20):
t.fd(1)
t.left(4)
t.circle(50,50)
t.circle(120,55)
t.speed(0)
t.seth(-90)
t.fd(70)
t.right(150)
t.fd(20)
t.left(140)
t.circle(140,90)
t.left(30)
t.circle(160,100)
t.left(130)
t.fd(25)
t.penup()
t.right(150)
t.circle(40,80)
t.pendown()
t.left(115)
t.fd(60)
t.penup()
t.left(180)
t.fd(60)
t.pendown()
t.end_fill()
t.right(120)
t.circle(-50,50)
t.circle(-20,90)
t.speed(1)
t.fd(75)
t.speed(0)
t.circle(90,110)
t.penup()
t.left(162)
t.fd(185)
t.left(170)
t.pendown()
t.circle(200,10)
t.circle(100,40)
t.circle(-52,115)
t.left(20)
t.circle(100,20)
t.circle(300,20)
t.speed(1)
t.fd(250)
t.penup()
t.speed(0)
t.left(180)
t.fd(250)
t.circle(-300,7)
t.right(80)
t.circle(200,5)
t.pendown()
t.left(60)
t.begin_fill()
t.fillcolor(‘green‘)
t.circle(-80,100)
t.right(90)
t.fd(10)
t.left(20)
t.circle(-63,127)
t.end_fill()
t.penup()
t.left(50)
t.fd(20)
t.left(180)
t.pendown()
t.circle(200,25)
t.penup()
t.right(150)
t.fd(180)
t.right(40)
t.pendown()
t.begin_fill()
t.fillcolor(‘green‘)
t.circle(-100,80)
t.right(150)
t.fd(10)
t.left(60)
t.circle(-80,98)
t.end_fill()
t.penup()
t.left(60)
t.fd(13)
t.left(180)
t.pendown()
t.speed(1)
t.circle(-200,23)
t.exitonclick()
三朵玫瑰是同伴用函数画的,我还得再研究研究。
from turtle import *
setup(0.5,0.9)
speed(9)
def DrawOneFlower(i):
seth(0)
if i>0:
penup()
fd(95.63)
right(90)
fd(51.6)
left(90)
elif i<0:
penup()
fd(-92.5)
right(-90)
fd(-57.02)
left(-90)
pendown()
right(i)
begin_fill()
fillcolor("red")
circle(80,20)
circle(5,150)
circle(160,20)
circle(6,150)
circle(200,18)
circle(15,30)
temp1=pos()
circle(15,130)
circle(80,30)
circle(240,10)
#左面的一瓣外圆弧
seth(-90-i)
fd(35)
seth(120-i)
fd(10)
seth(-100-i)
fd(10)
circle(80,80)
#右面的一瓣
seth(8-i)
circle(80,80)
circle(240,10)
temp2=pos()
goto(temp1)
end_fill()
pu()
goto(temp2)
pd()
seth(-120-i)
fd(35)
circle(-80,20)
circle(80,53)
#左面的一瓣内圆弧
seth(30-i)
s=pos()
circle(25,125)
circle(-100,40)
pu()
goto(0,0)
pd()
return s
def DrawRoot(s):
pu()
goto(s)
pd()
pensize(6)
pencolor(‘green‘)
seth(-100)
circle(100,40)
fd(222)
def DrawLeaf():
pencolor(‘brown‘)
pensize(1)
pu()
fd(-150)
seth(10)
pd()
begin_fill()
fillcolor(‘green‘)
temp=pos()
circle(200,15)
pu()
left(180)
circle(-200,10)
pd()
left(180)
seth(-30)
circle(60,120)
seth(150)
circle(60,120)
pu()
goto(temp)
pd()
seth(170)
fd(75)
fd(-60)
seth(-250)
circle(60,120)
seth(-70)
circle(60,120)
hideturtle()
end_fill()
def DrawIt():
Root_Start=DrawOneFlower(60)
DrawOneFlower(0)
DrawOneFlower(-60)
DrawRoot(Root_Start)
DrawLeaf()
DrawIt()
小组成员:张鹏宇,刘冰倩
原文:http://www.cnblogs.com/zpyshuai/p/7764191.html