赞
踩
本来这篇文章是想六一那天发的,但是忘记了,今天才想起来。
提后祝大家六一快乐!
废话不多说,我们放战歌!
- import random
- import turtle
-
- __Pen = turtle.Pen()
-
-
- # 分形樱花树
-
- # “画树”函数
- # 参数分别是树枝长度、画笔
-
- def tree(branchLen, t):
- if (branchLen > 3):
- if (8 <= branchLen and branchLen <= 12) :
- if (random.randint(0, 2) == 0) :
- t.pencolor('snow')
- else :
- t.pencolor('lightcoral')
- t.pensize((branchLen / 3))
- elif (branchLen < 8) :
- if (random.randint(0, 1) == 0) :
- t.pencolor('snow')
- else :
- t.pencolor('lightcoral')
- t.pensize((branchLen / 2))
- else :
- t.pencolor('sienna')
- t.pensize((branchLen / 10))
- t.forward(branchLen)
- a = (1.5 * (random.random()))
- t.right((20 * a))
- b = (1.5 * (random.random()))
-
- # 递归
- tree(branchLen - 10 * b, t)
- t.left((40 * a))
- tree(branchLen - 10 * b, t)
- t.right((20 * a))
- t.penup()
- t.backward(branchLen)
- t.pendown()
-
- # 绘制树下花瓣,参数分别是画板数、画笔
-
- def petal(m, t):
- for i in range(m):
- a = (200 - 400 * (random.random()))
- b = (10 - 20 * (random.random()))
- t.penup()
- t.forward(b)
- t.left(90)
- t.forward(a)
- t.pendown()
- t.pencolor('lightcoral')
- t.circle(1)
- t.penup()
- t.backward(a)
- t.right(90)
- t.backward(b)
-
- def main():
- t = turtle.Pen()
- __Pen.hideturtle()
- t.speed(0)
- turtle.bgcolor('wheat')
- t.left(90)
- t.penup()
- t.backward(150)
- t.pendown()
- t.pencolor('sienna')
- tree(60, t)
- petal(100, t)
- turtle.done()
-
- main()
彩色弹球
- import turtle
-
- __Pen = turtle.Pen()
-
-
- # 彩色弹球
- t = turtle.Pen()
- t.speed(0)
- turtle.bgcolor('black')
- # 更改sides变量,可以画出完全不同的图形哦
- # 改为2、3、4、5、6等,看看效果吧
- sides = 9
- colors = ['red','yellow','blue','orange','green','purple','cyan','white','grey']
- for x in range(360):
- t.pencolor(colors[(x % sides)])
- t.forward(((x * 3) / sides + x))
- t.left((360 / sides + 1))
- t.pensize(((x * sides) / 200))
- t.left(90)
- turtle.done()
螺旋线
- from turtle import *
- speed(0)
- bgcolor('black')
- pencolor('white')
- for x in range(1000):
- forward(x)
- left(59)
- done()
新冠病毒(乱入)
- from turtle import *
-
- bgcolor("black")
- n = 0
- speed(0)
- colormode(255)
- while n < 200:
- left(n)
- forward(n * 3)
- color(n, 255-n, n % 30*8)
- n += 1
- done()
小太阳
- from turtle import *
-
- pencolor("yellow")
-
- n = 0
- speed(0)
-
- while n < 36:
- for m in range(4):
- forward(100)
- left(90)
- left(10)
- done()
Copyright © 2003-2013 www.wpsshop.cn 版权所有,并保留所有权利。