赞
踩
大家好,本文将围绕python好看图案的编程代码展开说明,python简单图案代码小熊是一个很多人都想弄明白的事情,想搞清楚python简单图案代码turtle需要先了解以下几个事情。
Source code download: 本文相关源码
1、python画迪斯科灯
- import turtle
- import math
- import random
- #color = ['green','red','blue','yellow','orange','pink']
- pen = turtle.Turtle()
- turtle.colormode(255)
- rr = 3
- theta = 0
- pi = 3.1415926
- pen.pensize(5)
- pen.speed(0)
- pen.left(90)
- for j in range(60):
- r = random.randint(0,255)
- g = random.randint(0,255)
- b = random.randint(0,255)
- pen.penup()
- pen.goto(0,0)
- pen.down()
- #pen.pencolor(color[j%6])
- pen.pencolor((r,g,b))
- pen.penup()
- pen.goto(60*math.sin(2*pi/60*j),60*math.cos(2*pi/60*j))
- pen.down()
- #pen.reset()
- #pen.left(6)
- pen.forward(random.randint(20,80))
- pen.setheading(90)
- pen.right(6*j)
- #theta = 6 * j
- turtle.done()
2、Python画随机雨点
- import turtle
- import math
- import random
- pen = turtle.Turtle()
- turtle.colormode(255)
- rr = 20
- #theta = 0
- #pi = 3.1415926
- pen.pensize(5)
- pen.speed(0)
- r = 100
- g = 100
- b = 150
- dd0 = 20
- dd = 30
- for j in range(20):
- rr = 20
- r = 100
- g = 100
- b = 150
- dd0 = 20
- dd = 30
- x = random.randint(-300,300)
- y = random.randint(-300,300)
- for i in range(10):
- pen.color((r,g,b))
- pen.penup()
- #pen.goto(0,dd0+dd)
- pen.goto(x,y+dd0-2*(11-i))
- pen.down()
- pen.dot(rr)
- #dd = dd - 3
- rr = rr -2
- r = r + 6
- b = b + 6
- turtle.done()
3、Python画五彩螺旋
- from turtle import *
- colors = ['red', 'purple', 'blue', 'green', 'yellow', 'orange']
- for x in range(360):
- pencolor(colors[x % 6])
- width(x / 100 + 1)
- forward(x)
- left(59)
- speed(0)
- done()
五彩螺旋2
- import turtle
- color = ['green','red','blue','yellow','orange','pink']
- pen = turtle.Turtle()
- rr = 3
- pen.pensize(3)
- pen.speed(0)
- for j in range(20):
- for i in range(5):
- rr = rr + 2
- pen.pencolor(color[i])
- pen.forward(rr)
- pen.left(36) # 61 84 6
- pen.pencolor(color[5])
- pen.forward(rr)
- pen.left(36)
- rr = rr + 2
- turtle.done()
Copyright © 2003-2013 www.wpsshop.cn 版权所有,并保留所有权利。