设为首页 加入收藏

TOP

使用Python画一朵美丽的玫瑰花(一)
2019-02-28 00:08:29 】 浏览:374
Tags:使用 Python 美丽 玫瑰花

但是需要计算各种角度、距离等,所以要想完成一幅复杂的图像还是有一定的难度的。


效果图


使用Python画一朵美丽的玫瑰花


源码一


from turtle import *
import time
 
setup(600,800,0,0)
speed(0)
penup()
seth(90)
fd(340)
seth(0)
pendown()
 
speed(5)
begin_fill()
fillcolor('red')
circle(50,30)
 
for i in range(10):
    fd(1)
    left(10)
 
circle(40,40)
 
for i in range(6):
    fd(1)
    left(3)
 
circle(80,40)
 
for i in range(20):
    fd(0.5)
    left(5)
 
circle(80,45)
 
for i in range(10):
    fd(2)
    left(1)
   
circle(80,25)
 
for i in range(20):
    fd(1)
    left(4)
 
circle(50,50)
 
time.sleep(0.1)
 
circle(120,55)
 
speed(0)
 
seth(-90)
fd(70)
 
right(150)
fd(20)
 
left(140)
circle(140,90)
 
left(30)
circle(160,100)
 
left(130)
fd(25)
 
penup()
right(150)
circle(40,80)
pendown()
 
left(115)
fd(60)
 
penup()
left(180)
fd(60)
pendown()
 
end_fill()
 
right(120)
circle(-50,50)
circle(-20,90)
 
speed(1)
fd(75)
 
speed(0)
circle(90,110)
 
penup()
left(162)
fd(185)
left(170)
pendown()
circle(200,10)
circle(100,40)
circle(-52,115)
left(20)
circle(100,20)
circle(300,20)
speed(1)
fd(250)
 
penup()
speed(0)
left(180)
fd(250)
circle(-300,7)
right(80)
circle(200,5)
pendown()
 
left(60)
begin_fill()
fillcolor('green')
circle(-80,100)
right(90)
fd(10)
left(20)
circle(-63,127)
end_fill()
 
penup()
left(50)
fd(20)
left(180)
 
pendown()
circle(200,25)
 
penup()
right(150)
 
fd(180)
 
right(40)
pendown()
begin_fill()
fillcolor('green')
circle(-100,80)
right(150)
fd(10)
left(60)
circle(-80,98)
end_fill()
 
penup()
left(60)
fd(13)
left(180)
 
pendown()
speed(1)
circle(-200,23)
 
 
 
exitonclick()


效果图:


使用Python画一朵美丽的玫瑰花


源码二


import turtle
import math



def p_line(t, n, length, angle):
    """Draws n line segments."""
    for i in range(n):
        t.fd(length)
        t.lt(angle)



def polygon(t, n, length):
    """Draws a polygon with n sides."""
    angle = 360 / n
    p_line(t, n, length, angle)



def arc(t, r, angle):
    """Draws an arc with the given radius and angle."""
    arc_length = 2 * math.pi * r * abs(angle) / 360
    n = int(arc_length / 4) + 1
    step_length = arc_length / n
    step_angle = float(angle) / n


    # Before starting reduces, making a slight left turn.
    t.lt(step_angle / 2)
    p_line(t, n, step_length, step_angle)
    t.rt(step_angle / 2)



def petal(t, r, angle):
    """Draws a 花瓣 using two arcs."""
    for i in range(2):
        arc(t, r, angle)
        t.lt(180 - angle)



def flower(t, n, r, angle, p):
    """Draws a flower with n petals."""
    for i in range(n):
        petal(t, r, angle)
        t.lt(p / n)



def leaf(t, r, angle, p):
    """Draws a 叶子 and fill it."""
    t.begin_fill()  # Begin the fill process.
    t.down()
    flower(t, 1,

首页 上一页 1 2 下一页 尾页 1/2/2
】【打印繁体】【投稿】【收藏】 【推荐】【举报】【评论】 【关闭】 【返回顶部
上一篇C++与Python混合编程:Boost.Pyth.. 下一篇练习使用 __attribute__ 属性(仿..

最新文章

热门文章

Hot 文章

Python

C 语言

C++基础

大数据基础

linux编程基础

C/C++面试题目