• python--turtle画图


    Turtle 语法

    解释

    例子

    turtle.bgcolor("red ")

    画布背景颜色

     
    turtle.setup(width=800,height=600,startx=None,starty=None)
    当宽和高为整数时, 表示像素; 
    当宽和高为小数时, 表示占据电脑屏幕的比例,
    startx, starty表示矩形窗口左上角顶点的位置, 如果为空,则窗口位于屏幕中心
     
    turtle.up()

    拿起笔

    联用形式
    turtle.up()
    turtle.goto(x1,y1)

    turtle.down()

    turtle.goto(x1,y1)

    到某一点

    turtle.down()                                                                                                                                                                                                                          

    放下笔

    turtle.begin_fill()

    开始填充
    turtle.begin_fill()  
    turtle.fillcolor("yellow")
    for i in range(5):
        turtle.forward(x)
        turtle.right(y)
    turtle.end_fill()

    turtle.fillcolor("yellow")

    填充颜色

    for i in range(5):
        turtle.forward(x)
        turtle.right(y)

    所填充的形状绘图 (本例绘图效果为:五角星)

    turtle.end_fill()

    填充完毕
    turtle.color('yellow')
    画笔颜色
    turtle.speed(speed)
    画笔速度
    “fastest”: 0“fast”: 10“normal”: 6“slow”: 3“slowest”: 1
    turtle.forward(distance)
    向前方画直线长度200

    turtle.forward(200)

    turtle.right(degree)
    向右侧旋转144度

    turtle.right(144)

    turtle.setheading(degree)
    朝向角度30
    (一般是下笔的朝向)

    turtle.setheading(30)

    turtle.done()

    放在结尾,能持续显示画布

    turtle.circle(radius,  extent=None, steps=None)

    turtle.circle(200)  逆时针方向画一个200半径的圆:

    turtle.circle(-200)  顺时针方向画一个200半径的圆:

    turtle.circle(-20180) 顺时针方向画一个20半径的半圆----画弧线

    turtle.circle(200360,5) 时针画一个变长为2005边形  ----画多边形

    circle(50,180)  50为半径长度 180为角度  180半圆(图型在第一象限,方向逆时针半圆)

    circle(50,-180)  50为半径长度 180为角度  180半圆(图型在第二象限,方向顺时针半圆)

    circle(-50,180)  50为半径长度 180为角度  180半圆(图型在第四象限,方向顺时针半圆)

    circle(-50,-180)  50为半径长度 180为角度  180半圆(图型在第三象限,方向逆时针半圆)

    参数分别为半径、弧度和画圆弧线段的数量

     

    turtle.pencolor(color)

    turtle.pensize(distance)
    turtle.pencolor(color)
    画笔的颜色与粗细


    import turtle as t

    t.speed(0)
    t.pensize(8)
    t.hideturtle()
    t.screensize(500,500,bg='white')
    t.penup()
    t.goto(0, 0)
    t.pensize(4)
    t.pendown()
    t.color('black', 'white')
    t.begin_fill()

    # 画椭圆
    a = 0.4
    for i in range(120):
    if 0 <= i < 30 or 60 <= i < 90:
    a = a + 0.08
    t.lt(3) # 向左转3度
    t.fd(a) # 向前走a的步长
    else:
    a = a - 0.08
    t.lt(3)
    t.fd(a)
    t.end_fill()

    # 画弧
    import turtle as t
    t.pendown()
    t.setheading(90)
    for j in range(60): # 重复执行60次
    t.forward(3)
    t.left(3)
    t.penup()

    t.penup()
    t.goto(20,40)
    t.pendown()

    #画弧
    t.circle(-20,180)

    #画多边形
    t.circle(40,360,5)
    t.done()

      # 画波浪线

    t.circle(40, 80)
    t.circle(-40, 80)
    t.circle(40, 80)
  • 相关阅读:
    LeetCode 17. Letter Combinations of a Phone Number (电话号码的字母组合)
    Mordern Effective C++ --auto
    modern effective C++ -- Deducint Types
    基于锁的并发数据结构
    C++ 内存模型
    zlib 简单封装
    assert 实现分析
    Valgrind 快速入门
    kmp算法理解与记录
    make 要点简记
  • 原文地址:https://www.cnblogs.com/wenchengqingfeng/p/11732378.html
Copyright © 2020-2023  润新知