Python Turtle 中的 setworldcoordinates 方法

turtle 中默认的模式为 standard ,其坐标原点在画布(canvas)中心,单位为象素(pixel)。这种从标系也许不是最符合需要求的,因此可以用 setworlcoordinates 自定义坐标系。

setworldcoordinates(llx,lly,urx,ury) 表示屏幕左下角的 (x, y) 和屏幕右上角的 (x, y) 坐标。(文档上说是画布的左下角和右上角坐标,但实测是屏幕的左下角和右上角。)

Set up user-defined coordinate system and switch to mode “world” if necessary. This performs a screen.reset(). If mode “world” is already active, all drawings are redrawn according to the new coordinates.

举例:

# coding=utf-8

from turtle import *

setup(500,500) # 窗口大小 500 x 500 象素
setworldcoordinates(-0.5, 4.5, 4.5, -0.5) # 自定义坐标系统,并切换到 world 模式
goto(0,4)
goto(4,4)
goto(4,0)
goto(0,0)
exitonclick()

屏幕截图如下:

这里写图片描述

参考

what does the turtle.setworldcoordinates function do?

25.1. turtle — Turtle graphics

  • 2
    点赞
  • 7
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值