Python: Turtle

Posted Enomothem

tags:

篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了Python: Turtle相关的知识,希望对你有一定的参考价值。

Ax_Introduction

Turtle graphics is a popular way for introducing programming to kids. It was part of the original Logo programming language developed by Wally Feurzeig, Seymour Papert and Cynthia Solomon in 1967.
refer:
https://www.jianshu.com/p/b502c89132dd
https://docs.python.org/3/library/turtle.html

Bx_Note

setx()
sety()
seth()/setheading()
goto(x,y)
circle(r,e)
dot(r,color)
forward()
backward()
pendown()
penup()
left()
right()
...

Cx_Instance

No.1,wjx

from turtle import *
setup(400,400)
penup()
goto(-100,50)
pendown()
color("red")
begin_fill()
for i in range(5):
    forward(200)
    right(144)
end_fill()
hideturtle()
done()


No.2,love

from turtle import *
color(\'red\',\'pink\')
begin_fill()
left(135)
fd(100)
right(180)
circle(50,-180)
left(90)
circle(50,-180)
right(180)
fd(100)
end_fill()
hideturtle()
done()


No.3,lx

import turtle
n = 10
for i in range(1,10,1):
    for j in [90,180,-90,0]:
        turtle.seth(j)
        turtle.fd(n)
        n += 5

No.4,textinput

>>> turtle.textinput("NIM","What is your name?")

Dx_Hit the pit

Ex_STREE

import random
height = 11
for i in range(height):
    print(\' \' * (height - i), end=\'\')
    for j in range((2 * i) + 1):
        if random.random() < 0.1:
            color = random.choice([\'\\033[1;31m\', \'\\033[33m\', \'\\033[1;34m\'])
            print(color, end=\'\') 
        else:
            print(\'\\033[32m\', end=\'\') 
        print(\'*\', end=\'\')
    print()
print((\' \' * height) + \'|\')
import turtle
screen = turtle.Screen()
screen.setup(800,600)

circle = turtle.Turtle()
circle.shape(\'circle\')
circle.color(\'red\')
circle.up()
circle.goto(0,100)
circle.stamp()

square = turtle.Turtle()
square.shape(\'square\')
square.color(\'green\')
square.up()
square.goto(0,200)
square.stamp()

turtle.exitonclick()

by En0moThem

以上是关于Python: Turtle的主要内容,如果未能解决你的问题,请参考以下文章

Python-100天代码

python3 turtle使用报错,代码没有对齐

Python科赫雪花代码

turtle库的几个案例进阶,代码可直接运行(python经典编程案例)

turtle库的几个案例进阶,代码可直接运行(python经典编程案例)

为啥用python turtle库画蟒蛇会出现这个错误?