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()
示例#2
0
class Dice:
    def __init__(self, xloc, num=random.randint(1, 6), willDiscard=False):
        self.num = num
        self.willDiscard = willDiscard
        self.xloc = xloc
        self.img = Rectangle(Point(20 + 50 * self.xloc, 100),
                             Point(20 + 50 * (self.xloc + 1), 50))
        self.text = Text(Point(45 + 50 * self.xloc, 75), self.num).draw(win)

    def reroll(self):
        self.num = random.randint(1, 6)

    def swapDiscard(self):
        print(self.willDiscard)
        if (self.willDiscard):
            self.willDiscard = False
        else:
            self.willDiscard = True
        self.drawSelf()

    def drawSelf(self):
        self.img.undraw()
        self.text.undraw()
        if (self.willDiscard):
            self.img.setFill("red")
        else:
            self.img.setFill("white")
        self.img.draw(win)
        self.text.draw(win)
示例#3
0
class Button(object):
	def __init__(self, win, center, width, height, label):
		w, h = width/2, height/2
		x, y = center.getX(), center.getY()
		self.xmax, self.xmin = x+w, x-w
		self.ymax, self.ymin = y+h, y-h
		p1 = Point(self.xmin, self.ymin)
		p2 = Point(self.xmax, self.ymax)
		self.rect = Rectangle(p1, p2)
		self.rect.setFill('lightgray')
		self.rect.draw(win)
		self.label = Text(center, label)
		self.label.draw(win)
		self.deactivate()

	def clicked(self, p):
		return self.active and self.xmin <= p.getX() and self.xmax >= p.getX() and self.ymin <= p.getY() and self.ymax >= p.getY()

	def getLabel(self):
		return self.label.getText()

	def activate(self):
		self.label.setFill('black')
		self.rect.setWidth(2)
		self.active = True

	def deactivate(self):
		self.label.setFill('darkgrey')
		self.rect.setWidth(1)
		self.active = False
示例#4
0
class Tile:
    def __init__(self, xPos, yPos, type):
        self.xPos = xPos
        self.yPos = yPos
        self.type = type
        self.img = Rectangle(Point((20 * xPos), (20 * yPos)),
                             Point((20 * xPos + 20), (20 * yPos + 20)))
        self.img.setFill(colors[self.type])
        self.img.draw(win)

    def cycleType(self):
        if (self.type >= 6):
            self.type -= 7
        self.type += 1
        self.img.setFill(colors[self.type])

    def replaceRegWithDiff(self):
        if (self.type == 1):
            self.type = 2
            self.img.setFill(colors[self.type])

    def replaceRegWithWater(self):
        if (self.type == 1):
            self.type = 5
            self.img.setFill(colors[self.type])
示例#5
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()
示例#6
0
    def __init__(self, win, center, size):
        self.win = win
        self.background = 'white'
        self.foreground = 'black'

        self.pip_size = 0.1 * size
        half_size = size / 2.0
        offset = 0.6 * half_size

        #create square die face
        x, y = center.getX(), center.getY()
        point1 = Point(x - half_size, y - half_size)
        point2 = Point(x + half_size, y + half_size)
        rect = Rectangle(point1, point2)
        rect.setFill(self.background)
        rect.draw(win)

        #create 7 possible pip designs
        self.pip1 = self.__makePip(x - offset, y - offset)
        self.pip2 = self.__makePip(x - offset, y)
        self.pip3 = self.__makePip(x - offset, y + offset)
        self.pip4 = self.__makePip(x, y)
        self.pip5 = self.__makePip(x + offset, y - offset)
        self.pip6 = self.__makePip(x + offset, y)
        self.pip7 = self.__makePip(x + offset, y + offset)

        self.drawValue(1)
示例#7
0
class Boton(object):
    def __init__(self, v, centro, ancho, alto, etiqueta):
        #calculo de la posicion
        x, y = centro.getX(), centro.getY()
        w, h = ancho /2, alto /2
        self.xmax, self.xmin = x+w, x-w
        self.ymax, self.ymin = y+h, y-h
        p1 = Point(self.xmin, self.ymin)
        p2 = Point(self.xmax, self.ymax)
        #creacion del boton y etiqueta
        self.boton = Rectangle(p1, p2)
        self.boton.draw(v)
        self.boton.setFill('#CCC')
        self.etiqueta = Text(centro, etiqueta)
        self.etiqueta.setTextColor('#666')
        self.etiqueta.draw(v)
        self.desactivar()
    def color(self, c):
        self.boton.setFill(c)
    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
示例#8
0
    def draw_game_over(self):
        width = 300
        height = 50

        winners = self.__state.highest_score_players()

        tx = self.win.width / 2 - width / 2
        ty = self.win.height / 2 - height / 2
        rect = Rectangle(Point(tx, ty), Point(tx + width, ty + height))
        rect.setFill("grey")
        rect.draw(self.win)

        if len(winners) == 1:
            text_str = 'Player {} wins, press q to exit'.format(winners[0])
        else:
            text_str = 'Players {} win, press q to exit'.format(', '.join(
                str(w) for w in winners))
        text = Text(Point(tx + width / 2, ty + 20), text_str)
        text.setTextColor("black")
        text.draw(self.win)

        key = self.wait_key()
        if key == 'q':
            text.setText('exiting...')
            time.sleep(1)
            self.win.close()
        else:
            self.reset()
            self.loop()
示例#9
0
class Button:
    def __init__(self, win, center, width, height, label):
        w, h = width / 2.0, height / 2.0
        x, y = center.getX(), center.getY()
        self.xmax, self.xmin = x + w, x - w
        self.ymax, self.ymin = y + h, y - h
        p1 = Point(self.xmin, self.ymin)
        p2 = Point(self.xmax, self.ymax)
        self.rect = Rectangle(p1, p2)
        self.rect.setFill("lightgray")
        self.rect.draw(win)
        self.label = Text(center, label)
        self.label.draw(win)
        self.deactivate()

    def clicked(self, p):
        return (self.active and self.xmin <= p.getX() <= self.xmax
                and self.ymin <= p.getY() <= self.ymax)

    def getLabel(self):
        return self.label.getText()

    def activate(self):
        self.label.setFill("black")
        self.rect.setWidth(2)
        self.active = True

    def deactivate(self):
        self.label.setFill("darkgray")
        self.rect.setWidth(1)
        self.active = False

    def undraw(self):
        self.rect.undraw()
        self.label.undraw()
示例#10
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())
示例#11
0
class Square:

    def __init__(self, x, y, size):
        self.col = x        #Igual no hace falta
        self.row = y        #Igual no hace falta
        self.size = size    #Igual no hace falta

        self.wall = False
        self.square = Rectangle(Point(x*size,y*size+50), Point(x*size+size, y*size+size+50))

    def toggle(self):
        self.wall = not self.wall

    def setWall(self, wall):
        self.wall = wall

    def draw(self, win):
        if(self.wall):
            self.square.setFill(color_rgb(55, 55, 55))
        else:
            self.square.setFill(color_rgb(230,230,230))
        self.square.undraw()
        self.square.draw(win)

    def pintar(self):
        print("x: " + str(self.col) + " y: "+ str(self.row))

    def isWall(self):
        return self.wall
示例#12
0
class Button:
    def __init__(self, win, center, width, height, label='Button'):
        """
        Creates a rectangular button.

        Example usage:
        ==============
        centerPoint = Point(x, y)
        button = Button(win, centerPoint, width, height, 'Click Me!')
        """

        # Get most extreme vertices of button
        half_width = width / 2.0
        half_height = height / 2.0
        x, y = center.getX(), center.getY()
        self.x_min, self.y_min = x - half_width, y - half_height
        self.x_max, self.y_max = x + half_width, y + half_height

        # Create button outline
        point1 = Point(self.x_min, self.y_min)
        point2 = Point(self.x_max, self.y_max)
        self.rect = Rectangle(point1, point2)
        self.rect.setFill('lightgrey')
        self.rect.draw(win)

        # Create button text
        self.label = Text(center, label)
        self.label.draw(win)
        self.deactivate()

    def activate(self):
        """
        Sets this button to "active".
        """
        self.label.setFill('black')
        self.rect.setWidth(2)
        self.active = True

    def deactivate(self):
        """
        Sets this button to "inactive".
        """
        self.label.setFill('darkgrey')
        self.rect.setWidth(1)
        self.active = False

    def clicked(self, point):
        """
        Tests to see if the point clicked resides within the button's
        rectangle, and if the button is active.
        """
        if self.active:
            if (self.x_min <= point.getX() and self.y_min <= point.getY()
                    and self.x_max >= point.getX()
                    and self.y_max >= point.getY()):
                return True
        return False

    def getLabel(self):
        return self.label.getText()
示例#13
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 ()
示例#14
0
class Car():
    WHEEL_TO_TIRE_RATIO = 0.6

    def __init__(self, back_wheel_center, back_tire_radius, front_wheel_center,
                 front_tire_radius, body_height):
        upper_left_point = Point(back_wheel_center.x,
                                 back_wheel_center.y - body_height)
        bottom_right_point = front_wheel_center
        self.body = Rectangle(upper_left_point, bottom_right_point)

        self.back_wheel = Wheel(back_wheel_center,
                                back_tire_radius * Car.WHEEL_TO_TIRE_RATIO,
                                back_tire_radius)
        self.front_wheel = Wheel(front_wheel_center,
                                 front_tire_radius * Car.WHEEL_TO_TIRE_RATIO,
                                 front_tire_radius)

    def set_color(self, tire_color, wheel_color, body_color):
        self.body.setFill(body_color)

        self.back_wheel.set_color(wheel_color, tire_color)
        self.front_wheel.set_color(wheel_color, tire_color)

    def draw(self, win):
        self.body.draw(win)
        self.back_wheel.draw(win)
        self.front_wheel.draw(win)

    def animate(self, win, dx, dy, n):
        pass
示例#15
0
def draw_hold_button():
    # hold button points
    hold_a = Point(WIN.getWidth() * 2 / 11 - 100, WIN.getHeight() * 3 / 12)
    hold_b = Point(hold_a.getX() + 200, hold_a.getY() + 100)

    hold_button = Rectangle(hold_a, hold_b)

    hold_button.setFill("green")
    hold_button.setOutline("black")
    hold_button.setWidth(5)

    # Obtains the center point of the hold button
    center_hold_button = Point(0.5 * (hold_a.getX() + hold_b.getX()),
                               0.5 * (hold_a.getY() + hold_b.getY()))

    # Text class
    hold_text = Text(center_hold_button, "Hold")

    # Style the text
    hold_text.setFace("helvetica")
    hold_text.setSize(26)
    hold_text.setStyle("bold")
    hold_text.setTextColor("black")

    hold_button.draw(WIN)
    hold_text.draw(WIN)

    return hold_a, hold_b
示例#16
0
    def __init__(self, win, center, size):
        # Define some standard values
        self.win = win
        self.background = "white"
        self.foreground = "black"
        self.psize = 0.1 * size
        hsize = size / 2.0
        offset = 0.6 * hsize

        # Create a square for the face
        cx, cy = center.getX(), center.getY()
        p1 = Point(cx - hsize, cy - hsize)
        p2 = Point(cx + hsize, cy + hsize)
        rect = Rectangle(p1, p2)
        rect.draw(self.win)
        rect.setFill(self.background)

        # Create 7 circles for standard pip locations
        self.pips = [self.__makePip(cx - offset, cy - offset),
                     self.__makePip(cx - offset, cy),
                     self.__makePip(cx - offset, cy + offset),
                     self.__makePip(cx, cy),
                     self.__makePip(cx + offset, cy - offset),
                     self.__makePip(cx + offset, cy),
                     self.__makePip(cx + offset, cy + offset)]

        # Create a table for which pips are on for each value
        self.onTable = [[], [3], [2, 4], [2, 3, 4], [0, 2, 4, 6], [0, 2, 3, 4, 6], [0, 1, 2, 4, 5, 6]]

        # Draw an initial value
        self.setValue(1)
示例#17
0
def drawScoreDisplay(game_panel):

    # Draws box that serves as the background the score displays
    score_box = Rectangle(Point(50, 155), Point(250, 240))
    score_box.setFill("white")
    score_box.draw(game_panel)

    # Call readScores() function, and store top 4 scores from topscores.txt
    top_scores = readScores()
    # Print title for top scores table
    scores = ["TOP SCORES", "=========="]
    # For each of the top scores, create a string with the name and score
    for element in top_scores:
        # Convert tuple to list
        element = list(element)
        # Loop through name and score for each player
        for item in element:
            # Assign name to name
            if type(item) == str:
                name = item
            # Convert score to int and assign to score
            elif type(item) == int:
                score = str(item)
        # Create a string from the name and score with space between elements
        string = name + "      " + str(score)
        # Add player to scores list
        scores.append(string)
    # Create a text object of the top scores title and players and draw in game
    #  panel
    score_text = Text(Point(150, 198), "\n".join(scores[:6]))
    score_text.draw(game_panel)
    # Return objects
    return (score_box, score_text, scores)
示例#18
0
class Tile:

    ACTIVE_COLOR = "green"

    def __init__(self, bl, tr, color):
        self.bl = bl
        self.tr = tr
        self.rectangle = Rectangle(Point(self.bl[0], self.bl[1]),
                                   Point(self.tr[0], self.tr[1]))
        self.piece_image = None
        self.piece_obj = None
        self.state = {"active": False, "original_fill": color}

    def location(self):
        return self.bl

    def getX(self):
        return self.bl[0]

    def getY(self):
        return self.bl[1]

    def get_moves(self, location):
        if self.piece_obj:
            return self.piece_obj.get_moves(location)
        return []

    def set_piece(self, piece_image, piece_name):
        self.piece_image = piece_image
        self.piece_obj = PIECE_MAPPINGS[piece_name]()
        return self

    def still_active(self):
        return self.state["active"]

    def has_piece(self):
        return self.piece_image != None

    def onclick(self, window):
        """Handles highlighting tiles with pieces."""
        if self.piece_image:
            self.rectangle.undraw()
            active = self.state["active"]
            color = Tile.ACTIVE_COLOR if not active else self.state[
                "original_fill"]
            self.rectangle.setFill(color)
            self.rectangle.draw(window)
            self.piece_image.undraw()
            self.piece_image.draw(window)
            self.state["active"] = not active

    def highlight(self, window):
        if self.rectangle:
            self.rectangle.undraw()
            active = self.state["active"]
            color = Tile.ACTIVE_COLOR if not active else self.state[
                "original_fill"]
            self.rectangle.setFill(color)
            self.rectangle.draw(window)
            self.state["active"] = not active
示例#19
0
 def draw_cell(self, x, y, state):
     (gx, gy) = self.cell_coord(x, y)
     inset = 1
     box = Rectangle(
         Point(gx + inset, gy + inset),
         Point(gx + self.cell_width - inset, gy + self.cell_height - inset))
     box.setFill(self.bgcolour if state == 0 else self.cellcolour)
     box.draw(self.win)
def draw_rectangle(win, colour, point1, point2, current_tile, fill=False):
    """Helper function for drawing rectangles."""
    current_rectangle = Rectangle(Point(*point1), Point(*point2))
    if fill:
        current_rectangle.setFill(colour)
    current_rectangle.setOutline(colour)
    current_rectangle.draw(win)
    current_tile.append(current_rectangle)
示例#21
0
 def _draw_rect(self, x, y, color):
     pos_x = x * self.cell_width
     pos_y = y * self.cell_height
     rect = Rectangle(
         Point(pos_x, pos_y),
         Point(pos_x + self.cell_width, pos_y + self.cell_height))
     rect.setFill(color)
     rect.draw(self.window)
     return rect
示例#22
0
 def partial(i, j, color):
     print(n, size, i, j, color)
     one = Point(i * size, j * size)
     two = Point(size * (i + 1), size * (j + 1))
     rect = Rectangle(one, two)
     rect.setFill(color)
     rect.setOutline(color)
     rect.draw(win)
     return rect
示例#23
0
 def __init__(self, *objects):
     self.root = tk.Tk()
     ##        self.window = GraphWin('quad', self.root.winfo.screenwidth()/2, self.root.winfo.screenheight/2)
     self.window = GraphWin('quad', 1920, 1080)
     for obj in objects:
         rect = Rectangle(
             (obj['x'] + obj['width'] / 2, obj['y'] + obj['height'] / 2),
             obj['width'], obj['height'])
         rect.setFill('black')
         rect.draw(self.window)
示例#24
0
def drawResetButton(game_panel):
    # Creates yellow reset button to create new game with same player
    reset_button = Rectangle(Point(0, 260), Point(50, 300))
    reset_button.setFill("yellow")
    reset_button.draw(game_panel)
    reset_text = Text(Point(25, 281), "RESET")
    reset_text.setSize(14)
    reset_text.draw(game_panel)
    # Return objects
    return reset_button, reset_text
示例#25
0
class Rectangulo_centro(object):#clase para crear rectangulos centrados
    def __init__(self, ventana):
        ancho = ventana.width / 2
        alto = ventana.height / 2
        p1 = Point(ancho - 20, alto - 10)
        p2 = Point(ancho + 20, alto + 10)
        self.r = Rectangle(p1, p2)
        self.r.draw(ventana)
    def color(self, c):
        self.r.setFill(c)
示例#26
0
def draw_rec(board_column, board_row, color, dot_size):
    rtl = (board_column * (size * 2)) + offsetC
    rtr = (board_row * (size * 2)) + offsetR
    rbl = (board_column * (size * 2) + offsetC + (dot_size * 2))
    rbr = (board_row * (size * 2) + offsetR + (dot_size * 2))

    head = Rectangle(Point(rtl, rtr), Point(rbl, rbr))

    head.setFill(color)
    head.setOutline(color)
    head.draw(win)
示例#27
0
文件: main.py 项目: ryanwhite04/tiles
class Tile:

    # TODO make it just accept x, y coords and callback
    def __init__(self, dimensions, size, i, j):

        x = dimensions['x']
        y = dimensions['y']
        width = dimensions['width']
        height = dimensions['height']

        # In future might make across able to be different to down
        across = down = size
        self.area = Rectangle(Point(x + width * i, y + height * j),
                              Point(x + width * (i + 1), y + height * (j + 1)))
        self.text = Text(
            Point(x + width * (i + 1 / 2), y + height * (j + 1 / 2)), '')
        self.value = 0
        self.assign(i, j, across, down)

    def draw(self, win):
        self.area.draw(win)
        self.text.draw(win)
        return self

    def clear(self):
        self.area.undraw()
        self.text.undraw()
        return self

    def update(self, number):
        self.value = number
        if number > 0:
            self.text.setText(str(number))
        else:
            self.text.setText('')
        return self

    def double(self):
        self.update(2 * self.value)
        return self

    # Given the coordinates in the grid, assign direction for a move to perform
    # This could be simpler, TODO
    def assign(self, i, j, across, down):
        if (i == 0 and j != 0 and j != (down - 1)):
            self.direction = 'left'
        elif (i == (across - 1) and j != 0 and j != (down - 1)):
            self.direction = 'right'
        elif (j == 0 and i != 0 and i != (across - 1)):
            self.direction = 'up'
        elif (j == (down - 1) and i != 0 and i != (across - 1)):
            self.direction = 'down'
        else:
            self.direction = False
示例#28
0
    def _initialize(self):
        self.cells = self.blank_field(0)
        self.recs = self.blank_field(None)

        for x, y in self.allpos():
            rec = \
                Rectangle(
                    Point(x * self.cell_size, y * self.cell_size),
                    Point((x + 1) * self.cell_size, (y + 1) * self.cell_size))
            rec.setFill('white')
            rec.draw(self.window)
            self.recs[y][x] = rec
示例#29
0
def displaygraphicalgrid(win, grid, scale):
    for i in range(0, len(grid)):
        for j in range(0, len(grid[i])):
            Rect = Rectangle(Point(i * scale, j * scale),
                             Point((i + 1) * scale - 1, (j + 1) * scale - 1))
            if grid[i][j].solid:
                Rect.setFill("white")
                Rect.setOutline("white")
            else:
                Rect.setFill("black")
                Rect.setOutline("black")
            Rect.draw(win)
def button(ll_point, ur_point, text, color="white"):
    but = Rectangle(Point(ll_point[0], ll_point[1]),
                    Point(ur_point[0],
                          ur_point[1]))  # points are ordered ll, ur
    but.setFill(color)

    text = Text(
        Point((ll_point[0] + ur_point[0]) // 2,
              (ll_point[1] + ur_point[1]) // 2), text)
    but.draw(win)
    text.draw(win)

    return but, text
示例#31
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()
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))
示例#33
0
def main():
    win = graphics.GraphWin()
    shape = Rectangle(Point(75,75),Point(125,125))
    shape.setOutline('Red')
    shape.setFill('Red')
    shape.draw(win)
 
    for i in range(10):
        p = win.getMouse()
        tx = p.getX()-25
        ty = p.getY()-25
        bx = p.getX()+25
        by = p.getY()+25
 
        Rectangle(Point(tx,ty),Point(bx,by)).draw(win)
 
    Text(Point(100,180),'Click again to quit!').draw(win)
    win.getMouse()
    win.close()
示例#34
0
def main():
 
    win = graphics.GraphWin('Investment Grow Chart',320,240)
    win.setBackground('White')
    win.setCoords(-1.75,-9000,11.5,15400)
     
    Text(Point(4.87,13500),'Future Value Calculator').draw(win)
         
    Text(Point(4.5,-2000),'Input first principal:').draw(win)
    inputP = Entry(Point(9,-2000),6)
    inputP.setText('0')
    inputP.draw(win)
     
    Text(Point(3,-4000),' Input interest rate in decimal:').draw(win)
    inputR = Entry(Point(9,-4000),6)
    inputR.setText('0.0')
    inputR.draw(win)
     
     
    button = Rectangle(Point(2,-6000),Point(8,-8500))
    button.setFill('Green')
    button.draw(win)
    buttontext = Text(Point(5,-7250),'Show Result!:')
    buttontext.draw(win)
    win.getMouse()
     
    p = eval(inputP.getText())
    r = eval(inputR.getText())   
     
     
    Text(Point(-1,0),'0 K').draw(win)
    Text(Point(-1,2500),'2.5K').draw(win)
    Text(Point(-1,5000),'5 K').draw(win)
    Text(Point(-1,7500),'7.5K').draw(win)
    Text(Point(-1,10000),'10 K').draw(win)
     
    bar = Rectangle(Point(0,0),Point(1,p))
    bar.setFill('green')
    bar.setWidth(2)
    bar.draw(win)
     
    for i in range(1,11):
        p = p*(1+r)
        bar= Rectangle(Point(i,0),Point(i+1,p))
        bar.setFill('Green')
        bar.setWidth(2)
        bar.draw(win) 
     
    buttontext.setText('Quit.')
     
    win.getMouse()
    win.close()
示例#35
0
            dots = [[Circle(p, 5) for p in l] for l in points]
            for l in dots:
                for c in l:
                    c.setFill('black')
                    c.draw(win)

            printer(win, results_dir, f, i, 0)
            for j, (player, entry) in enumerate(game['history'], start=1):
                # Box finished
                is_vert, r, c = entry
                r = int(r)
                c = int(c)
                if is_vert == '':
                    rec = Rectangle(points[r][c], points[r+1][c+1])
                    rec.setFill(colors[player])
                    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:
示例#36
0
class Dado(object):
    def __init__(self, v, centro, ancho, alto):
        x, y = centro.getX(), centro.getY()
        w, h = ancho /2, alto /2
        self.ventana = v
        self.xmax, self.xmin = x+w, x-w
        self.ymax, self.ymin = y+h, y-h
        p1 = Point(self.xmin, self.ymin)
        p2 = Point(self.xmax, self.ymax)
        self.dado = Rectangle(p1, p2)
        self.dado.draw(v)
        self.dado.setFill('#FF0000')
        '''pintamos los circulos del dado con las posiciones reescalables de los puntos
    
            pos1            pos5
            pos2    pos4    pos6
            pos3            pos7
            
        '''
        self.pos1 = Point(self.xmin + w /2, self.ymin + h /2)
        self.pos2 = Point(self.xmin + w / 2, self.ymin + h)
        self.pos3 = Point(self.xmin + w / 2, self.ymin + h * 1.5)
        self.pos4 = Point(self.xmin + w, self.ymin + h)
        self.pos5 = Point(self.xmin + w * 1.5, self.ymin + h /2)
        self.pos6 = Point(self.xmin + w * 1.5, self.ymin + h)
        self.pos7 = Point(self.xmin + w * 1.5, self.ymin + h * 1.5)
        
        self.c1 = Circle(self.pos1, 4)
        self.c1.setOutline('#fff')
        self.c1.setFill('#fff')
        self.c1.draw(self.ventana)
            
        self.c2 = Circle(self.pos2, 4)
        self.c2.setOutline('#fff')
        self.c2.setFill('#fff')
        self.c2.draw(self.ventana)
            
        self.c3 = Circle(self.pos3, 4)
        self.c3.setOutline('#fff')
        self.c3.setFill('#fff')
        self.c3.draw(self.ventana) 
            
        self.c4 = Circle(self.pos4, 4)
        self.c4.setOutline('#fff')
        self.c4.setFill('#fff')
        self.c4.draw(self.ventana)
            
        self.c5 = Circle(self.pos5, 4)
        self.c5.setOutline('#fff')
        self.c5.setFill('#fff')
        self.c5.draw(self.ventana)
            
        self.c6 = Circle(self.pos6, 4)
        self.c6.setOutline('#fff')
        self.c6.setFill('#fff')
        self.c6.draw(self.ventana)
            
        self.c7 = Circle(self.pos7, 4)
        self.c7.setOutline('#fff')
        self.c7.setFill('#fff')
        self.c7.draw(self.ventana)
        
        self.limpiar()
        
    def colorDado(self, c):#personalizar el dado
        self.dado.setFill(c)
        
    def colorPunto(self, c):#personalizar los puntos del dado
        self.c1.setOutline(c)
        self.c1.setFill(c)
        self.c2.setOutline(c)
        self.c2.setFill(c)
        self.c3.setOutline(c)
        self.c3.setFill(c)
        self.c4.setOutline(c)
        self.c4.setFill(c)
        self.c5.setOutline(c)
        self.c5.setFill(c)
        self.c6.setOutline(c)
        self.c6.setFill(c)
        self.c7.setOutline(c)
        self.c7.setFill(c)
        
    def pulsado(self, p):#funcion para saber si se ha pulsado
        if p.getX() in range(self.xmin, self.xmax) and p.getY() in range(self.ymin, self.ymax):
            return True
        else:
            return False
        
    def ponValor(self, valor=1):#funcion para establecer la cara visible del dado
        self.limpiar()
        if valor == 1:
            self.c4.draw(self.ventana)
        elif valor == 2:
            self.c1.draw(self.ventana)
            self.c7.draw(self.ventana)
        elif valor == 3:
            self.c1.draw(self.ventana)
            self.c4.draw(self.ventana)
            self.c7.draw(self.ventana)
        elif valor == 4:
            self.c1.draw(self.ventana)
            self.c3.draw(self.ventana)
            self.c5.draw(self.ventana)
            self.c7.draw(self.ventana)
        elif valor == 5:
            self.c1.draw(self.ventana)
            self.c3.draw(self.ventana)
            self.c4.draw(self.ventana)
            self.c5.draw(self.ventana)
            self.c7.draw(self.ventana)
        elif valor == 6:
            self.c1.draw(self.ventana)
            self.c2.draw(self.ventana)
            self.c3.draw(self.ventana) 
            self.c5.draw(self.ventana)
            self.c6.draw(self.ventana)
            self.c7.draw(self.ventana)
            
    def limpiar(self):#limpiar el dado antes de pintar
        self.c1.undraw()
        self.c2.undraw()
        self.c3.undraw()
        self.c4.undraw()
        self.c5.undraw()
        self.c6.undraw()
        self.c7.undraw()
        
    def tirarDado(self):#funcion para visualizar aleatoriamente una cara
        posibles = [1, 2, 3, 4, 5, 6]
        num = choice(posibles)
        self.ponValor(num)
        return num