本文整理汇总了Python中picture.Picture.drawRectFill方法的典型用法代码示例。如果您正苦于以下问题:Python Picture.drawRectFill方法的具体用法?Python Picture.drawRectFill怎么用?Python Picture.drawRectFill使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类picture.Picture
的用法示例。
在下文中一共展示了Picture.drawRectFill方法的9个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: main
# 需要导入模块: from picture import Picture [as 别名]
# 或者: from picture.Picture import drawRectFill [as 别名]
def main():
canvas = Picture((500, 500))
canvas.display()
canvas.setPenColor(200,0,0)
canvas.drawRectFill(250,250,200,200)
canvas.display()
input()
示例2: main
# 需要导入模块: from picture import Picture [as 别名]
# 或者: from picture.Picture import drawRectFill [as 别名]
def main():
width = eval(input("Enter a width/height of the canvas (pixels): "))
numBricks = eval(input("Enter a number of bricks for the height of the pyramid: "))
canvas = Picture((width, width))
canvas.setPenColor(0, 255, 255)
canvas.drawRectFill(0, 0, width, width)
sideLength = width // numBricks
for i in range(0, numBricks):
drawRow(canvas, i * (sideLength / 2), width - 1 - sideLength * (i+1), numBricks - i, sideLength)
canvas.display()
示例3: main
# 需要导入模块: from picture import Picture [as 别名]
# 或者: from picture.Picture import drawRectFill [as 别名]
def main():
pic = Picture((800,800))
pic.setPenColor(128,80,255)
pic.drawRectFill(0,0,800,800)
for i in range(0, NUM_BUILDINGS):
drawBuilding(pic)
for i in range(0, 24):
drawSun(pic, i)
pic.writeFile("guss.bmp")
input()
示例4: main
# 需要导入模块: from picture import Picture [as 别名]
# 或者: from picture.Picture import drawRectFill [as 别名]
def main():
width = eval(input("Please enter the desired width for the canvas: "))
n = eval(input("Please enter the desired number of blocks for bottom row of the pyramid: "))
size=width/n
canvas = Picture((width, width))
canvas.setPenColor(255,0,0)
for i in range(0,n): #loop through the rows of the pyramid
for j in range(i,n): #loop through the bricks
canvas.drawRectFill(i*size/2+(j-i)*size,width-size*(i+1),size-2,size-1) #draw each rectangle, stopping a pixil short to leave visible lines between each block
canvas.display() #display the pyramid
input("Press enter to end the program.") #leave an input so the program doesnt end before we can see the picture
示例5: main
# 需要导入模块: from picture import Picture [as 别名]
# 或者: from picture.Picture import drawRectFill [as 别名]
def main():
try:
width = eval(input("Please enter the desired width for the canvas: "))
n = eval(input("Please enter the desired number of blocks for bottom row of the pyramid: "))
size=width/n
canvas = Picture((width, width))
canvas.setPenColor(255,0,0)
for i in range(0,n): #loop through the rows of the pyramid
for j in range(i,n): #loop through the bricks
canvas.drawRectFill(i*size/2+(j-i)*size,width-size*(i+1),size-2,size-1) #draw each rectangle, stopping a pixil short to leave visible lines between each block
canvas.display() #display the pyramid
input("Press enter to end the program.") #leave an input so the program doesnt end before we can see the picture
except ZeroDivisionError:
print("\nPlease enter something besides 0.")
except NameError:
print("Please enter intergers, nothing else.")
except:
print("Sorry, something unexpected has gone wrong!")
示例6: main
# 需要导入模块: from picture import Picture [as 别名]
# 或者: from picture.Picture import drawRectFill [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()
示例7: main
# 需要导入模块: from picture import Picture [as 别名]
# 或者: from picture.Picture import drawRectFill [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()
示例8: main
# 需要导入模块: from picture import Picture [as 别名]
# 或者: from picture.Picture import drawRectFill [as 别名]
def main() :
print("1. Bubbles\n2. Carpet\n3. Gasket\n4. Snowflake\n\n")
choice = eval(input("Input the number of the pattern you would like:"))
size = eval(input("Please enter a size: "))
depth = eval(input("Please enter a depth: "))
if choice == 1 : #Draw Bubbles
canvas = Picture((size*4,size*4))
canvas.setPenColor(255,102,0)
canvas.drawRectFill(0,0,size*4,size*4)
canvas.setPenColor(0,0,255)
canvas = bubbles(canvas,0,0,size*4,depth)
canvas.display()
if choice == 2 : #Draw Carpet
canvas = Picture((size*3,size*3))
canvas.setPenColor(0,255,0)
canvas.drawRectFill(0,0,size*3,size*3)
canvas.setPenColor(255,0,0)
canvas = carpet(canvas,0,0,size*3,depth)
canvas.display()
if choice == 3 : #Draw Gasket
canvas = Picture((size,size))
canvas.setPenColor(0,255,255)
canvas.drawRectFill(0,0,size,size)
canvas.setPenColor(0,0,255)
canvas.fillPoly([0,size//2,size],[size,0,size])
canvas.setPenColor(0,255,255)
canvas = gasket(canvas,0,0,size,depth)
canvas.display()
if choice == 4 : #Draw Snowflake
canvas = Picture((size + (size//2),size + (size//2)))
canvas.setPenColor(80,0,80)
canvas.drawRectFill(0,0,size + (size//2),size + (size//2))
canvas.setPenColor(0,255,0)
canvas.setPosition(size + (size//4),size)
canvas.rotate(240)
canvas = snowflake(canvas,size,depth)
canvas.rotate(240)
canvas = snowflake(canvas,size,depth)
canvas.rotate(240)
canvas = snowflake(canvas,size,depth)
canvas.display()
示例9: main
# 需要导入模块: from picture import Picture [as 别名]
# 或者: from picture.Picture import drawRectFill [as 别名]
def main():
try:
#Set variables
WIDTH = 50
HEIGHT = 80
CELL_SIZE = 6
ROUNDS = 500
#create picture
canvas = Picture((WIDTH*CELL_SIZE+1,HEIGHT*CELL_SIZE+1))
#create lists that represent the board
board = []
boardCopy = []
for i in range(0,WIDTH):
h = []
hCopy = []
for j in range(0,HEIGHT):
h.append(0)
hCopy.append(0)
board.append(h)
boardCopy.append(hCopy)
#draw out the grid
canvas.setPenColor(0,0,0)
canvas.drawRectFill(0,0,WIDTH*CELL_SIZE,HEIGHT*CELL_SIZE)
canvas.setPenColor(0,255,0)
canvas.drawLine(0,HEIGHT*CELL_SIZE,WIDTH*CELL_SIZE,HEIGHT*CELL_SIZE)
canvas.drawLine(WIDTH*CELL_SIZE,0,HEIGHT*CELL_SIZE,WIDTH*CELL_SIZE)
for i in range(0,HEIGHT):
canvas.drawLine(0,CELL_SIZE*i,WIDTH*CELL_SIZE,i*CELL_SIZE)
for i in range(0,WIDTH):
canvas.drawLine(CELL_SIZE*i,0,i*CELL_SIZE,HEIGHT*CELL_SIZE)
n=0
while n<1 or n>3:
n = eval(input("Please enter a number 1-3: "))
if n==1:
board[39][40]=1
board[40][39]=1
board[40][40]=1
board[41][40]=1
board[39][41]=1
elif n==2:
board[39][39]=1
board[39][40]=1
board[39][41]=0
board[40][39]=0
board[40][40]=1
board[40][41]=0
board[41][39]=0
board[41][40]=1
board[41][41]=0
board[39][42]=0
board[39][43]=1
board[39][44]=0
board[40][42]=0
board[40][43]=1
board[40][44]=0
board[41][42]=1
board[41][43]=1
board[41][44]=0
elif n==3:
board[39][39]=1
board[39][40]=0
board[39][41]=1
board[40][39]=1
board[40][40]=1
board[40][41]=0
board[41][39]=1
board[41][40]=0
board[41][41]=1
else:
print("Please try again")
#Draw any squares the start alive red.
for i in range(0,WIDTH):
for j in range(0,HEIGHT):
if board[i][j]==1:
canvas.setPenColor(255,0,0)
canvas.drawRectFill(i*CELL_SIZE+1,j*CELL_SIZE+1,CELL_SIZE-2,CELL_SIZE-2)
if board[i][j]==0:
canvas.setPenColor(0,0,0)
canvas.drawRectFill(i*CELL_SIZE+1,j*CELL_SIZE+1,CELL_SIZE-2,CELL_SIZE-2)
canvas.display()
#begin the game of life
for count in range(0,ROUNDS):
for i in range(0,WIDTH):
for j in range(0,HEIGHT):
boardCopy[i][j]=lifeCheck(board,i,j,WIDTH,HEIGHT)
if boardCopy[i][j]==1:
canvas.setPenColor(255,0,0)
canvas.drawRectFill(i*CELL_SIZE+1,j*CELL_SIZE+1,CELL_SIZE-2,CELL_SIZE-2)
else:
canvas.setPenColor(0,0,0)
canvas.drawRectFill(i*CELL_SIZE+1,j*CELL_SIZE+1,CELL_SIZE-2,CELL_SIZE-2)
canvas.display()
for i in range(0,WIDTH):
for j in range(0,HEIGHT):
board[i][j]=boardCopy[i][j]
except NameError:
print("Please enter a valid number next time.")
except SyntaxError:
print("Please enter a valid number next time.")
except:
#.........这里部分代码省略.........