本文整理匯總了Python中rectangle.Rectangle.height方法的典型用法代碼示例。如果您正苦於以下問題:Python Rectangle.height方法的具體用法?Python Rectangle.height怎麽用?Python Rectangle.height使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在類rectangle.Rectangle
的用法示例。
在下文中一共展示了Rectangle.height方法的3個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Python代碼示例。
示例1: move_rectangle
# 需要導入模塊: from rectangle import Rectangle [as 別名]
# 或者: from rectangle.Rectangle import height [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
示例2: draw_rectangle
# 需要導入模塊: from rectangle import Rectangle [as 別名]
# 或者: from rectangle.Rectangle import height [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()
示例3: move_rectangle
# 需要導入模塊: from rectangle import Rectangle [as 別名]
# 或者: from rectangle.Rectangle import height [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))