當前位置: 首頁>>代碼示例>>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;未經允許,請勿轉載。