当前位置: 首页>>代码示例>>Python>>正文


Python Rectangle.corner方法代码示例

本文整理汇总了Python中rectangle.Rectangle.corner方法的典型用法代码示例。如果您正苦于以下问题:Python Rectangle.corner方法的具体用法?Python Rectangle.corner怎么用?Python Rectangle.corner使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在rectangle.Rectangle的用法示例。


在下文中一共展示了Rectangle.corner方法的3个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。

示例1: move_rectangle

# 需要导入模块: from rectangle import Rectangle [as 别名]
# 或者: from rectangle.Rectangle import corner [as 别名]
def move_rectangle(old_rec, dx, dy):
    """
    Takes a rectangle and distances, and returns a new Rectangle object
    moved by those coordinates.
    """
    new_rec = Rectangle()
    new_rec.height = old_rec.height
    new_rec.width = old_rec.width
    new_rec.corner = Point()
    new_rec.corner.x = old_rec.corner.x + dx
    new_rec.corner.y = old_rec.corner.y + dy
    return new_rec
开发者ID:PriceHardman,项目名称:think_python,代码行数:14,代码来源:15-3_move_copy.py

示例2: draw_rectangle

# 需要导入模块: from rectangle import Rectangle [as 别名]
# 或者: from rectangle.Rectangle import corner [as 别名]
#!/usr/bin/python

from swampy.World import World
from rectangle import Rectangle, Point

def draw_rectangle(Canvas, Rectangle):
    bbox = [[Rectangle.corner.x, Rectangle.corner.y], 
            [Rectangle.corner.x + Rectangle.width, 
             Rectangle.corner.y + Rectangle.height]]
    Canvas.rectangle(bbox, outline="black", width=2, fill="green4")
    

world = World()

canvas = world.ca(width=500, height=500, background="white")
box = Rectangle()
box.corner = Point()
box.corner.x = 50
box.corner.y = 50
box.width = 100
box.height = 100

draw_rectangle(canvas, box)
world.mainloop()
开发者ID:debsir,项目名称:Learning,代码行数:26,代码来源:draw_rectangle.py

示例3: move_rectangle

# 需要导入模块: from rectangle import Rectangle [as 别名]
# 或者: from rectangle.Rectangle import corner [as 别名]
# Exercise 15-2.
# Write a function named move_rectangle that takes a Rectangle and two numbers
# named dx and dy. It should change the location of the rectangle by adding dx to the x
# coordinate of corner and adding dy to the y coordinate of corner.

from point import Point
from rectangle import Rectangle


def move_rectangle(rec, dx, dy):
    """Takes a rectangle object and moves it by dx and dy."""
    rec.corner.x += dx
    rec.corner.y += dy
    return None


rec = Rectangle()
rec.corner = Point()
rec.corner.x = 1
rec.corner.y = 2
rec.width = 10
rec.height = 15

dx = 2
dy = 3

print("Before: (x,y) = (%d,%d)" % (rec.corner.x, rec.corner.y))
move_rectangle(rec, dx, dy)
print("After: (x,y) = (%d,%d), (dx,dy) = (%d,%d)" % (rec.corner.x, rec.corner.y, dx, dy))
开发者ID:PriceHardman,项目名称:think_python,代码行数:31,代码来源:15-2_move_rectangle.py


注:本文中的rectangle.Rectangle.corner方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。