Ejemplo n.º 1
0
 def init(self):
     BasePlayer.init(self)
     self.pos = list(multiply(self.player.get_center(), common.block_size))
     self.move = [0, 0]
     self.crosshair_pic = common.colorize(BattlePlayer.crosshair_pic,
                                          self.player.color)
     self.empty_crosshair_pic = common.colorize(
         BattlePlayer.empty_crosshair_pic, self.player.color)
Ejemplo n.º 2
0
 def timed(msg):
     if rank == 0:
         print(colorize(msg, color='magenta'))
         tstart = time.time()
         yield
         print(
             colorize("done in %.3f seconds" % (time.time() - tstart),
                      color='magenta'))
     else:
         yield
Ejemplo n.º 3
0
# coding="utf-8"
import codecs
from PIL import Image
import numpy as np
import h5py
import matplotlib.pyplot as plt
import cv2
from common import colorize, Color
from math import *
import math
db_fname = 'results/SynthText.h5'
db = h5py.File(db_fname, 'r')
dsets = sorted(db['data'].keys())
count = 0
print "total number of images : ", colorize(Color.RED,
                                            len(dsets),
                                            highlight=True)


def rotate(img, pt1, pt2, pt3, pt4):

    # print (pt1,pt2,pt3,pt4)
    withRect = math.sqrt((pt4[0] - pt1[0])**2 + (pt4[1] - pt1[1])**2)
    heightRect = math.sqrt((pt1[0] - pt2[0])**2 + (pt1[1] - pt2[1])**2)
    #print (withRect,heightRect)
    if (withRect):
        angle = acos(abs(pt4[0] - pt1[0]) / withRect) * (180 / math.pi)
        #print (angle)

        if pt4[1] <= pt1[1]:
Ejemplo n.º 4
0
class SpinBox(Widget):

    up = [
        common.colorize(common.load_image("arrow.png", alpha=True), col)
        for col in ((0, 0, 0), (150, 0, 0))
    ]
    down = [pygame.transform.flip(surf, False, True) for surf in up]
    _hidden = False

    def __init__(self, label, pos, choices, default=None, on_change=None):
        self._choices = list(choices)
        self.index = 0
        self.label = label
        if default != None:
            self.value = default
        if on_change:
            self.on_change = on_change

        Widget.__init__(self, pos, text="", on_click=None)

        # add arrows
        up_pos = (self.pos[0] - SpinBox.up[0].get_width(), self.pos[1])
        down_pos = (
            self.pos[0] - SpinBox.up[0].get_width(),
            self.pos[1] + self.normal_surface.get_height() -
            SpinBox.down[0].get_height(),
        )
        self.up_widget = Widget(up_pos,
                                surfaces=SpinBox.up,
                                on_click=lambda: self.change(-1))
        self.down_widget = Widget(down_pos,
                                  surfaces=SpinBox.down,
                                  on_click=lambda: self.change(1))

        self.update()

    def choices():
        def fget(self):
            return self._choices

        def fset(self, choices):
            selected_element = self._choices[self.index]
            self._choices = choices
            try:
                self.index = choices.index(selected_element)
            except ValueError:
                self.index = 0
            self.update()

        return locals()

    choices = property(**choices())

    def change(self, diff):
        self.index += diff
        if hasattr(self, "on_change"):
            self.on_change()
        self.update()

    def update(self):
        self.surfaces_from_text(self.label + ": " +
                                str(self.choices[self.index]))
        self.up_widget.inactive = self.index == 0
        self.down_widget.inactive = self.index == len(self.choices) - 1

    def value():
        def fset(self, value):
            try:
                self.index = self.choices.index(value)
            except NameError:
                raise NameError("Could not find value in list of choices!")

        def fget(self):
            return self.choices[self.index]

        return locals()

    value = property(**value())

    def hidden():
        def fset(self, value):
            self._hidden = value
            self.up_widget.hidden = value
            self.down_widget.hidden = value

        def fget(self):
            return self._hidden

        return locals()

    hidden = property(**hidden())
Ejemplo n.º 5
0
 def __init__(self, player):
     BasePlayer.__init__(self)
     self.player = player
     self.select_pic = common.colorize(SelectPlayer.select_pic,
                                       self.player.color)
Ejemplo n.º 6
0
 def set_player_id(self, id):
     self._player_id = id
     self.name = self.names[id]
     self.color = self.colors[id]
     self.wall_pic = common.colorize(self.wall_pic, self.color)
     self.ground_pic = common.colorize(self.ground_pic, self.color)