确定turtle的坐标 Python

Python turtle库使用时坐标的确定

想画一个比较复杂的图像,而且还想用turtle画,无规律的笔势繁多的坐标很让人头疼,但还想画,所以就有了一个比较笨的方法。

下面使用PS确定坐标进行绘画。

PS有标尺工具,可以建立参考线,可以测量线段的长度和角度,更重要的是,PS的图像测量也是以像素为单位。

不过PS的坐标原点是在左上角,而在turtle里坐标是中心。有两种办法,一种是不改变坐标原点,在原点出建立直角坐标系,另一种方法是改变坐标原点位置
home() #以当前海龟位置为坐标原点

第一种方法相当于一个相对参考系,以长度角度画图比较方便,第二个可以在PS里给出坐标,直接用坐标绘图。

但是上述给出的方法可能有误差,不是精确到一像素长度,角度,坐标等,可能根据具体情况进行微调

PS使用如下:标尺参考线测量

附上一个画好的学校的正门!很酷有没有!我的大学
以下为源代码很长但很NICE :)

#绘制XX大学正门
from turtle import*
speed(5)
hideturtle()
setup(1200,600,200,100)
#绘制石碑
pensize(4)
pencolor("black")
penup()
goto(-585,0)
seth(-4.5)
pendown()
fd(580)
seth(-90)
fd(119)
right(90.5)
fd(578)
seth(270)
pu()
fd(29)
pd()
seth(0.75)
fd(577)
seth(90)
fd(18)

#"燕"
penup()
goto(-552,-20.6)
seth(-3.8)
pd()
fd(77)
seth(-90.9)
fd(76)
seth(179)
fd(79)
goto(-552,-20.6)
pu()
goto(-509,-102)
write("X",False,'center',font=('叶根友毛笔行书',53,'normal'))

#"山"
penup()
goto(-394,-33)
seth(-4)
pd()
fd(67)
seth(-92.5)
fd(70)
seth(179)
fd(66)
goto(-394,-33)
pu()
goto(-362,-109)
write("X",False,'center',font=('叶根友毛笔行书',45,'normal'))

#"大"
penup()
goto(-259,-42)
seth(-2.5)
pd()
fd(57)
seth(-90.7)
fd(67)
seth(180)
fd(56.7)
goto(-259,-42)
pu()
goto(-229,-108)
write("大",False,'center',font=('叶根友毛笔行书',40,'normal'))

#"学"
penup()
goto(-141,-50)
seth(-3)
pd()
fd(50)
seth(-90)
fd(62)
seth(180)
fd(49)
goto(-141,-50)
pu()
goto(-115,-113)
write("学",False,'center',font=('叶根友毛笔行书',38,'normal'))

#"YANSHAN"
penup()
goto(-432,-117)
seth(-1.5)
pd()
fd(113)
seth(-90)
fd(22)
seth(180)
fd(114)
goto(-432,-117)
pu()
goto(-375,-142)
write("YANSHAN",False,'center',font=('等线',16,'normal'))

#"UNIVERSITY"
penup()
goto(-300,-120)
seth(-2)
pd()
fd(126)
seth(-91)
fd(20)
seth(179)
fd(126)
goto(-300,-120)
pu()
goto(-238,-144)
write("UNIVERSITY",False,'center',font=('等线',15,'normal'))

#连接处
pu()
goto(-8,-107)
pd()
seth(0)
fd(37)
right(90)
fd(5)
right(90)
fd(37)
right(90)
pu()
goto(-8,-139)
pd()
seth(0)
fd(37)
right(90)
fd(32)
right(90)
fd(37)
right(90)
pu()
pensize(2)
goto(-8,-112)
pd()
for i in range(7):
    fd(3)
    seth(-90)
    fd(30)
    seth(0)
    fd(3)
    seth(90)
    fd(30)
    seth(0)

#正门
pu()
pensize(4)
goto(8,-139)
pd()
seth(90)
fd(250)
seth(14)
fd(26)
seth(-13)
fd(26)
seth(-90)
fd(17)
seth(-13)
fd(23)
seth(90)
fd(86)
seth(14)
fd(26)
seth(-14)
fd(20)
seth(-90)
fd(36)
seth(-15)
fd(96)
seth(90)
fd(18)
seth(10)
fd(22)
#中柱
seth(-16)
fd(16)
seth(-90)
fd(303)
seth(1.7)
fd(4)
seth(90)
fd(303)
seth(-16)
fd(16)
seth(-90)
fd(29)
seth(-15)
fd(64)
seth(90)
fd(12)
seth(7)
fd(20)
seth(-20)
fd(12)
seth(-90)
fd(75)
seth(-16)
fd(10)
seth(90)
fd(8)
seth(4)
fd(10)
seth(-20)
fd(12)
seth(-90)
fd(190)
#补充线条
pu()
goto(33,115)
pd()
seth(-90)
fd(296)

pu()
goto(59,93)
pd()
seth(-90)
fd(274)

pu()
goto(108,179)
pd()
seth(-90)
fd(358)

pu()
goto(126,140)
pd()
seth(-90)
fd(318)

pu()
goto(80,9)
pd()
seth(-90)
fd(185)

pu()
goto(344,0)
pd()
seth(-90)
fd(171)

pu()
goto(240,137)
pd()
seth(-90)
fd(310)

pu()
goto(222,27)
pd()
seth(-90)
fd(200)

pu()
goto(275,108)
pd()
seth(-90)
fd(277)

pu()
goto(355,95)
pd()
seth(-90)
fd(266)

pu()
goto(367,18)
pd()
seth(-90)
fd(188)

pu()
goto(390,25)
pd()
seth(-90)
fd(195)

pu()
goto(375,-21)
pd()
seth(-90)
fd(148)

#横栏1
pu()
goto(58,16)
pd()
seth(-13)
fd(38)
pu()
seth(90)
fd(13)
pd()
seth(167)
fd(38)

pu()
seth(90)
fd(65)
pd()
seth(-13)
fd(38)
pu()
seth(-90)
fd(14)
pd()
seth(167)
fd(38)
right(180)
for i in range(2):
    fd(8)
    seth(-90)
    fd(49)
    seth(-13)
    fd(8)
    seth(90)
    fd(49)
    seth(-13)
pu()
goto(58,56)
pd()
seth(-13)
fd(38)

#横栏2
pu()
goto(125,55)
pd()
seth(-15)
fd(112)
pu()
seth(90)
fd(14)
pd()
seth(165)
fd(112)
#上兰
pu()
seth(90)
fd(72)
pd()
seth(-15)
fd(112)
pu()
seth(-90)
fd(20)
pd()
seth(165)
fd(112)
right(180)
for i in range(4):
    fd(6)
    seth(-90)
    fd(50)
    seth(-15)
    fd(6)
    seth(90)
    fd(50)
    seth(-15)
fd(11)
for i in range(4):
    fd(6)
    seth(-90)
    fd(50)
    seth(-15)
    fd(6)
    seth(90)
    fd(50)
    seth(-15)
pu()
goto(125,95)
pd()
seth(-15)
fd(38)
pu()
fd(28)
pd()
fd(38)

#横栏3
pu()
goto(275,18)
pd()
seth(-15)
fd(75)
pu()
seth(90)
fd(14)
pd()
seth(165)
fd(75)
#上兰
pu()
seth(90)
fd(68)
pd()
seth(-15)
fd(75)
pu()
seth(-90)
fd(18)
pd()
seth(165)
fd(75)
right(180)
for i in range(3):
    fd(6)
    seth(-90)
    fd(50)
    seth(-15)
    fd(6)
    seth(90)
    fd(50)
    seth(-15)
fd(9)
for i in range(2):
    fd(6)
    seth(-90)
    fd(50)
    seth(-15)
    fd(6)
    seth(90)
    fd(50)
    seth(-15)
pu()
goto(275,55)
pd()
seth(-15)
fd(35)
pu()
fd(17)
pd()
fd(20)

#横栏4
pu()
goto(369,-20)
pd()
seth(-14)
fd(7)
pu()
seth(90)
fd(10)
pd()
seth(166)
fd(7)

pu()
seth(90)
fd(27)
pd()
seth(-14)
fd(7)
pu()
seth(-90)
fd(10)
pd()
seth(166)
fd(7)
right(180)
fd(4)
seth(-90)
fd(15)

pu()
goto(369,-2)
pd()
seth(-14)
fd(6)


#底线
pu()
goto(-8,-181)
pd()
seth(1.7)
fd(430)
done()
  • 15
    点赞
  • 49
    收藏
    觉得还不错? 一键收藏
  • 5
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论 5
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值