本文整理汇总了Python中picture.Picture.drawRect方法的典型用法代码示例。如果您正苦于以下问题:Python Picture.drawRect方法的具体用法?Python Picture.drawRect怎么用?Python Picture.drawRect使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类picture.Picture
的用法示例。
在下文中一共展示了Picture.drawRect方法的2个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: main
# 需要导入模块: from picture import Picture [as 别名]
# 或者: from picture.Picture import drawRect [as 别名]
def main():
# Get the width for the canvas
width = int(eval(input("How wide do you want the canvas to be? (In pixels) ")))
height = width
# Get the number of bricks tall the user wants the pyramid to be
try:
numBricks = int(eval(input("How many bricks tall do you want your pyramid to be? ")))
except:
print("That was a non-numeric value. You are the worst ever. Exciting.")
# Create the canvas
canvas = Picture((width, width))
# Fill in the background
canvas.setPenColor(255, 255, 255)
canvas.drawRectFill(0, 0, width, width)
# Calculate brick height and width
try:
brickHeight = int(width/numBricks)
brickWidth = int(width/numBricks)
except:
print("You put in 0 bricks, so you will only get a background. AHAHAHAHAHAAHAHAHAHAHAHAHA. AHAHA. AHA. HA.")
# Loop through each row of the pyramid
rowX = 0
rowY = 0
for i in range(0, numBricks):
# Find the y coordinate for every brick in this row
brickY = brickHeight*(i + 1)
# Loop through each brick in each row
for j in range(0, numBricks - i):
# Find the x coordinate for each brick as you go along
canvas.setPenColor(0, 255, 255)
canvas.drawRectFill(rowX + j*brickWidth, height - brickHeight - rowY, brickWidth, brickHeight)
canvas.setPenColor(0, 0, 0)
canvas.drawRect(rowX + j*brickWidth, height - brickHeight - rowY, brickWidth, brickHeight)
rowX += int(brickWidth/2)
rowY += brickHeight
canvas.writeFile("pyramid.bmp")
canvas.display()
示例2: main
# 需要导入模块: from picture import Picture [as 别名]
# 或者: from picture.Picture import drawRect [as 别名]
def main():
# Get the width for the canvas
width = int(eval(input("How wide do you want the canvas to be? (In pixels) ")))
# Get the number of bricks tall the user wants the pyramid to be
numBricks = int(eval(input("How many bricks tall do you want your pyramid to be? ")))
# Create the canvas
canvas = Picture((width, width))
# Fill in the background
canvas.drawRectFill(0, 0, width, width)
# Calculate brick height and width
brickHeight = int(width/numBricks)
brickWidght = int(width/numBricks)
# Loop through each row of the pyramid
for i in range(0, numBricks):
# Find the y coordinate for every brick in this row
brickY = brickHeight*(i + 1)
# Loop through each brick in each row
for j in range(int(1/2*brickHeight), numBricks - i):
# Find the x coordinate for each brick as you go along
brickX = brickHeight(j)
canvas.setPenColor(0, 0, 0)
canvas.drawRect(brickX, brickY, brickWidth, brickHeight)
canvas.display()