Пример #1
0
def main():
    pygame.init()
    # Setup the window (15*30, 15*30) : Resolution = 450,450
    screen = pygame.display.set_mode(
        (map_length * tile_size, map_height * tile_size))

    config = loader.load_json("config.json")
    images = loader.Images(config)

    lvl = game_class.Level(loader.map_from_file("map"), config["items"])
    mac_gyver = game_class.Character(lvl, config["items"])

    display.draw(lvl, mac_gyver, images, screen)

    continue_game = True
    end_game = False

    # Main game loop
    print("Have fun !")
    while continue_game:
        for event in pygame.event.get():  # iteration in all events
            if event.type == QUIT:
                continue_game = False
            if event.type == KEYDOWN:
                if not end_game:
                    if event.key == K_LEFT:
                        mac_gyver.move_to(left)
                    elif event.key == K_RIGHT:
                        mac_gyver.move_to(right)
                    elif event.key == K_UP:
                        mac_gyver.move_to(up)
                    elif event.key == K_DOWN:
                        mac_gyver.move_to(down)

                    if mac_gyver.status() == WIN:
                        print("You win")
                    elif mac_gyver.status() == LOST:
                        print("You loose")

                    if mac_gyver.status() != IN_MAZE:
                        print("\nDo you want to replay (y/n) ?")
                        end_game = True
                else:
                    if event.key == K_y:
                        print("Again!")
                        mac_gyver.reset()
                        lvl.reset()
                        end_game = False
                    elif event.key == K_n:
                        continue_game = False

                display.draw(lvl, mac_gyver, images, screen)
Пример #2
0
def draw_graph():
    type = select_type_inp(["Weekly", "Monthly", "Yearly", "Back"])

    if (type == "Back"):
        cmd_menu()
    else:
        type = type[0:len(type) - 2]
        file = select_type_inp(["Basic", "Deluxe", "Total", "Back"])

        if (file == "Back"):
            draw_graph()
        else:
            disp.draw(proc.calc_rev(file + ".txt", type), file, type)
Пример #3
0
def main():
    """Main function"""
    pygame.init()
    window = pygame.display.set_mode(
        (MAP_LENGTH * TILE_SIZE, MAP_HEIGHT * TILE_SIZE))

    config = load.config_from_file("config.json")
    images = load.Images(config)
    game = lvl.Maze(load.map_from_file("maze.xsb"), config["items"])
    mac_gyver = lvl.Hero(game, config["items"])

    display.draw(game, mac_gyver, images, window)

    in_game = True
    stop_game = False

    # Infinite loop
    print(config["start_msg"])
    while in_game:
        for event in pygame.event.get():  # Waiting for events
            if event.type == QUIT:
                in_game = False
            if event.type == KEYDOWN:
                if not stop_game:
                    if event.key == K_LEFT:
                        mac_gyver.move(LEFT)
                    elif event.key == K_RIGHT:
                        mac_gyver.move(RIGHT)
                    elif event.key == K_UP:
                        mac_gyver.move(UP)
                    elif event.key == K_DOWN:
                        mac_gyver.move(DOWN)

                    if mac_gyver.state == WIN:
                        print(config["win_msg"])
                    elif mac_gyver.state == LOST:
                        print(config["lost_msg"])

                    if mac_gyver.state != IN_MAZE:
                        print("\nAn other party (y/n) ?")
                        stop_game = True
                else:
                    if event.key == K_y:
                        print("\nHere we go again !")
                        mac_gyver.beginning()
                        game.start()
                        stop_game = False
                    elif event.key == K_n:
                        in_game = False

            display.draw(game, mac_gyver, images, window)
Пример #4
0
def main():
    """Main function"""
    pygame.init()
    window = pygame.display.set_mode(
        (MAP_LENGTH * TILE_SIZE, MAP_HEIGHT * TILE_SIZE))

    config = load.config_from_file("config.json")
    images = load.Images(config)
    lvl = game.Lvl(load.map_from_file("map.xsb"), config["items"])
    mac_gyver = game.Character(lvl, config["items"])

    display.draw(lvl, mac_gyver, images, window)

    continue_game = True
    end_game = False

    # Main game loop
    print(config["start_msg"])
    while continue_game:
        for event in pygame.event.get():  # iteration in all events
            if event.type == QUIT:
                continue_game = False
            if event.type == KEYDOWN:
                if not end_game:
                    if event.key == K_LEFT:
                        mac_gyver.move_to(LEFT)
                    elif event.key == K_RIGHT:
                        mac_gyver.move_to(RIGHT)
                    elif event.key == K_UP:
                        mac_gyver.move_to(UP)
                    elif event.key == K_DOWN:
                        mac_gyver.move_to(DOWN)

                    if mac_gyver.status == WIN:
                        print(config["end_msg_win"])
                    elif mac_gyver.status == LOST:
                        print(config["end_msg_lost"])

                    if mac_gyver.status != IN_MAZE:
                        print("\nDo you want to replay (y/n) ?")
                        end_game = True
                else:
                    if event.key == K_y:
                        print("Ejoy!")
                        mac_gyver.reset()
                        lvl.reset()
                        end_game = False
                    elif event.key == K_n:
                        continue_game = False

                display.draw(lvl, mac_gyver, images, window)
Пример #5
0
def radar(width, height, color):
    #radar display config
    screen_width = width
    screen_height = height
    x = pygame.init()
    pygame.font.init()
    defaultFont = pygame.font.get_default_font()
    fontRenderer = pygame.font.Font(defaultFont, 20)
    #screen_width = 800
    #screen_height =500
    radarDisplay = pygame.display.set_mode((screen_width, screen_height))
    pygame.display.set_caption('Radar Screen')
    #GPIO setup

    RangerRead = GroveUltrasonicRanger(5)

    # targets list
    targets = {}
    a = 0
    #radar read and write to dict
    while True:
        for angle in range(0, 180):
            distance = RangerRead.get_distance()
            distance = round(distance, 2)
            if distance != -1 and distance <= 50:
                targets[angle] = Target(angle, distance)

            draw(radarDisplay, targets, angle, distance, fontRenderer,
                 screen_width, screen_height, color)
            time.sleep(0.0001)
            #draw_bck(radarDisplay, fontRenderer, screen_width, screen_height)
        targets = {}

        for angle in range(180, 0, -1):
            distance = RangerRead.get_distance()
            distance = round(distance, 2)
            if distance != -1 and distance <= 50:
                targets[angle] = Target(angle, distance)

            draw(radarDisplay, targets, angle, distance, fontRenderer,
                 screen_width, screen_height, color)
            time.sleep(0.0001)

            #draw_bck(radarDisplay, fontRenderer, screen_width, screen_height)

        targets = {}
Пример #6
0
 def start(self):
     display.draw(self.board[:22, 2:-2], self.minos, self.score)
     while True:
         key = cv2.waitKeyEx(0)
         if key == 32:
             frameCnt = 0
             while True:
                 key = cv2.waitKeyEx(1)
                 a = self.update_mino(frameCnt, key)
                 display.draw(self.board[:22, 2:-2], self.minos, self.score)
                 frameCnt += 1
                 if key == 101:
                     break
                 if a:
                     self.init()
                     break
         elif key == 101:
             break
Пример #7
0
    if outfile:
        import display
        display = display.Display()

        import color
        import displaymethods

        edgedisp = display.add_method(
            displaymethods.EdgeDisplay(outputClones.posOutput))
        edgedisp.set_param('width',0.001)
        edgedisp.set_param('color',color.Gray(0.5))

        import psoutput
        device = psoutput.PSoutput(outfile)

        display.draw(mesh,device)
        
##        import psgfx
##        deformOutput = outputClones.VectorFieldOutput.clone()
##        deformOutput.plugParameter(displacement,"field")
##        positionSum = outputClones.VFieldSumOutput.clone()
##        positionSum.plugInput(deformOutput)
##        positionSum.plugInput(meshGUI.posOutput)

##        psgfx.psoutput(mesh, outfile, psgfx.PSgeometry(),
##                       [positionSum, meshGUI.posOutput])
        
    else:
        for node in mesh.funcnode_iterator():
            pos = node.position()
            print displacement.value(mesh, node, 0),\
Пример #8
0
        colordisp = display.add_method(
            displaymethods.CenterFillDisplay(outputClones.posOutput,
                                             outputClones.MaterialColorOutput))
        colordisp.set_param('colormap', color.graymap)

    if do_edges:
        edgedisp = display.add_method(
            displaymethods.EdgeDisplay(outputClones.posOutput))
        edgedisp.set_param('width', 0.001)
        edgedisp.set_param('color', color.Gray(0.5))

    if do_contours:
        cdisp = display.add_method(
            contourdisplay.PlainContourDisplay(outputClones.posOutput,
                                               funcOutput))
        cdisp.set_param('width', 0.005)
        cdisp.set_param('color', color.blue)
        cdisp.set_param('levels', nlevels)
        cdisp.set_param('nbins', contourbins)

    # get an output device
    import psoutput
    device = psoutput.PSoutput(psfilename)

    if proffile:
        import profiler
        prof = profiler.Profiler(proffile)
    display.draw(mesh, device)
    if proffile:
        prof.stop()
Пример #9
0
    # trace_enable()

    mesh.activate_field(temperature)
    mesh.activate_equation(heat_eqn)

    mesh.equilibrate(maxiters, tolerance, krylov_dim)

    if psfilename:
        thermalOutput = output.outputTypes['scalar field'].clone()
        thermalOutput.plugParameter(temperature, "field")
        rscl = outputClones.RescaleOutput.clone()
        rscl.plugInput(thermalOutput)
        rscl.plugParameter(0.0, "minimum")
        rscl.plugParameter(1.0, "maximum")

        import psoutput
        import display
        import displaymethods
        import color
        psdriver = psoutput.PSoutput(psfilename)

        display = display.Display()
        fill = display.add_method(
            displaymethods.CenterFillDisplay(outputClones.posOutput, rscl))
        fill.set_param('colormap', color.SpectralMap(saturation=0.9))
        display.draw(mesh, psdriver)

except ErrSetupError, s:
    print "Caught ErrSetupError."
    print "Message string: " + s.message()
Пример #10
0
try:
    while True:

        # rotate from 0 to 180

        for angle in range(0, 180):

            distance = ultrasonicRead(GPIO, TRIG, ECHO)

            # change the condition if the range is changed
            if distance != -1 and distance <= 50:
                targets[angle] = Target(angle, distance)
                xa[angle] = angle
                xd[angle] = distance
            draw(radarDisplay, targets, angle, distance, fontRenderer)

            angle = 180 - angle
            dc = 1.0 / 18.0 * angle + 2
            servo.ChangeDutyCycle(dc)

            time.sleep(0.001)

        # rotate from 180 to 0
        for angle in range(180, 0, -1):

            distance = ultrasonicRead(GPIO, TRIG, ECHO)

            # change the condition if the range is changed
            if distance != -1 and distance <= 50:
                targets[angle] = Target(angle, distance)
Пример #11
0
#!/usr/bin/python
# -*- coding:utf-8 -*-
import cam
import display
from tracks import Track 
import os
import time
from PIL import Image,ImageDraw,ImageFont
picdir = "."

player1 = Track(7)
display.init()
display.insertBmp(Image.open(os.path.join(picdir, 'menu.bmp')), None)
display.writeText(15, 25, 'hello')
display.writeText(15, 45, cam.checkDice())
display.writeText(25, 350, 'A')
display.writeText(95, 350, 'B')
display.writeText(170, 350, 'C')
display.writeText(240, 350, 'D')
display.draw()
player1.activateField(8)
time.sleep(5)
display.clear()
display.stop()
player1.activateField(0)
Пример #12
0
            if response == 'y':
                print("Guessing... ", end='')

                start = time.clock()
                guess = solve.guess(board)
                if guess:
                    board = guess
                    print("Guessed a correct solution!")
                else:
                    print("Couldn't find a solution; displaying the half-solved board.")
                duration += time.clock() - start

                break
            elif response == 'n':
                print("Will not try to guess and complete the board.")
                break
        duration -= time.clock() - now

# display board
if file_:
    print("Writing to file '{}'...".format(file_.name))
    display.write(board, file_, pretty_print, done)
else:
    print("Here is the solution:")
    display.draw(board, pretty_print, done)

# exit successfully!
duration += time.clock() - start
duration = round(duration, 1)
print('Execution complete in approximately {} seconds!'.format(duration))
sys.exit(0)
Пример #13
0
#GPIO setup

RangerRead = GroveUltrasonicRanger(5)

# targets list
targets = {}
a = 0
#radar read and write to dict
while True:
    for angle in range(0, 180):
        distance = RangerRead.get_distance()
        distance = round(distance, 2)
        if distance != -1 and distance <= 50:
            targets[angle] = Target(angle, distance)

        draw(radarDisplay, targets, angle, distance, fontRenderer,
             screen_width, screen_height)
        time.sleep(0.0001)
        #draw_bck(radarDisplay, fontRenderer, screen_width, screen_height)
    targets = {}

    for angle in range(180, 0, -1):
        distance = RangerRead.get_distance()
        distance = round(distance, 2)
        if distance != -1 and distance <= 50:
            targets[angle] = Target(angle, distance)

        draw(radarDisplay, targets, angle, distance, fontRenderer,
             screen_width, screen_height)
        time.sleep(0.0001)

        #draw_bck(radarDisplay, fontRenderer, screen_width, screen_height)
Пример #14
0
p.start(0)

targets = {}

try:
    while True:

        for a in range(0, 180):
            dist = int(ls.dLaser() / 10)  #conversao para cm
            print(dist)

            if dist != -1 and dist <= 50:
                targets[a] = Target(a, dist)
            else:
                targets[a] = Target(a, 50)
            draw(radarDisplay, targets, a, dist, fontRenderer)

            a = 180 - a
            dc = 1.0 / 18.0 * a + 2
            p.ChangeDutyCycle(dc)
            time.sleep(0.001)

        for a in range(180, 0, -1):
            dist = int(ls.dLaser() / 10)  #conversao para cm
            print(dist)

            if dist != -1 and dist <= 50:
                targets[a] = Target(a, dist)
            else:
                targets[a] = Target(a, 50)
            draw(radarDisplay, targets, a, dist, fontRenderer)
Пример #15
0
    mesh.activate_field(temperature)
    mesh.activate_equation(heat_eqn)

    mesh.equilibrate(maxiters, tolerance, krylov_dim)

    if psfilename:
        thermalOutput = output.outputTypes['scalar field'].clone()
        thermalOutput.plugParameter(temperature, "field")
        rscl = outputClones.RescaleOutput.clone()
        rscl.plugInput(thermalOutput)
        rscl.plugParameter(0.0, "minimum")
        rscl.plugParameter(1.0, "maximum")

        import psoutput
        import display
        import displaymethods
        import color
        psdriver = psoutput.PSoutput(psfilename)

        display = display.Display()
        fill = display.add_method(
            displaymethods.CenterFillDisplay(outputClones.posOutput, rscl))
        fill.set_param('colormap', color.SpectralMap(saturation=0.9))
        display.draw(mesh, psdriver)

    
except ErrSetupError, s:
    print "Caught ErrSetupError."
    print "Message string: " + s.message()
    
Пример #16
0
import argparse
import os
from display import draw
from PIL import Image

if __name__ == "__main__":
    parser = argparse.ArgumentParser(
        description='A CLI tool for displaying image on terminal.')
    parser.add_argument('-p',
                        '--image-path',
                        required=True,
                        help='the file path of image')
    args = parser.parse_args()

    if not os.path.isfile(args.image_path):
        print('[FAILED] \'{}\' is not a exists file'.format(args.image_path))
    else:
        print()
        draw(Image.open(args.image_path))