【有意思的python】用turtle画多朵花
以下代码用python的turtle库随机画出多10朵不同颜色、大小、位置的花~虽然看起来更像病毒的形状,哈哈哈····
import turtle
import random
def rgb_to_hex(r, g, b):
return '#{:02x}{:02x}{:02x}'.format(r, g, b)
def random_color():
r = random.randint(0, 255)
g = random.randint(0, 255)
b = random.randint(0, 255)
return (r, g, b)
canvas = turtle.Screen()
pen = turtle.Turtle()
for i in range(10):
size = random.randint(50, 150)
x = random.randint(-200, 200)
y = random.randint(-200, 200)
pen.penup()
pen.goto(x, y)
pen.pendown()
pen.color(rgb_to_hex(*random_color()))
pen.shape('turtle')
pen.begin_fill()
for i in range(36):
pen.forward(size)
pen.left(170)
pen.end_fill()
pen.hideturtle()
canvas.exitonclick()
相关知识
python画玫瑰花代码简单
python玫瑰花代码简单
python turtle玫瑰花绘制效果和源代码
【中秋征文】使用Python创意中秋节画月饼《花好月圆》
【Python实用工具】(情人节献礼)turtle函数绘制动态玫瑰花
【python】turtle龟绘制开了花朵的树,程序画图
python玫瑰花代码讲解
python画一朵花的代码
情人节用Python画玫瑰花
用python画花瓣
原文链接: 【有意思的python】用turtle画多朵花 https://www.huajiangbk.com/newsview565442.html
| 上一篇: 中班美术公开课教案及教学反思《老... | 下一篇: 【Python入门】Turtle... |
推荐分享

- 1明日花キララ:明日花绮罗年度... 17983
- 2明日花キララ(明日花绮罗)经... 10344
- 3兰花叶子扭的是什么兰 8086
- 4君子兰什么品种最名贵 十大名... 6709
- 5十大致癌花卉排行榜,哪些花卉... 6420
- 6李晓明工笔牡丹(魏紫)《牡丹... 6184
- 7家庭养花知识大全 家庭养花有... 5779
- 8家庭养花风水知识 家庭养花“... 5509
- 9花圈挽联怎么写? 5022
- 10世界上最名贵的10种兰花图片... 4880




