用python画一些有趣的图案(001)

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() 

用python画一些有趣的图案(001)_第1张图片

 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()

用python画一些有趣的图案(001)_第2张图片

 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() 

用python画一些有趣的图案(001)_第3张图片

五彩螺旋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()

 用python画一些有趣的图案(001)_第4张图片

 

你可能感兴趣的:(Python,编程和应用实现,python,开发语言,几何学)