(编辑:jimmy 日期: 2024/11/14 浏览:2)
本文实例为大家分享了Python画圣诞树的具体代码,供大家参考,具体内容如下
源代码
from turtle import * import random import time #from unittest.mock import right #import color as color #import down as down #from cv2.cv2 import circle n = 80.0 speed("fastest") screensize(bg='seashell') left(90) forward(3*n) color("orange", "yellow") begin_fill() left(126) for i in range(5): forward(n/5) right(144) forward(n/5) left(72) end_fill() right(126) color("dark green") backward(n*4.8) def tree(d, s): if d <= 0: return forward(s) tree(d-1, s*.8) right(120) tree(d-3, s*.5) right(120) tree(d-3, s*.5) right(120) backward(s) tree(15, n) backward(n/2) for i in range(200): a = 200 - 400 * random.random() b = 10 - 20 * random.random() up() forward(b) left(90) forward(a) down() if random.randint(0, 1) == 0: color('tomato') else: color('wheat') circle(2) up() backward(a) right(90) backward(b) time.sleep(60) write("author:超哥。圣诞节快乐!!!", move=True, align="left", font=("宋体", 30, "normal")) done()
运行的结果为
其实是动态图,这是最终的结果。
祝大家圣诞节快乐
以上就是本文的全部内容,希望对大家的学习有所帮助,也希望大家多多支持。