예제 #1
0
def main():
    canvas = Picture((500, 500))
    canvas.display()
    canvas.setPenColor(200,0,0)
    canvas.drawRectFill(250,250,200,200)
    canvas.display()
    input()
예제 #2
0
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
0
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
0
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
0
def main():
    # Create the canvas and fill in the background
    canvas = Picture((WIDTH, HEIGHT))
    chooseColor(canvas)
    canvas.drawRectFill(0, 0, WIDTH, HEIGHT)
    # Create 13 objects on the canvas
    for i in range(0, 13):
        chooseColor(canvas)
        chooseShape(canvas)
        
    canvas.display()
    canvas.writeFile("mlewisno.bmp")
예제 #6
0
def main() :
    W = 800
    H = 600
    art = Picture((W,H))
    art.setPenColor(20,0,20) #1
    art.drawRectFill(0,0,W,H) #2
    art = drawStars(art,W,H)
    art = drawMoon(art,60,60)
    art = drawLandscape(art)
    art = drawWolf(art,394,350)
    art.drawString(720,580,"-Tyler") #8
    art = pythonWT(art)
    art.writeFile("Wolf.bmp")
    art.display()
예제 #7
0
def main():
    width = eval(input("Enter a width for your canvas:  "))
    height = eval(input("Enter a height for your canvas:  "))
    n = eval(input("How many bricks tall would you like to make this pyramid?  "))
    
    canvas = Picture((width, height))
    x = 0
    y = height - (height/n)
    canvas.setPenColor(0,225,225)
    canvas.drawRectFill(0,0,width,height)

    drawPyramid(canvas, n, x, y, width, height)
    
    canvas.display()
예제 #8
0
def main() :
    # Gather user input
    width = eval(input("Please enter a width: "))
    n = eval(input("How many bricks tall will your pyramid be: "))
    # Set up the canvas
    canvas = Picture((width, width))
    canvas.setPenColor(0,255,255)
    canvas.drawRectFill(0,0,width,width)
    s = width//n
    # Place each brick in its proper location
    for i in range(0,n):
        x = (s//2)*i
        y = width - (i+1)*s
        for j in range(0,n-i):
            canvas = drawBrick(canvas,s,x,y)
            x += s
    # Display the canvas
    canvas.display()
예제 #9
0
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!")
예제 #10
0
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()
예제 #11
0
def main():
    try:
        width = eval(input("Enter a width/height of the canvas (pixels): "))
    except NameError:
        print("Please enter a numeric value.")
        return
    try:
        numBricks = eval(input("Enter a number of bricks for the height of the pyramid: "))
    except NameError:
        print("Please enter a numeric value.")
        return
    canvas = Picture((width, width))
    canvas.setPenColor(0, 255, 255)
    canvas.drawRectFill(0, 0, width, width)
    try:
        sideLength = width // numBricks
    except ZeroDivisionError:
        print("Please select a non-zero height for the pyramid.")
        return
    for i in range(0, numBricks):
        drawRow(canvas, i * (sideLength / 2), width - 1 - sideLength * (i+1), numBricks - i, sideLength)
    canvas.display()
예제 #12
0
def main() :
    # Gather user input
    try:
        width = eval(input("Please enter a width: "))
        n = eval(input("How many bricks tall will your pyramid be: "))
        # Set up the canvas
        canvas = Picture((width, width))
        canvas.setPenColor(0,255,255)
        canvas.drawRectFill(0,0,width,width)
        s = width//n
        # Place each brick in its proper location
        for i in range(0,n):
            x = (s//2)*i
            y = width - (i+1)*s
            for j in range(0,n-i):
                canvas = drawBrick(canvas,s,x,y)
                x += s
        # Display the canvas
        canvas.display()
    except ZeroDivisionError:
        print("Divide by zero error, enter a value greater than zero next time.")
    except NameError:
        print("Your input was not a number")
예제 #13
0
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()
예제 #14
0
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()
예제 #15
0
파일: life.py 프로젝트: Ash927/python-labs
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:
        print("Sorry, something unexpected has occured.  Please reload the program.")