python画等边三角形及彩蟒

python turtle 库 介绍

控制画笔绘制状态的函数
pendown() | pd() | down()
penup() | pu() | up()
pensize(wid ) | width(wid)
forward(distance) | fd(distance)
backward(distance)| bk(distance)
|back(distance)
right(angle) | rt(angle)
left(angle) | lt(angle)
setheading(to_angle)
position() | pos()
goto(x,y )
setposition(x,y ) | setpos(x,y )
circle(radius,extent ,steps )
dot(size ,*color) radians()
stamp() speed(speed )
clearstamp(stamp_id)
clearstamps(n ) undo()
speed(speed ) heading()
towards(x,y ) distance(x,y )
xcor() ycor()
setx(x) sety(y)
home() undo()
degrees(fullcircle = 360.0)
控制画笔运动的函数
控制画笔颜色和字体函数
color()  reset()
begin_fill()  end_fill()
filling()  clear()
screensize()
showturtle() | st()
hideturtle() | ht()
isvisible()
write(arg,move=False,align="left"
,font =("Arial",8,"normal") )
>>>import turtle
>>>from turtle import *
引入方式
bgcolor(*args)
bgpic(picname )
clearscreen()
resetscreen()
screensize(cwid ,canvh,bg )
tracer(n ,delay )
listen(xdummy ,ydummy )
onkey((fun,key)
onkeyrelease((fun,key)
onkeypress(fun,key )
onscreenclick(fun,btn=1,add )
TurtleScreen/Screen类的函数
getcanvas()
getshapes()
turtles()
window_height()
window_width()
bye()
exitonclick()
title(titlestring)
setup(wid=_CFG["wid"],h=_CFG["h"],
startx=_CFG["leftright"],
starty=_CFG["topbottom"])
turtle库
Python Quick Reference Series Python快速参考
python绘制等边三角形

import turtle
import random    
def drawsnake(rad):
    turtle.fd(rad)
    turtle.seth(120)
    turtle.fd(rad)
    turtle.seth(-120)
    turtle.fd(rad)

def main():
    turtle.setup(1300,800,0,0)
    pythonsize = 30
    turtle.pensize(1)
    c = random.uniform(0,1)
    d = random.randint(0,1)
    e = random.randint(0,1)
    f = (c,d,e)
    turtle.pencolor(f)
    turtle.seth(0)
    drawsnake(pythonsize * 6)
main()
python绘制彩蟒

import turtle
import random    
def drawsnake(rad,angle,len,neckrad):
    for i in range(len):
        c = random.uniform(0,1)
        d = random.randint(0,1)
        e = random.randint(0,1)
        f = (c,d,e)
        turtle.pencolor(f)
        turtle.circle(rad,angle)
        c = random.uniform(0,1)
        d = random.randint(0,1)
        e = random.randint(0,1)
        f = (c,d,e)
        turtle.pencolor(f)
        turtle.circle(-rad,angle)
    c = random.uniform(0,1)
    d = random.randint(0,1)
    e = random.randint(0,1)
    f = (c,d,e)
    turtle.pencolor(f)
    c = random.uniform(0,1)
    d = random.randint(0,1)
    e = random.randint(0,1)
    f = (c,d,e)
    turtle.pencolor(f)
    turtle.circle(rad,angle/2)
    c = random.uniform(0,1)
    d = random.randint(0,1)
    e = random.randint(0,1)
    f = (c,d,e)
    turtle.pencolor(f)
    turtle.fd(rad)
    c = random.uniform(0,1)
    d = random.randint(0,1)
    e = random.randint(0,1)
    f = (c,d,e)
    turtle.pencolor(f)
    turtle.circle(neckrad+1,180)
    c = random.uniform(0,1)
    d = random.randint(0,1)
    e = random.randint(0,1)
    f = (c,d,e)
    turtle.pencolor(f)
    turtle.fd(rad*2/3)

def main():
    turtle.setup(1300,800,0,0)
    pythonsize = 30
    turtle.pensize(pythonsize)
    c = random.uniform(0,1)
    d = random.randint(0,1)
    e = random.randint(0,1)
    f = (c,d,e)
    turtle.pencolor(f)
    turtle.seth(-220)
    drawsnake(40,80,5,pythonsize/2)
main()
turtle库

turtle.setup(width,height,x,y)
   启动一个图形窗口 参数为窗口的宽度、长度,以及窗口在屏幕上的左上角

turtle.pensize( width)
   运动轨迹的宽度

turtle.pencolor(color)
   运动轨迹的颜色

turtle.seth(angle)
   运动启动时的运动方向 0 表示 向东;90 向北,180 向西;270向南;负值表示反方向

turtle.circle(rad,angle)
   以圆为轨迹 rad表示半斤,angle表示角度

turtle.fd(rad)
   以直线为轨迹 rad为移动距离




你可能感兴趣的:(python学习,python,算法,等边三角形绘制,彩蟒绘制,turtle介绍)