赞
踩
当圣诞节遇上考研、遇上海龟绘图,于是有了本文的内容。圣诞节是固定的12月25日,而考研是12月底的某个周末。能不能用Python制作一个祝福呢。
Turtle库:Turtle(海龟)绘图很适合用来引导孩子学习编程,最初来自于 Wally Feurzeig, Seymour Papert 和 Cynthia Solomon 于 1967 年所创造的 Logo 编程语言。使用Turtle绘图可以编写重复执行简单动作的程序画出精细复杂的形状。
本文就利用Python语言内置的专门用来绘图的库,绘制一幅圣诞节暨考研祝福的程序画。
1、小猪佩奇、多啦爱梦、比卡丘:
https://blog.csdn.net/meenr/article/details/107245170
2、
https://blog.csdn.net/meenr/article/details/122851283
3、
https://blog.csdn.net/meenr/article/details/123166425
文末更多内容公众号中可直接下载py文件,篇幅有限,本文仅仅粘贴了一部分代码。
# -*- coding: utf-8 -*- """============================== #@Project : TurtleEg #@File : 圣诞 #@Software: PyCharm #@Author : Echo #@Email : robot1483693261@163.com #@Date : 2022/12/25 21:09 #@Desc : ==============================""" import turtle as t from turtle import * import random as r import time t.title("2贰进制") t.tracer(False) t.screensize(bg='black') n = 100.0 t.left(90) t.forward(3 * n) t.color("orange", "yellow") t.begin_fill() t.left(126) for i in range(5): t.forward(n / 5) t.right(144) t.forward(n / 5) t.left(72) t.end_fill() t.right(126) def lights(): if r.randint(0, 30) == 0: t.color('tomato') t.circle(6) elif r.randint(0, 30) == 1: t.color('orange') t.circle(3) else: t.color('dark green') t.color("dark green") t.backward(n * 4.8) def trees(d, s): if d <= 0: return t.forward(s) tree(d - 1, s * .8) t.right(120) trees(d - 3, s * .5) lights() t.right(120) trees(d - 3, s * .5) t.right(120) t.backward(s)
公众号地址:
https://mp.weixin.qq.com/s/ynG-dNNqO8kjIdf6ZFiZbg
CSDN主页地址:
https://blog.csdn.net/meenr
Copyright © 2003-2013 www.wpsshop.cn 版权所有,并保留所有权利。