绘制五角星
1 import turtle 2 3 turtle.color('black','red') 4 turtle.pensize(10) 5 turtle.begin_fill() 6 for i in range(5): 7 turtle.fd(200) 8 turtle.rt(144) 9 10 turtle.end_fill()
绘制一组同心圆
从键盘输入半径、绘制同心圆的个数及画笔的颜色
1 import turtle 2 3 turtle.pensize(10) 4 5 r=eval(input()) 6 n=eval(input()) 7 color=input() 8 turtle.pencolor(color) 9 10 for i in range(n): 11 turtle.circle(r+(i-1)*20,360)#每个同心圆的半径差为20 12 turtle.penup() 13 turtle.right(90) 14 turtle.forward(20) 15 turtle.left(90) 16 turtle.pendown()
键盘输入:
20
4
red
绘制渐变的圆
描述
利用turtle库的circle(50)函数可以画半径为50的圆,circle(50,steps=n)可以画半径为50的圆的内接正n边形,利用这个方法绘制示例中的图形,设置画笔为蓝色并用黄色填充图形。n由用户输入,要求n>=3且小于10。(注意:最后一个必须是圆,不能是正多边形)
输入格式
一个大于等于3且小于10的正整数
1 #渐变的圆 2 import turtle 3 4 number = int(input()) #把用户输入转成整数 5 6 turtle.screensize(1200,1000) 7 turtle.penup() 8 turtle.goto(-300,0) 9 turtle.pendown() 10 11 turtle.pensize(5) 12 turtle.color("blue","yellow") 13 turtle.begin_fill() 14 turtle.forward(-50) 15 16 for i in range(3,number): 17 turtle.circle(50, steps=i) 18 turtle.forward(100) 19 20 turtle.circle(50, steps=number) 21 if number == 1: 22 turtle.circle(50) 23 else: 24 turtle.forward(100) 25 turtle.circle(50) 26 turtle.end_fill() 27 turtle.hideturtle() #隐藏海龟
输入:10
输出:
绘制叠加的等边三角形
1 import turtle 2 turtle.pensize(10) 3 turtle.color('purple','pink') 4 turtle.begin_fill() 5 6 turtle.forward(100) 7 turtle.right(120) 8 turtle.forward(100) 9 10 turtle.right(120) 11 turtle.forward(100) 12 turtle.right(60) 13 turtle.forward(100) 14 15 turtle.right(120) 16 turtle.forward(200) 17 turtle.right(120) 18 turtle.forward(200) 19 turtle.right(120) 20 turtle.forward(100) 21 22 turtle.end_fill()
绘制奥运五环
1 #五环 2 import turtle #引用turtle库 3 turtle.pensize(10) #设置画笔大小 4 coordA=[-110,0,110,-55,55] #各个圆X轴坐标 5 coordB=[-25,-25,-25,-75,-75] #各个圆的Y坐标 6 colors=["red","blue","green","yellow","black"] 7 for i in range(5): 8 turtle.pencolor(colors[i]) 9 turtle.penup() 10 turtle.goto(coordA[i],coordB[i]) 11 turtle.pendown() 12 turtle.circle(45) 13 turtle.hideturtle() #隐藏画笔
啊~五环!你比六环少一环~
绘制八卦阵
1 #八卦阵 2 import turtle 3 turtle.pensize(5) #画笔大小 4 turtle.penup() 5 turtle.goto(0,120) 6 turtle.pendown() 7 8 turtle.color("black","black") 9 turtle.begin_fill() 10 turtle.circle(-120,180) 11 turtle.circle(-60,180) 12 turtle.circle(60,180) 13 turtle.end_fill() 14 turtle.circle(120,180) 15 16 turtle.penup() 17 turtle.goto(0,40) 18 turtle.pendown() 19 turtle.begin_fill() 20 turtle.circle(20) 21 turtle.end_fill() 22 23 turtle.color("black","white") 24 turtle.penup() 25 turtle.goto(0,-80) 26 turtle.pendown() 27 turtle.begin_fill() 28 turtle.circle(20) 29 turtle.end_fill() 30 31 turtle.hideturtle() #隐藏画笔
这里我们取大圆的半径为120,中圆自然是它的一半,小圆我们取中圆的三分之一。这样以后,各个点的坐标都出来了
天灵灵,地灵灵~
绘制国际象棋盘
1 #国际象棋 2 import turtle 3 turtle.pensize(3) 4 turtle.screensize(1200,1000) #画布大小 5 turtle.color("black","black") 6 n=eval(input()) #输入一个数 7 8 turtle.penup() 9 turtle.goto(-4*n,4*n) #从左上角开始画 10 turtle.pendown() 11 turtle.forward(8*n) #先画一个大的正方形 12 turtle.right(90) 13 turtle.forward(8*n) 14 turtle.right(90) 15 turtle.forward(8*n) 16 turtle.right(90) 17 turtle.forward(8*n) 18 19 coordA=[-3*n,-n,n,3*n] 20 coordB=[4*n,2*n,0,-2*n] 21 22 for i in range(4): 23 for j in range(4): 24 turtle.penup() 25 turtle.goto(coordA[i],coordB[j]) 26 turtle.pendown() 27 turtle.begin_fill() 28 turtle.right(90) 29 turtle.forward(n) 30 turtle.right(90) 31 turtle.forward(n) 32 turtle.right(90) 33 turtle.forward(n) 34 turtle.right(90) 35 turtle.forward(n) 36 turtle.end_fill() 37 38 coordC=[-4*n,-2*n,0,2*n] 39 coordD=[3*n,n,-n,-3*n] 40 41 for i in range(4): 42 for j in range(4): 43 turtle.penup() 44 turtle.goto(coordC[i],coordD[j]) 45 turtle.pendown() 46 turtle.begin_fill() 47 turtle.right(90) 48 turtle.forward(n) 49 turtle.right(90) 50 turtle.forward(n) 51 turtle.right(90) 52 turtle.forward(n) 53 turtle.right(90) 54 turtle.forward(n) 55 turtle.end_fill() 56 57 turtle.hideturtle()
题目: 画一个国际象棋盘,小格边长由用户输入2020-03-19
思路:先画一个大的正方形,设定一个N值为小正方形的边长。这样我们可以找到每个小正方形的坐标。开始绘画,按一下思路,这里会用到两层循环哦!
这是过程图:
这是结果:
注:从开始填充到结束填充,需要的是起点和终点都是同一个点。也就是说,一个封闭的图形才可以填充,否则,将会是起点和终点的连线之间所有封闭图形的填充。这也是我采用这种思路的原因。
感谢大家的浏览!