码迷,mamicode.com
首页 > 编程语言 > 详细

python_turtle模板画图

时间:2017-08-15 22:58:39      阅读:546      评论:0      收藏:0      [点我收藏+]

标签:代码   退出   hit   else   技术   .sh   文字   画板   sed   

turtle简单画图所用到的代码:

 1 turtle.showturtle()  #画图板
 2 turtle.screensize(2024,2000) #画图板大小
 3 turtle.forward() #往前移动
 4 turtle.right(90) #方向往左调整n度
 5 turtle.left(30) #方向往右调整n度
 6 turtle.write("hello") #写文字
 7 turtle.goto(50,50) #坐标移动
 8 turtle.penup()  #抬笔
 9 turtle.pendown() #落笔
10 
11 turtle.circle(100) # 画圆
12 turtle.done() # 显示不退出
13 turtle.reset() # 重置
14 turtle.begin_fill() #开始填充
15 turtle.circle(100,steps=5)  #设置边形
16 turtle.color("red") #画笔颜色 默认黑
17 turtle.end_fill()#结束填充
18 turtle.hideturtle() # 隐藏箭头
19 turtle.pensize("15") #画笔大小
20 turtle.write("hello world",font=("华文琥珀",20,"normal")) # 设置字体
21 turtle.screensize(2024,2718)  #画板大小
22 turtle.dot(10,"black")# 填充圆

 下面画一个围棋画板

技术分享
 1 turtle.showturtle()
 2 turtle.screensize(2000,2000)
 3 m=20
 4 for i in range (19):
 5     turtle.penup()
 6     turtle.goto(0,20*i)
 7     turtle.pendown()
 8     turtle.forward(20*18)
 9 turtle.right(270)
10 for i in range(19):
11     turtle.penup()
12     turtle.goto(20*i,0)
13     turtle.pendown()
14     turtle.forward(20*18)
15 turtle.dot(10,"black")
16 turtle.done()
View Code

国际象棋

技术分享
 1 turtle.showturtle()
 2 m=20
 3 
 4 for i in range(8):  #画多个方格位置
 5     for j in range(8):
 6         turtle.penup()
 7         turtle.goto(i*m,j*m)
 8         turtle.pendown()
 9         turtle.begin_fill()
10         #画一个方格
11         for k in range(4):
12             turtle.forward(m)
13             turtle.right(90)
14         # 判断黑白, i+j 偶数黑,奇数白
15         if (i+j)%2==0:
16             turtle.color("black")
17         else:
18             turtle.color("white")
19 
20         turtle.end_fill()
21 
22 turtle.done()
View Code

 折线图

技术分享
1 import turtle
2 for i in range(0,300,100):
3     for j in range (0,400,100):
4         turtle.goto(j,i)
5         turtle.pendown()
6         turtle.write(str(i)+","+str(j))
7     turtle.penup()
8 
9 turtle.done()
View Code

 最后画一个正方体

技术分享
 1 import  turtle
 2 
 3 turtle.goto(200,0)
 4 turtle.goto(200,200)
 5 turtle.goto(0,200)
 6 turtle.goto(0,0)
 7 
 8 turtle.penup()
 9 turtle.goto(100,100)
10 turtle.pendown()
11 
12 turtle.begin_fill()
13 turtle.goto(100,-100)
14 turtle.goto(-100,-100)
15 turtle.goto(-100,100)
16 turtle.goto(100,100)
17 turtle.color("red")
18 turtle.end_fill()
19 
20 turtle.goto(200,200)
21 turtle.penup()
22 turtle.goto(100,-100)
23 turtle.pendown()
24 turtle.goto(200,0)
25 turtle.penup()
26 turtle.goto(-100,-100)
27 turtle.pendown()
28 turtle.goto(0,0)
29 turtle.penup()
30 turtle.goto(-100,100)
31 turtle.pendown()
32 turtle.goto(0,200)
33 turtle.color("blue")
34 turtle.write("hello Python",font=("楷体","20","normal"))
35 turtle.done()
View Code

python_turtle模板画图

标签:代码   退出   hit   else   技术   .sh   文字   画板   sed   

原文地址:http://www.cnblogs.com/gamaboy/p/7360263.html

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!