标签:lse col height src 太极 div color down 国际
1、画五角星
import turtle turtle.pensize(5) turtle.pencolor("yellow") turtle.fillcolor("red") turtle.begin_fill() for i in range(5): turtle.forward(200) turtle.right(-72) turtle.forward(200) turtle.left(-144) turtle.end_fill() turtle.hideturtle() turtle.done()
运行结果:
2、
import turtle radius=int(input()) number=int(input()) color=input() turtle.pensize(2) turtle.pencolor(color) for i in range(number): turtle.circle(radius+i*10) turtle.penup() turtle.right(90) turtle.forward(10) turtle.left(90) turtle.pendown() turtle.hideturtle() turtle.done()
输入:
20
4
red
运行结果:
3、渐变的圆
import turtle n=int(input()) turtle.pensize(3) turtle.pencolor("blue") turtle.fillcolor("yellow") turtle.begin_fill() if n in [3,4,5,6,7,8,9]: for i in range(7): turtle.circle(50,steps=n+i) turtle.forward(100) turtle.circle(50) else: turtle.clear() turtle.end_fill() turtle.hideturtle() turtle.done()
输入:
3
运行结果:
4、
import turtle turtle.forward(100) for i in range(2): turtle.right(120) turtle.forward(100) turtle.right(60) turtle.forward(100) turtle.right(120) for i in range(3): turtle.forward(200) turtle.right(120) turtle.hideturtle() turtle.done()
运行结果:
5、
import turtle coordA=(-110,0,110,-55,55) coordB=(-25,-25,-25,-75,-75) colors=["red","blue","green","yellow","black"] turtle.pensize(5) for i in range(5): turtle.color(colors[i]) turtle.penup() turtle.goto(coordA[i],coordB[i]) turtle.pendown() turtle.circle(45) turtle.hideturtle() turtle.done()
运行结果:
6、
import turtle turtle.circle(100) turtle.fillcolor(‘black‘) turtle.begin_fill() turtle.circle(50,-180) turtle.end_fill() turtle.circle(-50,-180) turtle.begin_fill() turtle.circle(-100,180) turtle.end_fill() turtle.circle(-100,180) turtle.fillcolor(‘white‘) turtle.begin_fill() turtle.circle(-50,180) turtle.end_fill() turtle.penup() turtle.right(90) turtle.forward(40) turtle.right(90) turtle.fillcolor(‘black‘) turtle.begin_fill() turtle.circle(12) turtle.end_fill() turtle.penup() turtle.right(90) turtle.forward(80) turtle.right(90) turtle.fillcolor(‘white‘) turtle.begin_fill() turtle.circle(12) turtle.end_fill() turtle.hideturtle() turtle.done()
运行结果:
7、画国际象棋盘
import turtle s=int(input()) turtle.penup() turtle.goto(-150,150) turtle.pendown() for i in range(4): for i in range(4): turtle.forward(s) turtle.fillcolor(‘black‘) turtle.begin_fill() turtle.right(90) turtle.forward(s) turtle.left(90) turtle.forward(s) turtle.left(90) turtle.forward(s) turtle.right(90) turtle.end_fill() turtle.right(90) turtle.forward(s) turtle.right(90) for i in range(4): turtle.forward(s) turtle.fillcolor(‘black‘) turtle.begin_fill() turtle.left(90) turtle.forward(s) turtle.right(90) turtle.forward(s) turtle.right(90) turtle.forward(s) turtle.left(90) turtle.end_fill() turtle.left(90) turtle.forward(s) turtle.left(90) turtle.right(-180) for i in range(4): turtle.right(90) turtle.fd(8*s) turtle.hideturtle() turtle.done()
输入:
50
运行结果:
标签:lse col height src 太极 div color down 国际
原文地址:https://www.cnblogs.com/567823a/p/12587737.html