• 1.常用turtle功能函数


    #turtle常用命令汇总,括号中的参数仅仅作为举例使用,可根据需要修改

    #设置画面背景色

    turtle.bgcolor("black") 

    #设置窗口大小和在屏幕上的坐标 

    turtle.setup(width=200,height=200,startx=0,starty=0) 

    #设置背景图片,只支持gif格式 

    turtle.bgpic("1.gif")

     #用户点击屏幕时获得笔的坐标,制作app时响应用户的点击操作32

    turtle.onscreenclick(x,y)

     #退出turtle,无任何提示信息

    turtle.bye()

     #点击后退出turtle

    turtle.exitonclick()

     #关闭turtle,一般在使用完turtle后添加

    turtle.done()

     #启用画笔

    turtle.Pen()

     #画笔颜色设置,颜色可以使用英文单词或常见的#开头十六进制数表示

    turtle.color("red")  或turtle.Pen().color("#cc4455")

     #画笔前进长度,以像素为单位

    turtle.forward(2)

     #画笔后退长度

    turtle.backward(2)

    #画笔的初始位置 

    turtle.Pen().home()

     #画笔向左转

    turtle.left(90)

     #画笔向右转

    turtle.right(90)

     #设置画笔宽度,以像素为单位

    turtle.width(3)

    #后面内容都用t表示

     #抬起笔,停止写

    t.penup()

    #放下笔,开始写 

    t.pendown()

    #写指定内容”balabala“,并设置字体、字号、加粗等 

    t.write("balabala",font=("Arial",23,"bold"))

     #以参数为半径画圆

    t.circle(4)

     #以参数为直径画点

    t.dot(4)

     #笔的坐标(x,y)

    t.position()

     #笔的朝向

    t.heading()

     #设置笔的x坐标为position记录的x坐标,position由position=t.position()获得

    t.setx(position[0])

     #设置笔的y坐标为position记录的y坐标

    t.sety(position[1])

     #设置笔的朝向,画笔默认朝向为正右方

    t.setheading(30)

     #设置笔的坐标

    t.setpos(x,y)

    #设置填充颜色,开始填充,画圆填充,填充结束 

    t.fillcolor("#33de55")

    t.begin_fill()

    t.circle(5)

    t.end_fill()

     #笔移动到坐标(x,y)

    t.goto(x,y)

     #笔的移动速度参数范围0.5——10,范围之外为0,最快,不设置速度为最慢

    t.speed(0)

     #隐藏画笔

    t.hideturtle()

     #显示画笔

    t.showturtle()

    #删除画的内容,不修改画笔参数 

    t.clear()

    #删除画的内容,还原画笔参数为初始值

    t.reset()

  • 相关阅读:
    Delete Node in a Linked List leetcode
    Remove Linked List Elements leetcode
    Remove Linked List Elements
    Remove Element leetcode
    Merge Sorted Array leetcode
    Min Stack leetcode
    Valid Palindrome leetcode
    [LeetCode] 1. Two Sum
    [LeetCode] 520. Detect Capital
    [LeetCode] 791. Custom Sort String
  • 原文地址:https://www.cnblogs.com/ubuntu1987/p/10607745.html
Copyright © 2020-2023  润新知