def on_init(self):

        #create display and set display attr
        pygame.display.init()
        self.display = pygame.display.set_mode(v.menu_size, 0, 32)
        pygame.display.set_caption("Einstellungen")
        self.display.fill((50, 50, 200))

        #create buttons and draw them
        self.buttons = self.create_buttons()
        for button0 in self.buttons.values():
            button0.draw_button()
        pt.Painter().write_text(self.display, "Settings", 50, (255, 255, 255),
                                (v.menu_x_size * 0.42, v.menu_y_size * 0.05))

        pt.Painter().write_text(self.display, "music:", 25, (255, 255, 255),
                                (v.menu_x_size * 0.1, v.menu_y_size * 0.25))
        pt.Painter().write_text(self.display, "sound:", 25, (255, 255, 255),
                                (v.menu_x_size * 0.5, v.menu_y_size * 0.25))
        pt.Painter().write_text(self.display, "version:", 25, (255, 255, 255),
                                (v.menu_x_size * 0.1, v.menu_y_size * 0.5))
        pt.Painter().write_text(self.display, "mode:", 25, (255, 255, 255),
                                (v.menu_x_size * 0.5, v.menu_y_size * 0.5))
        pt.Painter().write_text(self.display, "resolution:", 25,
                                (255, 255, 255),
                                (v.menu_x_size * 0.35, v.menu_y_size * 0.75))
        pygame.display.update()
Beispiel #2
0
def part_one(args, input_lines):
    "Process part one of the puzzle"

    # 1. Create the painter
    signer = painter.Painter(text=input_lines[0])

    # 2. Get the maximum of the amplifiers without feedback
    halted = signer.run(watch=args.verbose)
    if halted != intcode.STOP_HLT:
        print("painter stopped unexpectively, reason = %d" % (halted))
        solution = None
    else:
        solution = signer.at_least_once()
        print("%d panels painted at least once" % (solution))

    # 3. Return result
    return solution is not None
    parser = argparse.ArgumentParser(description=u'Fast Neural Style server.')
    parser.add_argument(u'--main_npy_path',
                        u'-mnp',
                        default=u'n_style.npy',
                        help=u'directory to trained feed forward network.')
    parser.add_argument(u'--style_npy_paths',
                        u'-snp',
                        default=[],
                        nargs='+',
                        help=u'directory to trained feed forward network.')
    parser.add_argument(u'--save_npy_path',
                        default=u'n_style_combined.npy',
                        help=u'directory to trained feed forward network.')
    args = parser.parse_args()

    p = painter.Painter(num_styles=args.num_styles, save_dir=args.save_dir)

    main_npy = np.load(args.main_npy_path).item()
    style_npys = [
        np.load(style_npy_path).item()
        for style_npy_path in args.style_npy_path
    ]
    num_styles = len(style_npys)

    variable_names = main_npy.keys()

    for var_name in variable_names:
        if var_name.endswith("scale") or var_name.endswith(
                "shift") or var_name == "input_style_placeholder":
            additional_vars = []
            for i in range(num_styles):
Beispiel #4
0
 def __init__(self):
     self.running = False
     self.game = game.HvsH_Game(v.window_size)
     self.painter = painter.Painter(self.game)
        max_value = df[str1].max()
    if max_value < df[str2].max():
        max_value = df[str2].max()

    return min_value, max_value


min_x, max_x = get_min_max_value(name_list[0], name_list[2])
min_y, max_y = get_min_max_value(name_list[1], name_list[3])

image_size_x = int((max_x - min_x) / resolution + margin)
image_size_y = int((max_y - min_y) / resolution + margin)

image_str = "P2\n" + str(image_size_x) + " " + str(image_size_y) + "\n255\n"
img = np.zeros((image_size_y, image_size_x))
p = painter.Painter()

for i in range(df[name_list[0]].size):
    a_x = (df[name_list[0]][i] - min_x) / resolution + margin / 2
    a_y = (df[name_list[1]][i] - min_y) / resolution + margin / 2
    b_x = (df[name_list[2]][i] - min_x) / resolution + margin / 2
    b_y = (df[name_list[3]][i] - min_y) / resolution + margin / 2
    img = p.paint_segment(img, a_x, a_y, b_x, b_y, wall_parameter)

for i in range(img.shape[0] - 1, -1, -1):
    for j in range(img.shape[1]):
        image_str += str(int((1 - img[i][j]) * 255)) + "\n"

with open(generated_file_path + image_name, mode='w') as f:
    f.write(image_str)
Beispiel #6
0
    def set_attributes(self):

        if self.surface is not None:

            #create following attributes, when surface is set
            self.surfaces = {
                "surface_full":
                self.surface,
                "surface_board":
                self.surface.subsurface(
                    pygame.Rect(0.1 * self.surface.get_width(), 0,
                                0.8 * self.surface.get_width(),
                                0.95 * self.surface.get_height())),
                "surface_stones": {
                    "white":
                    self.surface.subsurface(
                        pygame.Rect(0, 0, 0.1 * self.surface.get_width(),
                                    0.95 * self.surface.get_height())),
                    "black":
                    self.surface.subsurface(
                        pygame.Rect(0.9 * self.surface.get_width(), 0,
                                    0.1 * self.surface.get_width(),
                                    0.95 * self.surface.get_height()))
                },
                "surface_text": {
                    "white":
                    self.surface.subsurface(
                        pygame.Rect(0, 0.95 * self.surface.get_height(),
                                    0.5 * self.surface.get_width(),
                                    0.05 * self.surface.get_height())),
                    "black":
                    self.surface.subsurface(
                        pygame.Rect(0.5 * self.surface.get_width(),
                                    0.95 * self.surface.get_height(),
                                    0.5 * self.surface.get_width(),
                                    0.05 * self.surface.get_height()))
                },
                "surface_menu":
                self.surface.subsurface(
                    pygame.Rect(1 / 3 * self.surface.get_width(),
                                1 / 3 * self.surface.get_height(),
                                1 / 3 * self.surface.get_width(),
                                1 / 3 * self.surface.get_height()))
            }

            #the following building of backgrounds takes very long, as tickled color backgrounds are live calculated (random ect, see in backgrounds)
            #            self.backgrounds = {self.surfaces["surface_board"]: bg.tickled_color(self.surfaces["surface_board"], c.background_color2, c.background_color3),
            #                                self.surfaces["surface_stones"]["white"]: bg.standard_color(self.surfaces["surface_stones"]["white"], c.background_side_stones),
            #                                self.surfaces["surface_stones"]["black"]: bg.standard_color(self.surfaces["surface_stones"]["black"], c.background_side_stones),
            #                                self.surfaces["surface_text"]["white"]: bg.standard_color(self.surfaces["surface_text"]["white"], c.background_text_box),
            #                                self.surfaces["surface_text"]["black"]: bg.standard_color(self.surfaces["surface_text"]["black"], c.background_text_box)}
            self.backgrounds = None

            self.painter = painter.Painter(self.backgrounds)
            self.board = board.Board(self.board_size, self.surfaces)
            self.locator = locator.Locator(self.board, 100)
            self.buttons = self.create_buttons()

            #create sound_maker, players and interactor according to settings
            self.sound_maker = sm.sound_maker(sound=self.settings["sound"],
                                              music=self.settings["music"])
            if self.settings["mode"] == "hvsh":
                if self.settings["version"] == "basic":
                    self.players = {
                        "white": plh.Human_Player("white", self.surfaces),
                        "black": plh.Human_Player("black", self.surfaces)
                    }
                    self.interactor = interactor.Interactor(
                        self.painter,
                        cal_ex.Calculator_Extended(self.locator, self.players),
                        self.turn, self.buttons, self.sound_maker)
                elif self.settings["version"] == "extended":
                    self.players = {
                        "white":
                        ple.Human_Player_Extended("white", self.surfaces),
                        "black":
                        ple.Human_Player_Extended("black", self.surfaces)
                    }
                    self.interactor = interactor.Interactor(
                        self.painter,
                        cal_ex.Calculator_Extended(self.locator, self.players),
                        self.turn, self.buttons, self.sound_maker)
            elif self.settings["mode"] == "hvsc":
                if self.settings["version"] == "basic":
                    self.players = {
                        "white": plh.Human_Player("white", self.surfaces),
                        "black": plc.Computer_Player("black", self.surfaces)
                    }
                    self.com_action = ca.Computer_Action(
                        self.locator, self.players)
                    self.calculator = cal_ex.Calculator_Extended(
                        self.locator, self.players)
                    self.interactor = interactor.Interactor(
                        self.painter, self.calculator, self.turn, self.buttons,
                        self.sound_maker)
                elif self.settings["version"] == "extended":
                    self.players = {
                        "white":
                        ple.Human_Player_Extended("white", self.surfaces),
                        "black":
                        plc.Computer_Player_Extended("black", self.surfaces)
                    }
                    self.com_action = ca.Computer_Action(
                        self.locator, self.players)
                    self.calculator = cal_ex.Calculator_Extended(
                        self.locator, self.players)
                    self.interactor = interactor.Interactor(
                        self.painter, self.calculator, self.turn, self.buttons,
                        self.sound_maker)
            elif self.settings["mode"] == "cvsc":
                if self.settings["version"] == "basic":
                    self.players = {
                        "white": plc.Computer_Player("white", self.surfaces),
                        "black": plc.Computer_Player("black", self.surfaces)
                    }
                    self.calculator = cal_ex.Calculator_Extended(
                        self.locator, self.players)
                    self.interactor = interactor.Interactor(
                        self.painter, self.calculator, self.turn, self.buttons,
                        self.sound_maker)
                    self.com_action = {
                        "white":
                        ca.Computer_Action(self.locator, self.players,
                                           "white"),
                        "black":
                        ca.Computer_Action(self.locator, self.players, "black")
                    }
                elif self.settings["version"] == "extended":
                    self.players = {
                        "white":
                        plc.Computer_Player_Extended("white", self.surfaces),
                        "black":
                        plc.Computer_Player_Extended("black", self.surfaces)
                    }
                    self.calculator = cal_ex.Calculator_Extended(
                        self.locator, self.players)
                    self.interactor = interactor.Interactor(
                        self.painter, self.calculator, self.turn, self.buttons,
                        self.sound_maker)
                    self.com_action = {
                        "white":
                        ca.Computer_Action(self.locator, self.players,
                                           "white"),
                        "black":
                        ca.Computer_Action(self.locator, self.players, "black")
                    }
Beispiel #7
0
                    help=u'GPU ID (negative value indicates CPU)')
parser.add_argument(u'--gpu_fraction', u'-gf', type=float, default=0.5,
                    help=u'Fraction of gpu memory to use. CPU mode is unaffected by this option.')
parser.add_argument(u'--port', u'-p', type=int, default=8000,
                    help=u'using port')
parser.add_argument(u'--host', u'-ho', default=u'localhost',
                    help=u'using host')
parser.add_argument(u'--save_dir', u'-sv', default=u'model/',
                    help=u'directory to trained feed forward network.')
parser.add_argument(u'--num_styles', u'-ns', type=int, default=38,
                    help=u'Number of styles')

parser.add_argument('--do_load_from_npy', dest='do_load_from_npy',
                    help='If true, it loads the weights from an npy file instead of from a checkpoint. '
                         '(default %(default)s).', action='store_true')
parser.set_defaults(do_load_from_npy=False)
parser.add_argument(u'--npy_path', default=u'n_style_combined_1_to_55.npy',
                    help=u'directory to a npy file storing combined weights.')
args = parser.parse_args()

print u'GPU: {}'.format(args.gpu)

p = painter.Painter(num_styles=args.num_styles, save_dir=args.save_dir, gpu=args.gpu, gpu_fraction=args.gpu_fraction, do_load_from_npy=args.do_load_from_npy,npy_path=args.npy_path)

httpd = BaseHTTPServer.HTTPServer((args.host, args.port), MyHandler)
print u'serving at', args.host, u':', args.port
httpd.serve_forever()

"""
python server.py --gpu=0 --save_dir=model/feed_forward_first_38_imgs-1024 --host
"""