python学习之表白的爱心图形

主要是利用turtle这个库,turtle-海龟渲染器,不多介绍。

from turtle import *
setup(500,500)
pencolor('pink')
fillcolor('red')
begin_fill()
left(140)
forward(111.65)
for i in range(200):
    right(1)
    forward(1)
left(120)
for i in range(200):
    right(1)
    forward(1)
forward(111.65)
end_fill()
hideturtle()
done()

实现效果:
python学习之表白的爱心图形_第1张图片
当然,需要特别的“爱”的人,
可以这样:

pencolor('blue')
fillcolor('green')

python学习之表白的爱心图形_第2张图片
再来一个升级版:

from turtle import *
from time import sleep
def go_to(x, y):
    up()
    goto(x, y)
    down()
def big_Circle(size):  
    speed(1)
    for i in range(150):
        forward(size)
        right(0.3)
def small_Circle(size):  
    speed(1)
    for i in range(210):
        forward(size)
        right(0.786) 
def line(size):
    speed(1)
    forward(51*size)
def heart( x, y, size):
    go_to(x, y)
    left(150)
    begin_fill()
    line(size)
    big_Circle(size)
    small_Circle(size)
    left(120)
    small_Circle(size)
    big_Circle(size)
    line(size)
    end_fill()
def arrow():
    pensize(10)
    setheading(0)
    go_to(-400, 0)
    left(15)
    forward(150)
    go_to(339, 178)
    forward(150)
def arrowHead():
    pensize()
    speed(1)
    color('red', 'red')
    begin_fill()
    left(120)
    forward(20)
    right(150)
    forward(35)
    right(120)
    forward(35)
    right(150)
    forward(20)
    end_fill()
def main():
    pensize(2)
    color('red', 'pink')
    #getscreen().tracer(30, 0) 
    heart(200, 0, 1)          
    setheading(0)             
    heart(-80, -100, 1.5)     
    arrow()                   
    arrowHead()              
    go_to(400, -300)
    write("by:wuluo", move=True, align="left", font=("宋体", 30, "normal"))
    done()
main()

实现效果:
python学习之表白的爱心图形_第3张图片
后面,有时间在介绍其它的。

你可能感兴趣的:(wuluo,python3)