turtle库基础练习

1.画一组同切圆

>>> import turtle
>>> turtle.circle(10)
>>> turtle.circle(20)
>>> turtle.circle(30)

turtle库基础练习_第1张图片

2.画一组同心圆

import turtle

for i in range(5):
    turtle.up()
    turtle.goto(0,-25*(i+1))
    turtle.down()
    turtle.circle(25*(i+1))

turtle库基础练习_第2张图片

3.画一个五角星

>>> import turtle
>>> turtle.color('yellow')
>>> turtle.bgcolor('red')
>>> turtle.hideturtle()
>>> turtle.beginfill()
Traceback (most recent call last):
  File "", line 1, in 
    turtle.beginfill()
AttributeError: module 'turtle' has no attribute 'beginfill'
>>> turtle.begin_fill()
>>> turtle.forward(99)
>>> turtle.right(144)
>>> turtle.forward(99)
>>> turtle.right(144)
>>> turtle.forward(99)
>>> turtle.right(144)
>>> turtle.forward(99)
>>> turtle.right(144)
>>> turtle.forward(99)
>>> turtle.end_fill()

turtle库基础练习_第3张图片

4.画一个黄色实心五角星

>>> import turtle
>>> turtle.color('yellow')
>>> turtle.bgcolor('red')
>>> turtle.hideturtle()
>>> turtle.beginfill()
Traceback (most recent call last):
  File "", line 1, in 
    turtle.beginfill()
AttributeError: module 'turtle' has no attribute 'beginfill'
>>> turtle.begin_fill()
>>> turtle.forward(99)
>>> turtle.right(144)
>>> turtle.forward(99)
>>> turtle.right(144)
>>> turtle.forward(99)
>>> turtle.right(144)
>>> turtle.forward(99)
>>> turtle.right(144)
>>> turtle.forward(99)
>>> turtle.end_fill()

turtle库基础练习_第4张图片

5.画左上角的五颗五角星

import turtle

turtle.setup(600,400,0,0)
turtle.color('yellow')
turtle.bgcolor('red')
turtle.fillcolor('yellow')

def mygoto(x,y):
    turtle.up()
    turtle.goto(x,y)
    turtle.down()
    
mygoto(-250,75)
turtle.begin_fill()
for i in range(5):
    turtle.forward(100)
    turtle.right(144)
turtle.end_fill()

mygoto(-100,150)
turtle.begin_fill()
for i in range(5):
    turtle.forward(50)
    turtle.right(144)
turtle.end_fill()

mygoto(-80,80)
turtle.begin_fill()
for i in range(5):
    turtle.forward(50)
    turtle.right(144)
turtle.end_fill()

mygoto(-70,20)
turtle.begin_fill()
for i in range(5):
    turtle.forward(50)
    turtle.right(144)
turtle.end_fill()

mygoto(-80,-40)
turtle.begin_fill()
for i in range(5):
    turtle.forward(50)
    turtle.right(144)
turtle.end_fill()

turtle库基础练习_第5张图片

 

转载于:https://www.cnblogs.com/xiepingjian/p/7509302.html

你可能感兴趣的:(turtle库基础练习)