turtle

Python画樱花树 !

北城余情 提交于 2019-11-28 17:06:49
Python的turtle模块肯定很棒吧!这次,我们要利用turtle来完成一个樱花树的绘制。我们要用def和for语句循环。 难度等级: Python资源共享群:626017123 工具:turtle、random 我用的是Python 3.8.0b3 Shell,开始写代码吧! # 樱花树 import randomimport turtle Jess = turtle.Turtle()Jess.hideturtle()Jess.left(90)Jess.penup()Jess.goto(0, -100)Jess.pendown() # “画树”函数# 参数分别是树枝长度、画笔def tree(branchLen, t): if (branchLen > 3): if (8 <= branchLen and branchLen <= 12) : if (random.randint(0, 2) == 0) : Jess.pencolor('snow') else : Jess.pencolor('lightcoral') Jess.pensize((branchLen / 3)) elif (branchLen < 8) : if (random.randint(0, 1) == 0) : Jess.pencolor('snow') else : Jess.pencolor(

画图

让人想犯罪 __ 提交于 2019-11-28 07:52:04
import turtle turtle.setup(800,800,200,200) turtle.pencolor('red') turtle.pensize(5) turtle.penup() turtle.fd(-200) turtle.pendown() turtle.circle(50,360) turtle.pencolor('green') turtle.penup() turtle.fd(100) turtle.pendown() turtle.circle(50,360) turtle.pencolor('black') turtle.penup() turtle.fd(-100) turtle.right(90) turtle.fd(35) turtle.pendown() turtle.circle(50,360) turtle.pencolor('yellow') turtle.penup() turtle.fd(53) turtle.right(-90) turtle.fd(50) turtle.pendown() turtle.circle(110,360) turtle.done() 来源: https://www.cnblogs.com/zhangjianguoweiwei/p/11400286.html