zoukankan      html  css  js  c++  java
  • turtle库基本使用

    import turtle as t

    画笔控制函数:

    t.penup()  抬起笔  别名:t.pu()

    t.pendown()  落下笔  别名: t.pd()

    t.pensize(2) 设置画笔粗细   别名:t.width(width)

    Example:
    >>> pensize()
    1
    >>> pensize(10) # from here on lines of width 10 are drawn

    t.pencolor(color)  画笔颜色  color是颜色字符串或rgb值  color有3种形式:颜色字符串  t.pencolor('purple')     rgb小数值,rgb元组值 t.pencolor(0.1,0.5,1)   t.pencolor((0.1,0.5,1))

    t.color('red','red)  设置画笔颜色和填充颜色

    Example:
    >>> color('red', 'green')
    >>> color()
    ('red', 'green')
    >>> colormode(255)
    >>> color((40, 80, 120), (160, 200, 240))
    >>> color()
    ('#285078', '#a0c8f0')

    t.begin_fill()  在绘制要填充的形状之前调用。t.end_fill() 填充调用begin_fill()后绘制的形状

    Example:
    >>> color("black", "red")
    >>> begin_fill()
    >>> circle(60)
    >>> end_fill()

    运动控制函数

    t.fd(100)  向前走100像素

    t.bk(40)  后退

    t.circle(10)   圆心在海龟左侧10像素的圆

    circle(radius, extent=None, steps=None)  半径,角度,边数
    Draw a circle with given radius.

    >>> t.circle(50,360,6)
    >>> t.circle(50,180,6)
    >>> t.circle(50,180,6)

     方向控制函数

    t.seth(-40)   行进方向角度的绝对坐标

    t.left(30)   基于当前角度向左转30度

    t.right(20) 基于当前角度向右转20度

  • 相关阅读:
    gerrit权限控制
    kvm虚拟机根目录磁盘扩容
    vim新手指南
    精通 vim 你应该理解的几个名词
    精通 VIM ,此文就够了
    linux下库的使用--动态库
    linux下库的使用--静态库
    linux下程序编译的各个阶段记录
    ASCII码表
    重构的过程记录--之利用系统数据库:
  • 原文地址:https://www.cnblogs.com/lisi01/p/9902521.html
Copyright © 2011-2022 走看看