1. 本际云推荐 - 专业推荐VPS、服务器,IDC点评首页
  2. 云主机运维
  3. VPS运维

python绘制神器五角星+小黄人+樱花方法介绍

关于python绘图的艺术美

我是本际云服务器推荐网的小编小本本,今天给大家分享一些关于python绘图的艺术美。在数学中有一种美,叫几何美,我们又称为艺术美,用具有规律的线条,迭代出美丽的图片,这就是许多艺术家在创作是的灵感渠道。

python绘制神器五角星+小黄人+樱花方法介绍

绘图案例

下面将给大家介绍一个简单的绘制五角星的案例:

import turtle

def draw_recursive_pentargram(size):
    
    count=1
    while count<=5:
        turtle.backward(size)
        turtle.right(144)
        count+=1
        
    size+=10
    if size<=100:
        draw_recursive_pentargram(size)

def main():
    
    turtle.speed(0)
    turtle.pensize(2)
    turtle.pencolor("red")
    turtle.bgcolor('black')
    size=50
    draw_recursive_pentargram(size)
    turtle.exitonclick()

if __name__=="__main__":
    main()

另外,下面还有两个比较复杂的案例,分别是绘制小黄人和樱花:

绘制小黄人

import turtle

t=turtle.Turtle()
wn=turtle.Screen()
turtle.colormode(255)
t.hideturtle()
t.speed(10)

# 代码略,详情见原文
turtle.exitonclick()

绘制樱花

import turtle as T
import random
import time

def Tree(branch,t):
time.sleep(0.0005)
if branch>3:
if 8<=branch<=12:
if random.randint(0,2)==0:
t.color('snow')
else:
t.color('lightcoral')
t.pensize(branch/3)
elif branch<8:
if random.randint(0,1)==0:
t.color('snow')
else:
t.color('lightcoral')
t.pensize(branch/2)
else:
t.color('sienna

原创文章,作者:小编小本本,如若转载,请注明出处:https://www.benjiyun.com/yunzhujiyunwei/vps-yunwei/7300.html