예제 #1
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
예제 #2
0
def setup(keybinds: Keybindings, square_size: int) -> Tuple[State, GraphWin]:
    '''
    Initializes the graphics and the list representing the grid
    '''
    rows, cols = (4, 9)
    start = (0, 4)

    grid_height = 0
    row_scale = rows * square_size
    if row_scale < 350:
        grid_height = 350
    else:
        grid_height = row_scale

    grid_width = 0
    col_scale = cols * square_size
    if col_scale < 350:
        grid_width = 350
    else:
        grid_width = col_scale

    # set up initial window
    win = GraphWin("Robot", grid_width, grid_height, autoflush=False)
    win.setBackground("green")

    help_str = '\n'.join(
        map(
            lambda item: 'Press {keys} to {desc}'.format(
                keys=', '.join(item[0]), desc=item[1][1]), keybinds.items()))
    help_text = Text(Point(win.getWidth() / 2,
                           win.getHeight() / 5 * 4), help_str)
    help_text.setFill("white")
    help_text.draw(win)

    return (State((rows, cols), start, Facing.RIGHT), win)
예제 #3
0
def main():
    win = GraphWin('Smartass Buster', 600, 800)
    exit_txt = Text(Point(win.getWidth() - 60,
                          win.getHeight() - 15), 'COMPUTE')
    exit_txt.draw(win)

    tri_thing = draw(win)

    if tri_thing:
        result = tri_thing.triangles()
    else:
        result = 0

    result1_txt = Text(Point(100,
                             win.getHeight() - 45), 'This figure contains')
    result2_txt = Text(Point(100,
                             win.getHeight() - 15),
                       '{} triangles'.format(result))
    result1_txt.draw(win)
    result2_txt.draw(win)
    win.getMouse()
예제 #4
0
win = GraphWin("pikMan", (size * 20), (size * 30))
win.setCoords(size, size, (size * 20), (size * 30))

gameStart = time.time()
gameTimer = 0.0
gameDuration = 25
alive = True

print('hello, pikman')
print(gameBoard[1][2])

win.setBackground("black")
# win.setBackground("white")
draw_board()

noticeText = Text(Point(win.getWidth() / 2, 250), "Welcome to Wonderland")
noticeText.setTextColor("yellow")
noticeText.draw(win)
scoreText = Text(Point(win.getWidth() / 2, 270), "127.0.0.1")
scoreText.setTextColor("white")
scoreText.draw(win)

pikColor = draw_pikman(pikLocation, pikColor)
draw_notice("Click anywhere to quit", "yellow")
draw_pik_score(pikScore, "0")
debug_print()

# ---------------------------------------------------------
# Start game loop
# ---------------------------------------------------------
while alive:
예제 #5
0

# pip install pyautogui
import pyautogui
from graphics import GraphWin, Circle, Point, Entry, color_rgb
import time

win = GraphWin("pipetka", 200, 200, autoflush=True)  # создаем графическую форму размером 200х200 и элементы на ней
x, y = pyautogui.position()  # получаем в x, y координаты мыши
r, g, b = pyautogui.pixel(x, y)  # получаем в r, g, b цвет

ColorDot = Circle(Point(100, 100), 25)  # создаем точку, отображающую цвет
ColorDot.setFill(color_rgb(r, g, b))  # устанавливает ей заливку из ранее полученных цветов
ColorDot.draw(win)  # рисуем на форме win

RGBtext = Entry(Point(win.getWidth() / 2, 25), 10)  # создаем RGB вывод
RGBtext.draw(win)  # рисуем на форме win

RGBstring = Entry(Point(win.getWidth() / 2, 45), 10)  # создаем вывод цвета в web стиле
RGBstring.draw(win)  # рисуем на форме win

Coordstring = Entry(Point(win.getWidth() / 2, 185), 10)  # создаем отображение координат
Coordstring.draw(win)  # рисуем на форме win

while True:  # цикл перереисовки формы
    time.sleep(0.1)  # задержка в 0.1 с, чтобы питон не сходил с ума

    x, y = pyautogui.position()  # получаем в x, y координаты мыши
    r, g, b = pyautogui.pixel(x, y)  # получаем в r, g, b цвет
    ColorDot.setFill(color_rgb(r, g, b))  # Обновляем цвет
    RGBtext.setText(pyautogui.pixel(x, y))  # Обновляем RGB