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()
예제 #2
0
    def __init__(self, num_players: int, pairs: int):
        self.win = GraphWin('Matching Game', WIN_SIZE, WIN_SIZE)

        self.__reset_num_players = num_players
        self.__reset_pairs = pairs

        self.reset()
예제 #3
0
 def __init__(self, characters, script, delay=1, iterations=100):
     self.window = GraphWin()
     self.characters = characters
     self.script = script
     self.time = 0
     self.delay = delay
     self.iterations = iterations
예제 #4
0
    def __init__(self):
        self.win = GraphWin("Dice Poker", 600, 400)
        self.win.setBackground("green3")
        banner = Text(Point(300, 30), "Python Poker Parlor")
        banner.setSize(24)
        banner.setFill("yellow2")
        banner.setStyle('bold')
        banner.draw(self.win)

        self.msg = Text(Point(300, 380), "Welcome to the Dice Table")
        self.msg.setSize(18)
        self.msg.draw(self.win)
        self.createDice(Point(300, 100), 75)
        self.buttons = []
        self.addDiceButtons(Point(300, 170), 75, 30)
        b = Button(self.win, Point(300, 230), 400, 40, "Roll Dice")
        self.buttons.append(b)
        b = Button(self.win, Point(300, 280), 150, 40, "Score")
        self.buttons.append(b)
        b = Button(self.win, Point(570, 375), 40, 30, "Quit")
        self.buttons.append(b)
        b = Button(self.win, Point(50, 375), 40, 30, "rule")
        self.buttons.append(b)
        self.money = Text(Point(300, 325), "$100")
        self.money.setSize(18)
        self.money.draw(self.win)
        self.Max = 0
        self.MaxRecord = Text(Point(300, 350),
                              "currentMaxrecord:${}".format(self.Max))
        self.MaxRecord.setSize(18)
        self.MaxRecord.setTextColor("red")
        self.MaxRecord.draw(self.win)
예제 #5
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()
예제 #6
0
def ten_strings():
    """
    7. Write a function, ten_strings(), that allows the user to plot 10 strings
    of their choice at locations of a graphics window chosen by clicking on the
    mouse (the strings should be entered one-by-one by the user within a text
    entry box at the top of the graphics window, clicking the mouse after
    entering each one).
    """
    win = GraphWin("Ten strings", 400, 300)

    message = Text(Point(200, 15),
                   "Enter what you want then click where you want it")
    message.draw(win)

    input_box = Entry(Point(200, 50), 10)
    input_box.draw(win)

    for _ in range(10):
        position = win.getMouse()

        if input_box.getText() == "":
            new_message = Text(position, "[EMPTY MESSAGE]")

        else:
            new_message = Text(position, input_box.getText())

        new_message.draw(win)
        input_box.setText("")

    message.setText("You have used up all of your messages")

    await_user_input(win)
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()
예제 #8
0
def drawGamePanel():

    # Creates gray Game Panel window
    game_panel = GraphWin("Game Panel", 300, 300)
    game_panel.setBackground("gray")

    # Creates title text with background
    title_background = Rectangle(Point(0, 0), Point(300, 40))
    title_background.setFill("white")
    title_background.draw(game_panel)
    title_text = Text(Point(150, 20), "BoilerMazer")
    title_text.setSize(30)
    title_text.setStyle("bold")
    title_text.draw(game_panel)

    # Creates exit button and text
    exit_button = Rectangle(Point(250, 260), Point(300, 300))
    exit_button.setFill("red")
    exit_button.draw(game_panel)
    exit_text = Text(Point(275, 281), "EXIT")
    exit_text.setSize(14)
    exit_text.draw(game_panel)

    # Creates green button, which will be used for new player and start options
    green_button = Rectangle(Point(100, 260), Point(200, 300))
    green_button.setFill("green")
    green_button.draw(game_panel)
    return game_panel
예제 #9
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()
예제 #10
0
 def createWindow(self, N):
     """
     Create the graphics window.
     Arguments:
         self - the SkewerUI instance
         N - the capacity of the skewer
     """
     self.win = GraphWin("Shish Kebab", 800, 200)
     self.win.setCoords( \
         WIN_LOW_LEFT_X, \
         WIN_LOW_LEFT_Y - 0.1, \
         WIN_LOW_LEFT_X+(N+1)*FOOD_WIDTH, \
         WIN_UP_RIGHT_Y + 0.1 \
     )
     
     # draw skewer
     line = Line( \
         Point(WIN_LOW_LEFT_X, WIN_LOW_LEFT_Y+WIN_HEIGHT/2.0), \
         Point(N, WIN_LOW_LEFT_Y+WIN_HEIGHT/2.0) \
     )
     line.setWidth(LINE_THICKNESS)
     line.draw(self.win)
     handle = Circle( \
         Point(N-.1, WIN_LOW_LEFT_Y+WIN_HEIGHT/2.0), \
         SKEWER_HANDLE_RADIUS \
     )
     handle.setFill(BKGD_COLOR)
     handle.setWidth(LINE_THICKNESS)
     handle.draw(self.win)
     self.items = []
예제 #11
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()
예제 #12
0
 def run(self):
     while self.money >= 10 and self.interface.wantToPlay():
         self.playRound()
     scoreboard = Scoreboard()
     for score in scoreboard.top10:
         if self.money > int(score.score):
             win2 = GraphWin("Dice Poker", 600, 400)
             win2.setBackground("green3")
             banner = Text(Point(300, 30),
                           "New High Score!\nPlease enter your name:")
             banner.setSize(24)
             banner.setFill("yellow2")
             banner.setStyle("bold")
             banner.draw(win2)
             textbox = Entry(Point(300, 150), 30)
             textbox.draw(win2)
             enter_btn = Button(win2, Point(300, 200), 60, 30, "Enter")
             enter_btn.activate()
             p = win2.getMouse()
             playerName = str(textbox.getText())
             if enter_btn.clicked(p):
                 scoreboard.addScore(playerName, self.money)
                 scoreboard.sortScores()
                 scoreboard.saveScores()
                 break
     self.interface.close()
def draw_grid(size):
    squares = size - 1
    win = GraphWin("Graphical traced walk", 50 * size, 50 * size)
    win.setCoords(0, size, size, 0)

    border_rectangle = Rectangle(Point(0.5, 0.5), Point(size - 0.5, size - 0.5)).draw(win)
    border_rectangle.setFill("gray")
    border_rectangle.setWidth(2)

    centre_square = Rectangle(
        Point(size / 2 - 0.5, size / 2 - 0.5),
        Point(size / 2 + 0.5, size / 2 + 0.5),
    ).draw(win)
    centre_square.setFill("cyan")
    centre_square.setOutline("")

    person = Circle(Point(size / 2, size / 2), 0.25).draw(win)
    person.setFill("red")

    square_texts = [[""] * squares for _ in range(squares)]

    for i in range(squares):
        for j in range(squares):
            # grid lines
            Line(Point(1.5 + j, 0.5), Point(1.5 + j, size - 0.5)).draw(win)
            Line(Point(0.5, 1.5 + j), Point(size - 0.5, 1.5 + j)).draw(win)

            # text within each square
            square_text = Text(Point(1 + j, 1 + i), "").draw(win)
            square_texts[i][j] = square_text

    return win, person, square_texts
예제 #14
0
 def __init__(self):
     self.win = GraphWin("Dice Poker", 600, 400)
     self.win.setBackground("green3")
     banner = Text(Point(300, 30), "Python Poker Parlor")
     banner.setSize(24)
     banner.setFill("yellow2")
     banner.setStyle("bold")
     banner.draw(self.win)
     self.msg = Text(Point(300, 380), "Welcome to the Dice Table")
     self.msg.setSize(18)
     self.msg.draw(self.win)
     self.createDice(Point(300, 100), 75)
     self.buttons = []
     self.addDiceButtons(Point(300, 170), 75, 30)
     b = Button(self.win, Point(300, 230), 400, 40, "Roll Dice")
     self.buttons.append(b)
     b = Button(self.win, Point(300, 280), 150, 40, "Score")
     self.buttons.append(b)
     b = Button(self.win, Point(570, 375), 40, 30, "Quit")
     self.buttons.append(b)
     b = Button(self.win, Point(30, 375), 40, 30, "Help")
     self.buttons.append(b)
     self.money = Text(Point(300, 325), "$100")
     self.money.setSize(18)
     self.money.draw(self.win)
예제 #15
0
def draw_background(palette: GraphWin):
    _height = palette.getHeight()
    _width = palette.getWidth()

    sky_percentage = 0.7

    sky = get_rectangle(gr.Point(0, _height * sky_percentage), _width, _height * sky_percentage)
    land = get_rectangle(gr.Point(0, _height), _width, _height * (1 - sky_percentage))
    sun = gr.Circle(gr.Point(_width * 0.85, _height * 0.15), _height * 0.1)

    sky.setFill(gr.color_rgb(0, 0, 200))
    land.setFill(gr.color_rgb(80, 240, 20))
    sun.setFill(gr.color_rgb(255, 255, 0))

    sky.draw(palette)
    land.draw(palette)
    sun.draw(palette)

    sky_shift = _height * 0.15
    for i in range(5):
        cloud = gr.Circle(gr.Point(0 + sky_shift, _height * 0.15), _height * 0.05)
        cloud.setFill(gr.color_rgb(255, 255, 255))
        cloud.draw(palette)
        sky_shift += _height * 0.1 / 2
    sky_shift = _height * 0.175
    for i in range(4):
        cloud = gr.Circle(gr.Point(0 + sky_shift, _height * 0.10), _height * 0.05)
        cloud.setFill(gr.color_rgb(255, 255, 255))
        cloud.draw(palette)
        sky_shift += _height * 0.1 / 2
예제 #16
0
def draw_archery_target():
    """
    3. Write a function, draw_archery_target(), that draws a coloured target
    consisting of concentric circles of yellow (innermost), red and blue. The
    sizes of the circles should be in correct proportion i.e. the red circle
    should have a radius twice that of the yellow circle, and the blue circle
    should have a radius three times that of the yellow circle.

    Hint: objects drawn later will appear on top of objects drawn earlier.
    """
    win = GraphWin("Target")
    win.setCoords(0, 0, 1, 1)
    centre = Point(0.5, 0.5)

    yellow_circle = Circle(centre, 0.1)
    yellow_circle.setFill("yellow")

    red_circle = Circle(centre, yellow_circle.getRadius() * 2)
    red_circle.setFill("red")

    blue_circle = Circle(centre, yellow_circle.getRadius() * 3)
    blue_circle.setFill("blue")

    blue_circle.draw(win)
    red_circle.draw(win)
    yellow_circle.draw(win)

    await_user_input(win)
예제 #17
0
파일: gui.py 프로젝트: Spensaur-K/Logix
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()
예제 #18
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()
예제 #19
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()
예제 #20
0
def log(data, time, window: GraphWin):
    sum_speed = 0
    sum_satiety = 0
    sum_devide_satiety = 0
    sum_child_count = 0

    for c in data['cells']:
        sum_speed += c.speed
        sum_satiety += c.satiety
        sum_devide_satiety += c.devide_satiety
        sum_child_count += c.childCount

    # print("Количество: ", len(data['cells']))
    # print("Средняя скорость: ", str(sum_speed / len(data['cells'])))
    # print("Средняя сытость: ", str(sum_satiety / len(data['cells'])))
    # print("Средняя сытость для размножения: ", str(sum_devide_satiety / len(data['cells'])))
    # print("_________________")

    x = (time + 10) % window.width

    y1 = 165 - len(data['cells']) / 8
    y2 = 330 - (sum_speed / len(data['cells']) * 20)
    y3 = 495 - len(data['food']) / 4
    y4 = 660 - sum_child_count / len(data['cells']) * 5
    # y4 = 660 - sum_devide_satiety / len(data['cells'])

    window.create_rectangle(x, y1, x + 2, y1 + 2)
    window.create_rectangle(x, y2, x + 2, y2 + 2)
    window.create_rectangle(x, y3, x + 2, y3 + 2)
    window.create_rectangle(x, y4, x + 2, y4 + 2)
예제 #21
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()
예제 #22
0
def main():
    win = GraphWin ( "Click and Type", 400, 400)
    for i in range(10):
        pt = win.getMouse()
        key = win.getKey()
        label = Text (pt, key)
        label.draw(win)
예제 #23
0
    def getBounds(self,
                  window: graphics.GraphWin) -> Tuple[int, int, int, int]:
        """
        Calcula os cantos de uma bounding box ao redor do texto.

        Argumentos:
            window: necessária para desenhar o texto temporariamente

        Retorna:
            tupla contento as coordenadas dos cantos
            (1) acima, esquerdo e (2) abaixo, direito
            (x1, y1, x2, y2)
        """
        if self.id is not None:
            # O texto já está desenhado.
            # Só precisamos criar a bouding box ao redor dele.
            bounds = window.bbox(self.id)
        else:
            # O texto ainda não está desenhado.
            # Nós precisamos desenhá-lo temporariamente, para criar a bounding box.

            previous_tag = self.config.get('tag', None)
            self.config['tag'] = 'getting_width'
            self.draw(window)
            bounds = window.bbox(self.config['tag'])
            self.undraw()
            self.config['tag'] = previous_tag

        return bounds
예제 #24
0
 def __init__(self, name):
     self.win = GraphWin(name, 500,
                         500)  # give title and dimensions of window
     self.r = 200
     self._setup()
     self.current_gaps = []
     self.current_gaps_nodes = []
예제 #25
0
def draw_house(door_colour, lights_on, n, size):
    win = GraphWin("House", 100 * size, 100 * size)
    win.setCoords(0, 0, 1, 1)

    roof = Polygon(Point(0.01, 0.7), Point(0.22, 0.992), Point(0.78, 0.992),
                   Point(0.992, 0.7))
    roof.setFill("pink")
    roof.draw(win)

    # draw wall and door
    draw_rectangle(win, Point(0.008, 0.008), Point(0.992, 0.7), "brown")
    draw_rectangle(win, Point(0.15, 0.008), Point(0.4, 0.45), door_colour)

    # draw door number
    door_n = Text(Point(0.275, 0.35), n)
    door_n.setSize(4 + 2 * size)
    if door_colour == "black":
        door_n.setFill("white")
    door_n.draw(win)

    # draw window
    if lights_on:
        window_colour = "yellow"
    else:
        window_colour = "black"
    draw_rectangle(win, Point(0.55, 0.15), Point(0.85, 0.45), window_colour)
예제 #26
0
    def __init__(self, cols=None, rows=None, window=None, scale=None):
        super().__init__()
        if scale is not None:
            self.scale = scale
        else:
            self.scale = 0.036
        if window is not None:
            self.window = window
        else:
            windowWidth = self.scale * ((self.cols * characterDiameter) +
                                        ((self.cols + 1) * characterRadius))
            windowHeight = self.scale * ((self.rows * characterDiameter) +
                                         ((self.rows + 1) * characterRadius))
            self.window = GraphWin("Retrotextual",
                                   windowWidth,
                                   windowHeight,
                                   autoflush=False)
            self.window.setBackground("black")

        center = arr([characterDiameter, characterDiameter])
        for row in range(self.rows):
            for col in range(self.cols):
                self.characters.append(GraphicsCharacter(self, center))
                center[0] += characterDiameter + characterGap
            center[0] = characterDiameter
            center[1] = characterRadius * 5
예제 #27
0
def main():
    die_number = 0
    choice = True
    dice = []

    # Test the Window Display
    win = GraphWin("My Graphics Window", 1600, 600)
    win.setBackground('red')

    # Test the User Input for Number of Dice
    die_number = int(input('Enter number of dice to roll: '))
    my_dice = Dice_roller(die_number)

    # Get Dice Graphic for Number of Dice
    for i in range(die_number):
        die = dg.Dice(100)
        dice.append(die)

    # Test Rolling and Displaying Dice
    choice = int(input('Enter 1 to roll dice or 0 to quit: '))
    while choice == True:
        for j in range(5):
            offset = 0
            my_dice.roll_dice()
            for i in range(die_number):
                dice[i].draw_dice(win, Point(200 + offset, 200),
                                  int(my_dice.die[i]))
                offset = offset + 120
        choice = int(input('Enter 1 to roll again or 0 to quit: '))
예제 #28
0
def main():
    win = GraphWin("Tetrominoes", 200, 150)
    #block = Block(Point(1, 1), 'red')
    #block.draw(win)
    #shape = I_shape(Point(3, 1))
    shape = Shape([1, 2], 'red')
    shape.draw(win)
    win.mainloop()
예제 #29
0
def main():
    # create the application window
    win = GraphWin("Slye's Dyce", 1200, 800)
    win.setCoords(0, 0, 120, 80)

    type = gettype(win)
    playsummary(win, type)
    playgame(win, type)
예제 #30
0
def create_window():
    width = int(1920 * SCALING)
    height = int(1080 * SCALING)

    # Create game window
    win = GraphWin("Black Jack", width, height, autoflush=False)
    win.setBackground(colour_rgb(135, 206, 250))
    return win
예제 #31
0
def main():
    win = GraphWin("An Awesome Car", 700, 300)

    car = Car(Point(50, 50), 15, Point(100, 50), 15, 40)
    car.set_color('black', 'gray', 'pink')
    car.draw(win)

    win.mainloop()
예제 #32
0
파일: Windows.py 프로젝트: JacktonL/Physics
    def __init__(self):

        self.size = 400
        self.win1 = GraphWin("Window 1", self.size, self.size)
        self.win2 = GraphWin("Window 2", self.size, self.size)
        self.vx = randint(3, 7)
        self.vy = randint(3, 7)
        self.m = 15
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()
예제 #34
0
def main():
    win = GraphWin("map", 1000, 800)
    win.setCoords(-88.357, 41.786, -88.355, 41.788)

    with open("2016-08-04_20-20-41.000.txt", "r") as log:
        lines = log.readlines()
        for n in range(0, len(lines) - 1, 3):
            line = lines[n].split(", ")
            if len(line) == 6:
                p = Point(float(line[2]), float(line[1]))
                p.setFill('red')
                Line(p, vect(p, radians(-(float(line[3]) + 270)))).draw(win)
                p.draw(win)

            else:
                Text(Point(float(lines[n+1].split(", ")[2]) + .00005, float(lines[n+1].split(", ")[1]) + .00005), line[0]).draw(win)
                print(line)
예제 #35
0
파일: gui.py 프로젝트: Spensaur-K/Logix
	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)
예제 #36
0
파일: diff_graph.py 프로젝트: mckoss/labs
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()
예제 #37
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)
예제 #38
0
class SkewerUI(object):
    """
    Class: SkewerUI
    Description: A graphical display for the Skewer. It displays
        the items in on the skewer graphically, as they are added,
        removed and shifted around by the various commands.
    """

    __slots__ = ( 
        'win',          # the graphical window
        'items'         # the list of food items (strings) from top to bottom
    )

    def __init__( self, N ):
        """
        Create the SkewerUI.
        Arguments:
            self - the SkewerUI being created
            N - the capacity of the skewer (for the window size)
        """
        
        # create the window
        self.createWindow( N ) # (Sets value of win attribute.)
        self.items = []
    
    def close(self):
        """
        On destruction, close the graphical window.
        Arguments:
          self - the SkewerUI being created
        """
        
        self.win.close()
    
    def createWindow(self, N):
        """
        Create the graphics window.
        Arguments:
            self - the SkewerUI instance
            N - the capacity of the skewer
        """
        self.win = GraphWin("Shish Kebab", 800, 200)
        self.win.setCoords( \
            WIN_LOW_LEFT_X, \
            WIN_LOW_LEFT_Y - 0.1, \
            WIN_LOW_LEFT_X+(N+1)*FOOD_WIDTH, \
            WIN_UP_RIGHT_Y + 0.1 \
        )
        
        # draw skewer
        line = Line( \
            Point(WIN_LOW_LEFT_X, WIN_LOW_LEFT_Y+WIN_HEIGHT/2.0), \
            Point(N, WIN_LOW_LEFT_Y+WIN_HEIGHT/2.0) \
        )
        line.setWidth(LINE_THICKNESS)
        line.draw(self.win)
        handle = Circle( \
            Point(N-.1, WIN_LOW_LEFT_Y+WIN_HEIGHT/2.0), \
            SKEWER_HANDLE_RADIUS \
        )
        handle.setFill(BKGD_COLOR)
        handle.setWidth(LINE_THICKNESS)
        handle.draw(self.win)
        self.items = []



    class _ShapeInfo():
        __slots__ = [ 'shapeClass', 'ctorArgs' ]
        def __init__( self, shapeClass, ctorArgs ):
            self.shapeClass = shapeClass
            self.ctorArgs = ctorArgs

    Shapes = { \
              True: _ShapeInfo( Circle, ( Point( 0, .5 ), .5 ) ), \
              False: _ShapeInfo( Rectangle, ( Point( -.5, 0 ), Point( .5, 1 ) ) ) \
    } # The bool is for vegetarian

    def add( self, food ):
        """
        Called whenever an item is added to the Skewer, so the graphics
        can be updated.  It uses the KSpot class to get the food items
        and display them.
        Arguments:
            self - the SkewerUI instance
            food - the new food added to the skewer (KSpot)
        """    
        if food != None:
            shapeInfo = SkewerUI.Shapes[ food.item.veggie ]
            graphic = (shapeInfo.shapeClass)( *shapeInfo.ctorArgs )
            graphic.setFill(Colors[food.item.name])
            graphic.draw( self.win )
            for prev in self.items:
                prev.move( 1, 0 )
            self.items.insert( 0, graphic )
            

    def remove( self ):
        """
        Called whenever an item is removed to the Skewer, so the graphics
        can be updated.  It uses the KSpot class to get the food items
        and display them.
        Arguments:
            self - the SkewerUI instance
            head - the head of the skewer (KSpot)
        """
        
        if len( self.items ) != 0:
            self.items[ 0 ].undraw()
            self.items.pop( 0 )
            for prev in self.items:
                prev.move( -1, 0 )
예제 #39
0
if __name__ == "__main__":
    results_dir = 'results'
    for f in (f for f in os.listdir(results_dir) if f.endswith('.log')):
        hist = json.load(open(os.path.join(results_dir, f)))
        colors = None
        for i, game in enumerate(hist):
            score = [0, 0]
            images = []
            names = game['players']
            size = int(game['size'])

            dim = 600
            left_marg = 50
            top_marg = 200
            win = GraphWin(game, dim + 2*left_marg, dim + top_marg + 50)
            win.setBackground(color_rgb(255, 255, 255))

            if not colors:
                colors = {names[0]: 'blue', names[1]: 'red'}
                p1 = Text(Point(left_marg + dim//2, 30), names[0])
                p1.setFill(colors[names[0]])
                p1.setSize(20)
                score1 = Text(Point(left_marg + dim//6, 70), '0:0')
                score1.setFill(colors[names[0]])
                score1.setSize(30)

                vs = Text(Point(left_marg + dim//2, 70), 'vs')
                vs.setFill('black')
                vs.setSize(20)
예제 #40
0
def setup_graphics_window(winname, glength, gwidth, slength, swidth):
        win = GraphWin(winname, glength, gwidth)
        win.setCoords(0, 0, slength, swidth)
        return win
예제 #41
0
    def pulsado(self, p):
        if p.getX() in range(self.xmin, self.xmax) and p.getY() in range(self.ymin, self.ymax):
            return True
        else:
            return False
    def activar(self):
        self.etiqueta.setTextColor('#000')
        self.estado = True
        
    def desactivar(self):
        self.etiqueta.setTextColor('#666')
        self.estado = False
        
        
        
    
w = GraphWin('Mi boton', 600, 400)
b1 = Boton(w, Point(300, 200), 80, 40, 'Okey')
b2 = Boton(w, Point(300, 250), 80, 40, 'Activar')

while True:
    p = w.getMouse()
    if b1.pulsado(p):
        b1.color('blue')
    if b2.pulsado(p):
        if b2.estado:
            b2.desactivar()
        else:
            b2.activar()
        
w.getMouse()