文章目录
粉色五角星
- 粉色五角星
- 连续五个随机颜色五角星
- 红色玩具车
- 高度旋转堆叠的正方形组
- K阶科赫雪花
- 斜分绿树
- 分形树
- 分形心
- 谢尔平斯基三角形
- 紫色小蛇
- 随机色旋转图形
- 小猪佩奇
import turtle
def drawFivePointStar(t, x, y, lengthOfSide):
# 从(x, y)向东南方向出发
t.up()
t.goto(x, y)
t.left(36)
t.down()
for i in range(5):
t.forward(lengthOfSide)
# 144 = 180 - 36
t.left(144)
myTurtle = turtle.Turtle()
myTurtle.hideturtle()
myTurtle.color("deeppink")
myWindow = myTurtle.getscreen()
lengthOfSide = 200
drawFivePointStar(myTurtle, 0, 0, lengthOfSide)
myWindow.exitonclick()
from turtle import *
from random import randint
def drawStar(x, y):
pu()
goto(x, y)
pd()
colormode(255)
# set heading: 0
seth(0)
for i in range(5):
r = randint(0, 255)
g = randint(0, 255)
b = randint(0, 255)
pencolor(r, g, b)
fd(40)
rt(144)
hideturtle()
for x in range(0, 250, 50):
drawStar(x, 0)
done()
import turtle
t = turtle.Pen()
t.color(1,0,0)
t.begin_fill()
t.forward(100)
t.left(90)
t.forward(20)
t.left(90)
t.forward(20)
t.right(90)
t.forward(20)
t.left(90)
t.forward(60)
t.left(90)
t.forward(20)
t.right(90)
t.forward(20)
t.left(90)
t.forward(20)
t.end_fill()
t.color(0,0,0)
t.up()
t.forward(10)
t.down()
t.begin_fill()
t.circle(10)
t.end_fill()
t.setheading(0)
t.up()
t.forward(90)
t.right(90)
t.forward(10)
t.setheading(0)
t.begin_fill()
t.down()
t.circle(10)
t.end_fill()
t.hideturtle()
import turtle
for i in range(360):
turtle.setheading(i)
for i in range(4):
turtle.forward(100)
turtle.left(90)
import turtle
def koch(len, n):
if n == 0:
turtle.fd(len)
else:
for i in [0, 60, -120, 60]:
turtle.left(i)
koch(len/3, n-1)
level = int(input())
turtle.penup()
turtle.goto(-250, 150)
turtle.pensize(2)
turtle.color('orange')
turtle.pendown()
koch(500, level)
turtle.right(120)
koch(500, level)
turtle.right(120)
koch(500, level)
turtle.right(120)
turtle.hideturtle()
turtle.done()
三阶科赫雪花:
五阶科赫雪花:
from turtle import *
# 递归绘制一棵树
def tree(branchLength, turtle):
if branchLength > 5:
turtle.forward(branchLength)
turtle.right(20)
tree(branchLength-15, turtle)
turtle.left(40)
tree(branchLength-10, turtle)
turtle.right(20)
turtle.backward(branchLength)
myTurtle = Turtle()
myWindow = myTurtle.getscreen()
myTurtle.hideturtle()
myTurtle.left(90)
myTurtle.up()
myTurtle.backward(300)
myTurtle.down()
myTurtle.color('green')
tree(110, myTurtle)
from turtle import *
# 设置色彩模式是RGB:
colormode(255)
lt(90)
lv = 14
l = 120
s = 45
width(lv)
# 初始化RGB颜色:
r = 0
g = 0
b = 0
pencolor(r, g, b)
penup()
bk(l)
pendown()
fd(l)
def draw_tree(l, level):
global r, g, b
# save the current pen width
w = width()
# narrow the pen width
width(w * 3.0 / 4.0)
# set color:
r = r + 1
g = g + 2
b = b + 3
pencolor(r % 200, g % 200, b % 200)
l = 3.0 / 4.0 * l
lt(s)
fd(l)
if level
关注
打赏
热门博文
- 【Linux】Ubuntu20.04安装和卸载MySQL8
- 【Linux】Ubuntu 20.04 报错 curl: (23) Failure writing output to destination 的解决方法
- 【Java】JUnit 4.13.2 警告 ‘assertEquals(double, double)‘ is deprecated 的解决方法
- 【JavaScript】处理 @parcel/transformer-js: Browser scripts cannot have imports or exports.
- 【Python】处理TypeError: Plain typing.NoReturn is not valid as type argument
- 【Python】Matplotlib可视化50例
- 【C语言】C语言修改MySQL数据库
- 【Java】从默认包导入类和对象报错的解决方法
- 【Java】panel.getGraphics()报错空指针异常的解决方法
- 【Java】IDEA编译Java项目报错 java: 找不到符号 的解决方法