如何用python turtle画一个中国象棋的棋盘?

绘制棋盘,每个格子50import turtlet=turtle.Pen()bs=50#画直线def line(x,y,z): t.penup() t.goto(x,y) t.pendown() t.fd(z)#两点直线def any(a,b,c,d): t.penup() t.goto(a,b) t.pendown() t.goto(c,d)#画L型def typeL(x,y): t.penup(...
如何用python turtle画一个中国象棋的棋盘?
#绘制棋盘,每个格子50import turtlet=turtle.Pen()bs=50#画直线def line(x,y,z): t.penup() t.goto(x,y) t.pendown() t.fd(z)#两点直线def any(a,b,c,d): t.penup() t.goto(a,b) t.pendown() t.goto(c,d)#画L型def typeL(x,y): t.penup() t.goto(x-bs*0.25, y+bs*0.075) t.pendown() t.goto(x-bs*0.075, y+bs*0.075) t.goto(x - bs*0.075, y + bs*0.25) t.penup() t.goto(x - bs*0.25, y - bs*0.075) t.pendown() t.goto(x - bs*0.075, y - bs*0.075) t.goto(x - bs*0.075, y - bs*0.25) t.penup() t.goto(x+bs*0.25, y+bs*0.075) t.pendown() t.goto(x+bs*0.075, y+bs*0.075) t.goto(x + bs*0.075, y + bs*0.25) t.penup() t.goto(x + bs*0.25, y - bs*0.075) t.pendown() t.goto(x + bs*0.075, y - bs*0.075) t.goto(x + bs*0.075, y - bs*0.25)#画半L型def typehL(x,y,z): if(z=='l'): t.penup() t.goto(x-bs*0.25, y+bs*0.075) t.pendown() t.goto(x-bs*0.075, y+bs*0.075) t.goto(x - bs*0.075, y + bs*0.25) t.penup() t.goto(x - bs*0.25, y - bs*0.075) t.pendown() t.goto(x - bs*0.075, y - bs*0.075) t.goto(x - bs*0.075, y - bs*0.25) if(z=='r'): t.penup() t.goto(x + bs*0.25, y + bs*0.075) t.pendown() t.goto(x + bs*0.075, y + bs*0.075) t.goto(x + bs*0.075, y + bs*0.25) t.penup() t.goto(x + bs*0.25, y - bs*0.075) t.pendown() t.goto(x + bs*0.075, y - bs*0.075) t.goto(x + bs*0.075, y - bs*0.25)#画横线p=bs*4.5while(p>=-bs*4.5): line(-bs*4,p,bs*8) p=p-bsany(bs*4,bs*4.5,bs*4,-bs*4.5)any(-bs*4,bs*4.5,-bs*4,-bs*4.5)t.right(90)q=-bs*3while(q<bs*4): line(q,bs*4.5,bs*4) q=q+bsq=-bs*3while(q<bs*4): line(q,-bs*0.5,bs*4) q=q+bs#画斜线any(-bs,-bs*4.5,bs,-bs*2.5)any(bs,-bs*4.5,-bs,-bs*2.5)any(-bs,bs*4.5,bs,bs*2.5)any(bs,bs*4.5,-bs,bs*2.5)#画L型typeL(-bs*2,-bs*1.5)typeL(0,-bs*1.5)typeL(bs*2,-bs*1.5)typeL(-bs*2,bs*1.5)typeL(0,bs*1.5)typeL(bs*2,bs*1.5)typeL(-bs*3,-bs*2.5)typeL(bs*3,-bs*2.5)typeL(-bs*3,bs*2.5)typeL(bs*3,bs*2.5)typehL(-bs*4,-bs*1.5,'r')typehL(bs*4,-bs*1.5,'l')typehL(-bs*4,bs*1.5,'r')typehL(bs*4,bs*1.5,'l')turtle.done()2018-11-24
这个要收费的😂简单问题免费解答,小程序就不能无偿给你写了2016-12-24
mengvlog 阅读 7 次 更新于 2025-07-19 09:07:57 我来答关注问题0
檬味博客在线解答立即免费咨询

Python相关话题

Copyright © 2023 WWW.MENGVLOG.COM - 檬味博客
返回顶部