PyRect是一个简单的模块,包含用于类似Pygame矩形区域的Rect类。
项目描述
PyRect是一个简单的模块,包含用于类似Pygame矩形区域的Rect类。
此模块类似于Pygame的Rect类的独立版本。它与Simon Wittber的Rect模块类似,但兼容Python 2和3。
目前处于开发中,尽管基本功能正常。
安装
pip安装pyrect
快速入门指南
首先,通过提供其左上角的XY坐标来创建一个Rect对象,然后是宽度和高度
>>> import pyrect >>> r = pyrect.Rect(0, 0, 10, 20)
有一些属性是自动计算的(它们的名称与Pygame的Rect对象相同)
>>> r.width, r.height, r.size (10, 20, (10, 20)) >>> r. left 0 >>> r.right 10 >>> r.top 0 >>> r.bottom 20 >>> r.center (5, 10) >>> r.topleft (0, 0) >>> r.topright (10, 0) >>> r.midleft (0, 10)
更改这些属性将重新计算其他属性。左上角是锚点,用于任何增长或收缩。
>>> r.topleft (0, 0) >>> r.left = 100 >>> r.topleft (100, 0) >>> r.topright (110, 0) >>> r.width = 30 >>> r.topright (130, 0)
Rect对象锁定为整数,除非您将enableFloat设置为True
>>> r = pyrect.Rect(0, 0, 10, 20) >>> r.width = 10.5 >>> r.width 10 >>> r.enableFloat = True >>> r.width = 10.5 >>> r.width 10.5 >>> r2 = pyrect.Rect(0, 0, 10.5, 20.5, enableFloat=True) >>> r2.size (10.5, 20.5)
Rect属性
Rect对象有几个可以读取或修改的属性。它们与Pygame的Rect对象相同
x, y
top, left, bottom, right
topleft, bottomleft, topright, bottomright
midtop, midleft, midbottom, midright
center, centerx, centery
size, width, height
w, h
还有一些其他属性
盒子(一个元组(左,上,宽,高))
区域 (只读)
周长 (只读)
项目详情
关闭
PyRect-0.2.0.tar.gz 的哈希值
算法 | 哈希摘要 | |
---|---|---|
SHA256 | f65155f6df9b929b67caffbd57c0947c5ae5449d3b580d178074bffb47a09b78 |
|
MD5 | 8139f7036c54a0c770a14059d967f22e |
|
BLAKE2b-256 | cb042ba023d5f771b645f7be0c281cdacdcd939fe13d1deb331fc5ed1a6b3a98 |