python画圣诞树_python画圣诞树
使用python画一棵圣诞树
height = 5stars = 1for i in range(height): print((' ' * (height - i)) + ('*' * stars)) stars += 2print((' ' * height) + '|')
效果
高级做法
from turtle import *from shapes import *from random import randintmyPen = Turtle()myPen.shape("turtle")myPen.speed(10)window = turtle.Screen()window.bgcolor("#69D9FF")y = -100width = 240#let's draw the trunk of the treedraw_rectangle(myPen, "brown", -15, y-40, 30, 40)#Now the tree itselfwhile width>20: width = width - randint(20,30) height = randint(15,35) x = 0 - width/2 draw_rectangle(myPen, "green", x, y, width, height) y = y + height#And finally let's add a star at the top of our tree.draw_star(myPen, "yellow", 4, y, 20)myPen.penup()myPen.color("red")myPen.goto(-100, -180)myPen.write("Merry Christmas", None, None, "24pt bold")myPen.hideturtle()
import turtledef draw_circle(turtle, color, x, y, radius): turtle.penup() turtle.color(color) turtle.fillcolor(color) turtle.goto(x,y) turtle.pendown() turtle.begin_fill() turtle.circle(radius) turtle.end_fill() def draw_triangle(turtle, color, x, y, size): turtle.penup() turtle.color(color) turtle.fillcolor(color) turtle.goto(x,y) turtle.pendown() turtle.begin_fill() for i in range (3): turtle.forward(size) turtle.left(120) turtle.end_fill() turtle.setheading(0) def draw_square(turtle, color, x, y, size): turtle.penup() turtle.color(color) turtle.fillcolor(color) turtle.goto(x,y) turtle.pendown() turtle.begin_fill() for i in range (4): turtle.forward(size) turtle.left(90) turtle.end_fill() turtle.setheading(0) def draw_rectangle(turtle, color, x, y, width, height): turtle.penup() turtle.color(color) turtle.fillcolor(color) turtle.goto(x,y) turtle.pendown() turtle.begin_fill() for i in range (2): turtle.forward(width) turtle.left(90) turtle.forward(height) turtle.left(90) turtle.end_fill() turtle.setheading(0) def draw_star(turtle, color, x, y, size): turtle.penup() turtle.color(color) turtle.fillcolor(color) turtle.goto(x,y) turtle.pendown() turtle.begin_fill() turtle.right(144) for i in range(5): turtle.forward(size) turtle.right(144) turtle.forward(size) turtle.end_fill() turtle.setheading(0)
图片效果
视频效果后续发。。。。
python画圣诞树_python画圣诞树相关推荐
- python代码画乌龟_python画乌龟
广告关闭 腾讯云11.11云上盛惠 ,精选热门产品助力上云,云服务器首年88元起,买的越多返的越多,最高返5000元! 效果展示 turtle库是python语言中一个很流行的绘制图像的函数库,想象一 ...
- python画箭头_python画折线示意图实例代码
python画折线图方法 前做PPT要用到折线图,嫌弃EXCEL自带的看上去不好看,就用python写了一个画折线图的程序. import matplotlib.pyplot as plt x=[1, ...
- python樱花卡片_Python画一棵漂亮的樱花树(不一样种樱花+玫瑰+圣诞树喔)
很多用Python(大可能是turtle库)绘制的树图,感受很漂亮,我整理了一下,挑了一些我以为不错的代码分享给你们(这些我都测试过,确实能够生成喔~) one 樱花树html 动态生成樱花 效果图( ...
- python话圣诞树_python画圣诞树
今天是圣诞节,送你一棵圣诞树,圣诞节快乐!! 源代码领取↓(直接复制粘贴即可) # -*- coding: utf-8 -*- from turtle import * from random imp ...
- python画蝴蝶_python画蝴蝶曲线图的实例
蝴蝶曲线是由Temple H·Fay发现的可用极坐标函数表示的蝴蝶曲线. 由于此曲线优美, 因此就想把它作为博客favicon.ico,这里我使用pytho matplotlib.pyplot包来绘制 ...
- python turtle画五边形_python画一朵玫瑰给你
听说 python 还能画画?是的,今天亲手画一朵玫瑰给你. turtle 是 python 中一个强大的绘制图像的库,可以用来绘制各种图像,使用起来很方便. 但是需要计算各种角度.距离等,所以要想完 ...
- python画离散点_python画散点图
Python发射导弹的正确方式 今天Toby教你如何用python的basemap包绘制轰炸东京的地图. 在数据可视化过程中,我们常常需要将数据根据其采集的地理位置在地图上显示出来.比如说我们会想要在 ...
- python散点图解_python 画三维图像 曲面图和散点图的示例
用python画图很多是根据z=f(x,y)来画图的,本博文将三个对应的坐标点输入画图: 散点图: import matplotlib.pyplot as plt from mpl_toolkits. ...
- python 画蝴蝶_python画蝴蝶曲线图的实例
蝴蝶曲线是由Temple H·Fay发现的可用极坐标函数表示的蝴蝶曲线. 由于此曲线优美, 因此就想把它作为博客favicon.ico,这里我使用pytho matplotlib.pyplot包来绘制 ...
最新文章
- HTML的标签描述15
- Win7 OBJECT_HEADER之TypeIndex解析
- 线上SQL脚本执行错了出事之后互相甩锅怎么办?
- 【模型解读】从LeNet到VGG,看卷积+池化串联的网络结构
- Spring Cloud Alibaba 简介
- 企业建设呼叫中心需要考虑哪些因素
- 链家大数据多维分析引擎实践
- LeetCode-1208:尽可能使字符串相等
- 2016.05.17开通自己的博客
- Atitit 登录账号管理法passport 目录 1. 总则	1 1.1. 身份分类登录账号 管理员 操作人员 普通用户	1 1.2. 安全考虑,必须单独分开的账号储存表,使用不同等加密技术与秘
- ubuntu中wps字体添加
- 产品经理十七章:结构化发散思维
- 【UEFI实战】HII之配置
- JAVA复习:8进制与16进制
- 追女孩的九大禁忌!!!
- 网易科技《美好实验室》内容品牌发布,好产品缔造美好生活
- 为什么恒压驱动电源会缩短LED的使用寿命?
- RS-232C接口定义(DB9与DB25)常用引脚定义
- JSVC简介之快速入门
- 防抖与节流(鼠标移入事件每隔一段时间执行)
热门文章
- java中字符类型的转换
- 指针变量本质(四十三)
- 报错:/check/src/check_log.c:27:10: 致命错误: subunit/child.h:没有那个文件或目录
- ARM指令ldr、str、stm、ldm理解
- iOS获取camera的yuv数据
- C++之基类构造函数初始化
- 深度学习自学(二十九):上下文感知和对规模不敏感的动作重复计数
- win10磁盘管理界面各系统分区介绍
- python创建字符串_Python基础之字符串
- php中怎么判断输入密码与原密码一致_「每周FPGA案例」电子密码锁设计