Ejemplo n.º 1
0
def main():
    # Introduction
    print("This program plots the growth of a 10-year investment.")
    # Get principal and interest rate
    principal = float(input(" Enter the initial principal: "))
    apr = float(input(" Enter the annualized interest rate: "))
    # Create a graphics window with labels on left edge
    win = GraphWin("Investment Growth Chart ", 320, 240)
    win.setBackground("white")
    Text(Point(20, 230), ' 0.0K').draw(win)
    Text(Point(20, 180), ' 2.5K').draw(win)
    Text(Point(20, 130), ' 5.0K').draw(win)
    Text(Point(20, 80), ' 7.5K').draw(win)
    Text(Point(20, 30), '10.0K').draw(win)
    # Draw bar for initial principal
    height = principal * 0.02
    bar = Rectangle(Point(40, 230), Point(65, 230 - height))
    bar.setFill("green")
    bar.setWidth(2)
    bar.draw(win)
    # Draw bars for successive years
    for year in range(1, 11):
        # calculate value for the next year
        principal = principal * (1 + apr)
        # draw bar for this value
        xll = year * 25 + 40
        height = principal * 0.02
        bar = Rectangle(Point(xll, 230), Point(xll + 25, 230 - height))
        bar.setFill("green")
        bar.setWidth(2)
        bar.draw(win)
    input(" Press <Enter> to quit ")
    win.close()
Ejemplo n.º 2
0
def eye_picker():
    """
    8. The pract06.py file contains an incomplete draw_coloured_eye() function
    for which the graphics window, centre point, radius and eye colour (a
    string) are given as parameters. Complete the draw_coloured_eye() function
    so that it draws an eye like those from last week, but for any given colour.
    Write another function eye_picker() that asks the user for the coordinates
    of the centre of an eye, its radius and colour. If the user inputs a valid
    eye colour (blue, grey, green, or brown), then an appropriately coloured eye
    should be displayed in a graphics window. Otherwise, just a 'not a valid eye
    colour' message should be output. Remember to avoid repetitive code.
    """
    centre_coord = eval(
        input(
            "Enter the coordinate for the centre of the eye (as a tuple) > "))
    x_coord, y_coord = centre_coord
    centre = Point(x_coord, y_coord)
    radius = float(input("Enter the radius of the eye > "))
    colours = ["grey", "green", "blue", "green"]
    print(*colours, sep=", ")

    while True:
        try:
            colour = input("Enter the colour of the eye > ").lower()
            if colour in colours:
                break
        except TclError:
            print("Not a valid eye colour")

    win = GraphWin("Coloured eye")
    draw_coloured_eye(win, centre, radius, colour)

    win.getMouse()
    win.close()
Ejemplo n.º 3
0
def main():

    # create the application window
    win = GraphWin("Dice Roller")
    win.setCoords(0,0,10,10)
    win.setBackground("gray")

    # draw the interface widgets
    die1 = DieView(win, Point(3,7), 2)
    die2 = DieView(win, Point(7,7), 2)
    rollButton = Button(win, Point(5,4.5), 6, 1, "Roll Dice")
    rollButton.activate()
    quitButton = Button(win, Point(5,1), 2, 1, "Quit")

    # event loop
    pt = win.getMouse()
    while not quitButton.clicked(pt):
        if rollButton.clicked(pt):
            # re-rolling value and pip color of die1
            value1 = randrange(1, 7)
            color = color_rgb(randrange(0,256), randrange(0,256), randrange(0,256))
            die1.setValue(value1)
            die1.setColor(color)
            # re-rolling value and pip color of die2
            value2 = randrange(1, 7)
            color = color_rgb(randrange(0,256), randrange(0,256), randrange(0,256))
            die2.setValue(value2)
            die2.setColor(color)
            quitButton.activate()
        pt = win.getMouse()

    # close up shop
    win.close()
Ejemplo n.º 4
0
def draw_tour(tour):
    from graphics import Point, Circle, Line, GraphWin
    maxX = max([x for x, y in tour])
    minX = min([x for x, y in tour])
    maxY = max([y for x, y in tour])
    minY = min([y for x, y in tour])

    N = 750
    norm_x = N / (maxX - minX)
    norm_y = N / (maxY - minY)

    win = GraphWin("TSP", N, N)
    for n in tour:
        c = Point(*norm(n, norm_x, norm_y, minX, minY))
        c = Circle(c, 2)
        c.draw(win)

    for i, _ in enumerate(tour[:-1]):
        p1 = norm(tour[i], norm_x, norm_y, minX, minY)
        p2 = norm(tour[i + 1], norm_x, norm_y, minX, minY)
        l = Line(Point(*p1), Point(*p2))
        l.draw(win)

    win.getMouse()
    win.close()
def main():

    # create the application window
    win = GraphWin("Dice Roller")
    win.setCoords(0, 0, 10, 10)
    win.setBackground("green2")

    # Draw the interface widgets
    die1 = DieView(win, Point(3,7), 2)
    die2 = DieView(win, Point(7,7), 2)
    rollButton = Button(win, Point(5,4.5), 6, 1, "Roll Dice")
    rollButton.activate()
    quitButton = Button(win, Point(5,1), 2, 1, "Quit")

    # Event loop
    pt = win.getMouse()
    while not quitButton.clicked(pt):
        if rollButton.clicked(pt):
            value1 = randrange(1,7)
            die1.setValue(value1)
            value2 = randrange(1,7)
            die2.setValue(value2)
            quitButton.activate()
        pt = win.getMouse()

    # close up shop
    win.close()
Ejemplo n.º 6
0
def draw_tour(path_d, all_nodes):
	from graphics import Point, Circle, Line, GraphWin
	maxX = max([x for x, y in all_nodes])
	minX = min([x for x, y in all_nodes])
	maxY = max([y for x, y in all_nodes])
	minY = min([y for x, y in all_nodes])

	N = 750
	norm_x = N/(maxX - minX)
	norm_y = N/(maxY - minY)

	win = GraphWin("TSP", N, N)
	for n in all_nodes:
		c = Point(*norm(n, norm_x, norm_y, minX, minY))
		c = Circle(c, 3)
		c.draw(win)

	for (k, subdict) in path_d.iteritems():
		#t = Text(Point(*subdict['center']*N), k)
		#t.draw(win)
		if not subdict['hasBeenSplit']:
			p = Point(*norm(subdict['center'], norm_x, norm_y, minX, minY))

			c1i, c2i = subdict['connections']
			c1 = Point(*norm(path_d[str(c1i)]['center'], norm_x, norm_y, minX, minY))
			c2 = Point(*norm(path_d[str(c2i)]['center'], norm_x, norm_y, minX, minY))
			l1 = Line(p, c1)
			l2 = Line(p, c2)
			l1.draw(win)
			l2.draw(win)

	win.getMouse()
	win.close()
Ejemplo n.º 7
0
def main():
    print("This program plots the growth of a 10-year investment.")
    print()

    principal = eval(input("Enter the initial principal: "))
    apr = eval(input("Enter the annualized interest rate: "))

    win = GraphWin("Investment Growth Chart", 320, 240)
    win.setBackground("white")
    win.setCoords(-1.75, -200, 11.5, 10400)

    Text(Point(-1, 0), "0.0K").draw(win)
    Text(Point(-1, 2500), "2.5K").draw(win)
    Text(Point(-1, 5000), "5.0K").draw(win)
    Text(Point(-1, 7500), "7.5K").draw(win)
    Text(Point(-1, 10000), "10.0K").draw(win)

    draw_bar(win, 0, principal)

    for year in range(1, 11):
        principal = principal * (1 + apr)
        draw_bar(win, year, principal)

    input("Press <Enter> to quit.")

    win.close()
Ejemplo n.º 8
0
def main():

    # Create animation window
    win = GraphWin("Projectile Animation", 640, 480, autoflush=False)
    win.setCoords(-10, -10, 210, 155)
    # Draw baseline
    Line(Point(-10, 0), Point(210, 0)).draw(win)
    # Draw labeled ticks every 50 meters
    for x in range(0, 210, 50):
        Text(Point(x, -5), str(x)).draw(win)
        Line(Point(x, 0), Point(x, 2)).draw(win)

    # Event loop, each time through fires a single shot
    angle, vel, height = 45.0, 40.0, 2.0
    while True:
        # Interact with the user
        inputwin = InputDialog(angle, vel, height)
        choice = inputwin.interact()
        inputwin.close()

        if choice == "Quit": # Loop exit
            break

        # Create a shot and track until it hits ground or leaves window
        angle, vel, height = inputwin.getValues()
        shot = ShotTracker(win, angle, vel, height)
        while 0 <= shot.getY() and -10 < shot.getX() <= 210:
            shot.update(1/50)
            update(50)

        win.close()
def main():
    #draw main window
    win = GraphWin('Dice Roller', 500, 500)
    win.setCoords(0, 0, 10, 10)
    win.setBackground('green2')

    #draw die and buttons
    die1 = DieView(win, Point(3, 6.5), 2)
    die2 = DieView(win, Point(7, 6.5), 2)
    rollButton = Button(win, Point(3, 2.5), 4, 1, 'Roll Dice')
    rollButton.activate()
    quitButton = Button(win, Point(8, 2.5), 2, 1, 'Quit')

    #event loop
    pt = win.getMouse()
    while not quitButton.clicked(pt):
        if rollButton.clicked(pt):
            a, b = randrange(1, 7), randrange(1, 7)
            die1.setValue(a)
            die2.setValue(b)
            quitButton.activate()
            pt = win.getMouse()

    #clean up
    win.close()
Ejemplo n.º 10
0
def get_window(x=600, y=600):
    try:
        win = GraphWin('', x, y)
        yield ([], [], x, y, win)
        win.getMouse()
    finally:
        win.close()
Ejemplo n.º 11
0
def debug_window():
    from graphics import GraphWin

    win = GraphWin('Floor', SCREEN_WIDTH_PX, SCREEN_HEIGHT_PX)
    win.setBackground("black")

    for circle in circle_grid():
        for [x, y] in circle.points(factor=1.):
            win.plotPixel(x, y, "white")
    
    # for circle in circle_grid():
    #     for [x, y] in circle.points(factor=2.):
    #         win.plotPixel(x, y, "white")

    for donut_slice in donut_grid():
        for [x, y] in donut_slice:
            win.plotPixel(x, y, "white")
            sleep(0.001)

    # gaze = RandomPoint.pick()
    # stimulus = random.choice(STIMULI_COORDENATES)
    # for i in np.arange(0,1000,0.01): 
    #     gaze = gaze.add(gaze.pick(r=1))
    #     x, y = (gaze.x*10)+stimulus[0]+50, (gaze.y*6)+stimulus[1]+50
    #     win.plotPixel(x, y, "white")
    #     if x > stimulus[0]+100 or x < stimulus[0]:
    #         gaze = RandomPoint.pick()
    #         stimulus = random.choice(STIMULI_COORDENATES)

    #     if y > stimulus[1]+100 or y < stimulus[1]:
    #         gaze = RandomPoint.pick()
    #         stimulus = random.choice(STIMULI_COORDENATES)

    win.getKey()
    win.close()
Ejemplo n.º 12
0
def main():
    print("This program plots the growth of a 10-year investment!")

    principal = eval(input("Enter the initial principal: "))
    apr = eval(input("Enter the annualized interest rate: "))

    win = GraphWin("Investment Growth Chart", 320, 240)
    win.setBackground("white")
    win.setCoords(-1.75, -200, 11.5, 10400)

    Text(Point(-1, 0), "0.0K").draw(win)
    Text(Point(-1, 2500), "2.5K").draw(win)
    Text(Point(-1, 5000), "5.0K").draw(win)
    Text(Point(-1, 7500), "7.5K").draw(win)
    Text(Point(-1, 10000), "10.0K").draw(win)

    bar = Rectangle(Point(0, 0), Point(1, principal))
    bar.setFill("green")
    bar.setWidth(2)
    bar.draw(win)

    for year in range(1, 11):
        principal = principal * (1 + apr)
        bar = Rectangle(Point(year, 0), Point(year + 1, principal))
        bar.setFill("green")
        bar.setWidth(2)
        bar.draw(win)

    input("Press <Enter> to quit.")
    win.close()
Ejemplo n.º 13
0
def main():
    win = GraphWin('Dice Roller')
    win.setCoords(0, 0, 10, 10)
    win.setBackground('green2')

    die1 = MultiSidedDie(6)
    die2 = MultiSidedDie(6)
    dieView1 = DieView(win, Point(3, 7), 2)
    dieView2 = DieView(win, Point(7, 7), 2)

    rollButton = Button(win, Point(5, 4.5), 6, 1, 'Roll Dice')
    rollButton.activate()

    quitButton = Button(win, Point(5, 1), 2, 1, 'Quit')

    point = win.getMouse()
    while not quitButton.clicked(point):
        if rollButton.clicked(point):
            die1.roll()
            dieView1.drawValue(die1.getValue())
            die2.roll()
            dieView2.drawValue(die2.getValue())
            quitButton.activate()
        point = win.getMouse()

    win.close()
Ejemplo n.º 14
0
def drawTree(pathFile):
    """Draw the tree of the annotatedFile provided
    
    Args:
        the path of the annotated data file (string)
    Returns:
        a board with the words printed on it (board, from graphics)
        
    """

    listWords = createListWords(pathFile)
    #definition of the Board to print the tree
    boardLength = width
    boardHeight = height
    board = GraphWin("Billy's Tree Board", boardLength, boardHeight)
    #def of my anchor for the first point
    offset = (getRootIndex(listWords) / len(listWords))
    rootPositionX = offset * boardLength + 75
    rootPositionY = offset * boardHeight + 75
    #place the words on the board
    listWordOnBoard = setupRoot(board, rootPositionX, rootPositionY, listWords)
    setupRestOfWords(board, rootPositionX, rootPositionY, listWordOnBoard,
                     listWords)
    #pause, wait for a click on the window, then close properly
    board.getMouse()
    board.close()
Ejemplo n.º 15
0
def main():

    # create the application window
    win = GraphWin("Dice Roller")
    win.setCoords(0, 0, 10, 10)
    win.setBackground("green2")

    # Draw the interface widgets
    die1 = DieView(win, Point(3, 7), 2)
    die2 = DieView(win, Point(7, 7), 2)
    rollButton = CButton(win, Point(5, 4.5), 1.5, "Roll Dice")
    rollButton.activate()
    quitButton = CButton(win, Point(5, 1), 1, "Quit")

    # Event loop
    pt = win.getMouse()
    while not quitButton.clicked(pt):
        if rollButton.clicked(pt):
            value1 = randrange(1, 7)
            die1.setValue(value1)
            value2 = randrange(1, 7)
            die2.setValue(value2)
            quitButton.activate()
        pt = win.getMouse()

    # close up shop
    win.close()
def main():

    # create application window
    win = GraphWin("Three Door Monte", 600, 400)
    win.setCoords(0, 0, 15, 10)
    win.setBackground("darkgrey")

    # create game
    doorMonte = Game(win)

    # create replay and quit button
    quitbutton = Button(win, Point(11.25, 1), 3, 1.5, "Quit")
    quitbutton.activate()
    replay = Button(win, Point(3.75, 1), 3, 1.5, "Replay")

    # event loop
    click = win.getMouse()
    while not quitbutton.clicked(click):
        if doorMonte.doorPicked(click):
            replay.activate()
        elif replay.clicked(click):
            doorMonte.reset()
        click = win.getMouse()

    win.close()
Ejemplo n.º 17
0
def draw_patch_window():
    """
    9. Write a function draw_patch_window() (without parameters) which displays, in
    a graphics window of size 100 × 100 pixels, the patch design which is
    labelled with the final digit of your student number. The patch design
    should be displayed in red, as in the table. It's important that your
    program draws the patch design accurately, but don't worry if one pixel is
    chopped off at the edge of the window. Note that you don't need to draw a
    border around the patch design.
    """
    win = GraphWin("Patch design", 100, 100)
    for distance in (20, 40, 60, 80, 100):
        line = Line(Point(0, distance), Point(distance, 0))
        line.setFill("red")
        line.setWidth(2)
        line.draw(win)

        line = Line(Point(100 - distance, 0), Point(100, distance))
        line.setFill("red")
        line.setWidth(2)
        line.draw(win)

    for distance in (20, 40, 60, 80):
        line = Line(Point(distance, 100), Point(100, distance))
        line.setFill("red")
        line.setWidth(2)
        line.draw(win)

        line = Line(Point(0, distance), Point(100 - distance, 100))
        line.setFill("red")
        line.setWidth(2)
        line.draw(win)

    win.getMouse()
    win.close()
Ejemplo n.º 18
0
def main():
    win = GraphWin("Dice Poker", 600, 400)
    win.setBackground("green3")
    banner = Text(Point(300, 30), "Python Poker Parlor")
    banner.setSize(24)
    banner.setFill("yellow2")
    banner.setStyle("bold")
    banner.draw(win)
    letsPlayBtn = Button(win, Point(300, 300), 400, 40, "Let's Play!")
    letsPlayBtn.activate()
    exitBtn = Button(win, Point(300, 350), 400, 40, "Exit")
    exitBtn.activate()
    showHighScores(win)

    while True:
        p = win.getMouse()

        if letsPlayBtn.clicked(p):
            win.close()
            inter = GraphicsInterface()
            app = PokerApp(inter)
            app.run()
            break

        if exitBtn.clicked(p):
            win.close()
            break
Ejemplo n.º 19
0
def main(window_width, window_height, square_dim, filename):

    window = GraphWin("Karnaugh Map", window_width, window_height)

    window.setBackground(color_rgb(255, 255, 255))

    for line in get_k_map_lines(window_width, window_height, square_dim):
        line.setWidth(1)
        line.setFill(color_rgb(0, 0, 0))
        line.draw(window)

    variables = [(chr(i), chr(i) + "'") for i in range(65, 91)]
    shuffle(variables)
    for label in get_k_map_variable_labels(window_width, window_height, square_dim, variables):
        label.setTextColor('black')
        label.setSize(30)
        label.draw(window)

    k_map_values = get_k_map_values()
    for text in get_k_map_text_values(window_width, window_height, square_dim, k_map_values):
        text.setTextColor('black')
        text.setSize(30)
        text.draw(window)
    # print(k_map_values)
    ps = window.postscript(colormode='color')
    img = Image.open(io.BytesIO(ps.encode('utf-8')))
    img.save(filename)

    window.close()
Ejemplo n.º 20
0
def main():
    #create app window
    win = GraphWin("Dice Roller")
    win.setCoords(0, 0, 10, 10)
    win.setBackground('green2')

    #draw interface widgets
    die1 = DieView(win, Point(3, 7), 2)
    die2 = DieView(win, Point(7, 7), 2)
    rollButton = Button(win, Point(5, 4.5), 6, 1, 'Roll Dice')
    rollButton.activate()
    quitButton = Button(win, Point(5, 1), 2, 1, 'Quit')

    #event loop
    pt = win.getMouse()
    while not quitButton.clicked(pt):
        if rollButton.clicked(pt):
            value1 = randrange(1, 7)
            die1.setValue(value1)
            value2 = randrange(1, 7)
            die2.setValue(value2)
            quitButton.activate()
        pt = win.getMouse()

    #close shope
    win.close()
Ejemplo n.º 21
0
class OptionGUI(GUI):
	# initialize, and popup
	# syntax: OptionGUI(bannerText, option1Text, option1Callback, option2Text, option2Callback)
	# parameters:
		# bannerText: appears above the two buttons (string)
		# option1Text: appears on first button (string)
		# option1Callback: called if option1 button is clicked (function)
		# option2Text: appears on second button (string)
		# option2Callback: called if option2 button is clicked (function)
	def __init__(self, bannerText, option1Text, option1Callback, option2Text, option2Callback):
		self.window = GraphWin("", 500, 200)
		super().__init__()
		
		self.add(Button(Point(100 , 100), option1Text, lambda: self.__closeAndCall(option1Callback)))
		self.add(Button(Point(300 , 100), option2Text, lambda: self.__closeAndCall(option2Callback)))
		banner = TextArea(Point(250, 50))
		banner.add(bannerText, "black", 17, 0, 0)
		self.add(banner)
	# draw OptionGUI
	# syntax: self.draw()
	# parameter: None
	# returns: None
	def draw(self):
		super().draw(self.window)
	
		
	# close the option window then call the given function
	# syntax: self.__closeAndCall(callback)
	# parameter: 
		# callback: gets called after window closes (function)
	# returns: None
	def __closeAndCall(self, callback):
		self.window.close()
		callback()
Ejemplo n.º 22
0
def get_image_path():
    width, height = 300, 150
    win = GraphWin("Image Path", width, height)
    win.setBackground(color_rgb(0, 0, 0))

    path_entry = Entry(Point(width // 2, height // 2 - 50), 30)
    path_entry.draw(win)

    ok_button = Rectangle(Point(width - 50, height - 50),
                          Point(width - 5, height - 5))
    ok_button.setFill(color_rgb(255, 255, 255))
    ok_button.draw(win)
    ok_button_text = Text(ok_button.getCenter(), "OK")
    ok_button_text.setSize(15)
    ok_button_text.draw(win)

    while True:
        click = win.getMouse()
        clickx = click.getX()
        clicky = click.getY()

        if ok_button.getP1().getX() <= clickx <= ok_button.getP2().getX(
        ) and ok_button.getP1().getY() <= clicky <= ok_button.getP2().getY():
            win.close()
            return str(path_entry.getText())
Ejemplo n.º 23
0
def main():

    # create the application window
    win = GraphWin("Dice Roller", )
    win.setCoords(0, 0, 10, 10)
    win.setBackground("green2")

    # draw the interface widgets

    b1 = Button(win, Point(4, 2), 3, 2, "Roll")
    b2 = Button(win, Point(8, 2), 3, 2, "Quit")

    d1 = DieView(win, Point(3, 6), 3)
    d2 = DieView(win, Point(7, 6), 3)

    # event loop

    while True:
        if b1.clicked(win.getMouse()):
            d1.setValue(MSdie().setValue())
            d2.setValue(MSdie().setValue())
        elif b2.clicked(win.getMouse()):
            return False

    # close the window
    win.close()
Ejemplo n.º 24
0
def main():

    # create the application window
    win = GraphWin("Dice Roller", WINDOW_WIDTH, WINDOW_HEIGHT)
    win.setBackground("black")

    # draw the interface widgets
    centerPoint = Point(WINDOW_WIDTH / 2, WINDOW_HEIGHT / 2)
    quit = Button(win, Point(WINDOW_WIDTH - 75, WINDOW_HEIGHT - 50), 75, 50,
                  'Quit')
    quit.activate()

    roll = Button(win, Point(WINDOW_WIDTH - 150, WINDOW_HEIGHT - 50), 75, 50,
                  'Roll')
    roll.activate()

    die1 = DieView(win, Point(WINDOW_WIDTH / 2 - 50, WINDOW_HEIGHT / 2), 50)
    die2 = DieView(win, Point(WINDOW_WIDTH / 2 + 50, WINDOW_HEIGHT / 2), 50)

    # event loop
    run = True
    while run:
        clickPoint = win.getMouse()
        if (roll.clicked(clickPoint)):
            die1.setValue(randrange(1, 7))
            die2.setValue(randrange(1, 7))
        run = not quit.clicked(clickPoint)

    # close the window
    win.close()
Ejemplo n.º 25
0
def main():
    fileInput = "C:\Programming\CS138\Week 8\canoe.gif"
    fileOutput = "C:\Programming\CS138\Week 8\grayCanoe.gif"

    image = Image(Point(400, 300), fileInput)  # Getting our image.
    width = image.getWidth()
    height = image.getHeight()
    win = GraphWin("Monochromatic Conversion", width,
                   height)  # Creating our window.
    image.draw(win)

    row = 0  # The starting pixel for our x-axis
    column = 0  # The starting pixel for our y-axis

    win.getMouse()

    for row in range(image.getWidth()):
        for column in range(image.getHeight()):
            r, g, b = image.getPixel(row, column)
            brightness = int(round(0.299 * r + 0.587 * g + 0.114 * b))
            image.setPixel(row, column,
                           color_rgb(brightness, brightness, brightness))
            win.update()

    image.save(fileOutput)
    win.getMouse()
    win.close()
Ejemplo n.º 26
0
def main() :
    # Introduction
    print ( " This program plots the growth of a 10-year investment . " )
    # Get principal and interest rate
    principal = float(input ("Enter the initial principal : "))
    apr = float(input("Enter the annualized interest rate : "))
    # Create a graphics window with labels on left edge
    win = GraphWin ("Investment Growth Chart ", 320 , 240)
    win.setBackground ("white")
    win.setCoords (-1.75, -200 , 11.5, 10400)

    Text(Point (- 1, 0) , ' 0.0K').draw (win)
    Text(Point (- 1, 2500) , '2.5K').draw (win)
    Text(Point (- 1, 5000) , ' 5.0K').draw (win)
    Text(Point (- 1, 7500) , ' 7.5k').draw (win)
    Text(Point (- 1, 10000) , '10.0K').draw (win)
    # Draw bar f or init ial princ ipal
    bar = Rectangle (Point (0, 0) , Point (1, principal))
    bar.setFill ("green")
    bar.setWidth (2)
    bar.draw (win)
    # Draw a bar for each subsequent year
    for year in range (1, 11) :
        principal = principal * ( 1 + apr)
        bar = Rectangle (Point (year, 0), Point (year+ 1 , principal ))
        bar.setFill ("green")
        bar.setWidth (2)
        bar.draw(win)
    input(" Press <Enter> to quit.")
    win.close ()
Ejemplo n.º 27
0
def view_pop(pop, hold=False):
    win = GraphWin("Polygons", 200, 200)
    for i, indie in enumerate(pop):
        text = Text(Point(180, 180), fitness(indie))
        indie.draw(win)
        text.draw(win)
        time.sleep(0.5)
        indie.undraw()
        text.undraw()
    if hold:
        win.getMouse()
    win.close()
Ejemplo n.º 28
0
def test():
    window = GraphWin()
    window.setCoords(0, 0, 10, 10)
    r = Rectangle(Point(1, 1), Point(2, 2))
    r.setFill("red")
    r.draw(window)
    for i in range(10):
        time.sleep(1)
        r.undraw()
        r.move(1, 0)
        r.draw(window)
    window.getMouse()
    window.close()
Ejemplo n.º 29
0
def main():

    # create the application window
    window = GraphWin("Dice Roller")
    window.setCoords(0, 0, 10, 10)
    window.setBackground("green2")

    # draw the interface widgets

    # event loop

    # close the window
    window.close()
Ejemplo n.º 30
0
def main():
    win = GraphWin("Five Click House", 500, 500)
    win.setBackground(color_rgb(43, 43, 43))

    p = win.getMouse()
    p1 = Point(p.getX(), p.getY())
    p = win.getMouse()
    p2 = Point(p.getX(), p.getY())
    base = Rectangle(p1, p2)  # Base of the house, initial rectangle.
    base.setOutline(color_rgb(180, 180, 180))
    base.draw(win)

    dist = sqrt((p2.getX() - p1.getX())**2 +
                (p2.getY() - p1.getY())**2)  # Distance between p1 and p2.
    baseHeight = p1.getY() - p2.getY()  # Height of the 'base' object.
    baseWidth = p2.getX() - p1.getX()  # Width of the 'base' object.
    doorWidth = (baseWidth / 5)

    p = win.getMouse()
    p3 = Point(p.getX(), p.getY())  # Third Mouse Click.
    p4 = Point((p3.getX() - doorWidth / 2), p3.getY())  # Top left of door.
    p5 = Point(p3.getX() + doorWidth / 2,
               p1.getY())  # Bottom right of the door.
    door = Rectangle(p4, p5)
    door.setOutline(color_rgb(180, 180, 180))
    door.draw(win)

    p = win.getMouse()
    p6 = Point(p.getX(), p.getY())  # Fourth Click.
    p7 = Point(p6.getX() - doorWidth / 4,
               p6.getY() - doorWidth / 4)  # Top left of the window.
    p8 = Point(p6.getX() + doorWidth / 4,
               p6.getY() + doorWidth / 4)  # Bottom right of the window
    window = Rectangle(p7, p8)
    window.setOutline(color_rgb(180, 180, 180))
    window.draw(win)

    p = win.getMouse()
    p9 = Point(p.getX(), p.getY())  # Fifth Mouse Click, also tip of roof.
    p10 = Point(p1.getX(), p1.getY() - baseHeight)  # Left corner of roof.
    p11 = Point(p2.getX(), p2.getY())  # Right corner of roof.
    roof = Polygon(p9, p10, p11)
    roof.setOutline(color_rgb(180, 180, 180))
    roof.draw(win)

    print("Distance between p1 and p2:", dist)
    print("p1 x:", p1.getX(), "\np1 y:", p1.getY(), "\np2 x:", p2.getX(),
          "\np2 y:", p2.getY())
    print("Base Height:", baseHeight, "\nBase Width:", baseWidth)
    win.getMouse()
    win.close()
Ejemplo n.º 31
0
def window():
    win = GraphWin("얘기 카운트", 1280, 720)
    win.setBackground(color_rgb(17, 22, 15))

    historyText = Text(Point(480, 360), '')
    historyText.setFill(color_rgb(255, 255, 255))
    historyText.setFace("arial")
    historyText.setSize(16)
    historyText.draw(win)

    rect = Rectangle(Point(960, 0), Point(1280, 720))
    rect.setFill(color_rgb(17, 22, 15))
    rect.draw(win)

    clockText = Text(Point(1117, 16), "")
    clockText.setFill(color_rgb(255, 255, 255))
    clockText.setFace("courier")
    clockText.setSize(16)
    clockText.draw(win)

    yaegiConstText = Text(Point(1117, 300), "%s 횟수" % toFilter)
    yaegiConstText.setFill(color_rgb(255, 255, 255))
    yaegiConstText.setFace("arial")
    yaegiConstText.setSize(36)
    yaegiConstText.draw(win)

    yaegiNumberText = Text(Point(1117, 420), "0")
    yaegiNumberText.setFill(color_rgb(255, 255, 255))
    yaegiNumberText.setFace("arial")
    yaegiNumberText.setSize(36)
    yaegiNumberText.draw(win)

    line = graphics.Line(Point(960, 0), Point(960, 720))
    line.setFill(color_rgb(200, 200, 200))
    line.draw(win)

    while not win.checkMouse():
        clockText.setText(
            "%s KST" %
            datetime.datetime(2020, 1, 1).now().isoformat().split('.')[0])
        yaegiNumberText.setText(str(yaegiCount))
        historyText.setText('\n'.join(history))

        sleep(1)

    win.close()

    running = False

    global f
    f.write('%s count: %d' % (toFilter, yaegiCount))
Ejemplo n.º 32
0
def main():
    # create GraphWin
    win = GraphWin("Three Button Monte", 800, 600)
    coordWidth = 10; coordHeight = 10
    factorWidth = win.width / coordWidth; factorHeight = win.height / coordHeight
    win.setCoords(0, 0, coordWidth, coordHeight)

    # place three buttons in window
    # doors = [Button(win, Point(2, 5), 2, 4, door1(), factorWidth, factorHeight),
    #          Button(win, Point(5, 5), 2, 4, door2(), factorWidth, factorHeight),
    #          Button(win, Point(8, 5), 2, 4, door3(), factorWidth, factorHeight)]
    doors = [Button(win, Point(2, 5), 2, 4, "Door 1"),
             Button(win, Point(5, 5), 2, 4, "Door 2"),
             Button(win, Point(8, 5), 2, 4, "Door 3")]
    for door in doors:
        door.setSize(36)
        door.activate()

    # place Quit button in window
    # quitButton = Button(win, Point(8.5, 1.5), 1, 1, "Quit", factorWidth, factorHeight)
    quitButton = Button(win, Point(8.5, 1.5), 1, 1, "Quit")
    quitButton.setSize(24)
    quitButton.activate()

    # place blank message text in window
    result = Text(Point(3.5, 1.5), '')
    result.setSize(18)
    result.draw(win)

    # get mouse click
    pt = win.getMouse()

    # event loop...until Quit clicked
    while not quitButton.clicked(pt):
        # randomly determine which door is correct
        secretDoor = randrange(0, 3)

        # take action for button clicked (1, 2, 3, or Quit)
        if doors[secretDoor].clicked(pt):
            result.setText('Congratulations, you are correct!')
        else:
            result.setText('Sorry, the correct door was door #{}'.format(secretDoor + 1))

        sleep(2)
        result.setText('')

        # get mouse click
        pt = win.getMouse()

    win.close()
Ejemplo n.º 33
0
def main():
    parser = argparse.ArgumentParser()
    parser.add_argument("--size", type=int, default=3, help="Size of k")
    args = parser.parse_args()

    win = GraphWin("My Circle", WIN_SIZE, WIN_SIZE)

    k = args.size
    m = k * (k - 1) + 1
    r = min(pi * R / m * 0.50, 20)

    ds = DiffState(k)
    ds.search()

    points = []
    for i in range(m):
        ang = 2 * pi * i / m
        center = (CENTER[0] + R * sin(ang), CENTER[1] - R * cos(ang))
        points.append(Point(center[0], center[1]))

    if m < 20:
        for i in range(m):
            for j in range(i, m):
                if not (i in ds.current and j in ds.current):
                    l = Line(points[i], points[j])
                    l.draw(win)
                    l.setOutline(all_color)

    for i in range(m):
        for j in range(i, m):
            if i in ds.current and j in ds.current:
                l = Line(points[i], points[j])
                l.setWidth(3)
                l.draw(win)
                l.setOutline(set_color)

    for i in range(m):
        c = Circle(points[i], r)
        c.setFill("red")
        c.draw(win)

    win.getMouse()
    win.close()
Ejemplo n.º 34
0
	def play(self, level=1):
		'''
		Starts a new game.
		
		level - Start a game at level <level>
		
		Game loop idea taken from
		http://www.koonsolo.com/news/dewitters-gameloop/
		'''
		self.setBackground(level)
		hero=Hero(self)
		life=Life(self,3,self.width)
		currentScore=CurrentScore(self,self.width)
		enemyClassList=enemyclasses.getAllEnemies(maxLevel=1)
		enemies=[random.choice(enemyClassList)(self)]
		
		while self.gameRunning:
			mouseClick = self.checkMouse()
			if mouseClick:
				if(enemies[0].kill(mouseClick)):
					currentScore.setSize(36)
				pass
				
			for enemy in enemies:
				enemy.walk()
			
			
			
			time.sleep(0.01)
			_root.update()
			
			del mouseClick
			if self.gameRunning and hero.isDead():
				self.gameOver()
		for enemy in enemies:
			del enemy
		del enemies
		del hero
		GraphWin.close(self)
Ejemplo n.º 35
0
                    rec.draw(win)
                    scores[player] += 1
                    score_text[player].undraw()
                    score_text[player].setText('{}:{}'.format(wins[player], scores[player]))
                    score_text[player].draw(win)
                else:
                    if is_vert:
                        line = Line(points[r][c], points[r+1][c])
                    else:
                        line = Line(points[r][c], points[r][c+1])
                    line.draw(win)
                    line.setFill(colors[player])

                printer(win, results_dir, f, i, j)
            (n1, s1), (n2, s2) = scores.items()
            if s1 > s2:
                winner = n1
            elif s2 > s1:
                winner = n2
            else:
                winner = None

            if winner:
                wins[winner] += 1
                score_text[winner].undraw()
                score_text[winner].setText('{}:{}'.format(wins[winner], scores[winner]))
                score_text[winner].draw(win)
            printer(win, results_dir, f, i, j+1)

            win.close()