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为移动距离




  • 5
    点赞
  • 4
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值