def __init__(self): self.glyph = Glyph(CLIP, ncols=2, **DEFAULT) Macros['b'] = ('font', Font(P_BOLD, 8)) Macros['big'] = ('font', Font(P_REG, 16)) Macros['BIG'] = ('font', Font(P_BOLD, 16)) Macros['red'] = ('color', RED) Macros['green'] = ('color', GREEN) Macros['bkg_blu'] = ('bkg', BLUE) Macros['red_pot'] = REDPOT self.editor = Editor(EDITOR_CLIP, **DEFAULT) self.editor_info = Glyph(EDITOR_INFO_CLIP, **DEFAULT)
def __init__(self, text, x=0, y=0, width=200, height=200, font=config.DEFAULT_FONT_PATH, size=config.DEFAULT_FONT_SIZE, rgb=(255, 255, 255)): #Glyph variables Sprite.__init__(self, x, y) self.x = x self.y = y self.entries = {} Macros['red'] = ('color', (255, 0, 0)) self.font = pygame.font.Font(font, size) self.args = { 'bkg': (30, 30, 30), 'color': (255, 255, 255), 'font': self.font, 'spacing': 0 } height = self.heightCalculation(text) self.glyph = Glyph(Rect(x + 10, y + 6, width, height), ncols=1, **self.args) self.entries['0'] = text self.glyph.input(self.entries['0']) self.glyph.update() #Draw background and border self.drawBox() #Process input for link processing self.process_input = True
def map_print(user, maps): FONT = Font("silkscreen.ttf", 16) DEFAULT = { 'bkg': (0, 0, 0), 'color': (250, 250, 250), 'font': FONT, 'spacing': 0, #FONT.get_linesize(), } x = user.position[1] y = user.position[2] px = user.position[3] py = user.position[4] maps[y][x] = " " maps[py][px] = "+" conector = "" maps_impreso = [] for linea in maps: imprimir = conector.join(linea) maps_impreso.append(imprimir) maps_impreso = conector.join(maps_impreso) glyph = Glyph(Rect(0, 0, 600, 600), ncols=1, **DEFAULT) glyph.input(maps_impreso, justify='justified') glyph.update() return (glyph)
def get_glyph(self): type = random.choice(list(GLYPHS.keys())) angle = random.choice([0, 1, 2, 3]) self.glyph = Glyph(type, angle) self.glyph.rect.topleft = self.spawn_pos self.used = False self.dirty = True
def get_glyph(self, font, char_code, font_size, font_width, font_height): """ find glyph, create it if not found """ if font is None: font = self.default_font elif isinstance(font, Font): font = font else: font = self._scene.find_font(font) for glyph in self._glyphs: if glyph.char_code == char_code and \ glyph.font == font and \ glyph.font_size == font_size and \ glyph.width == font_width and \ glyph.height == font_height: return glyph glyph = Glyph(font, char_code, font_size, font_width, font_height) logger.debug(glyph) self._glyphs.append(glyph) glyph.object_index = len(self._glyphs) - 1 return glyph
def glyphs(self): if not hasattr(self, "__glyphs"): from fonts import fonts from shapely.wkb import loads from glyph import Glyph self.__glyphs = {} for glyphRow in fonts.sql.getGlyphs(getFontTableName(self.name)): name, unicodeCode, geomWKB = glyphRow geom = loads(geomWKB, hex=True) self.__glyphs[name] = Glyph(name, unicodeCode, geom) return self.__glyphs
def read(self, dirname): files = os.listdir(dirname) for file in files: curr_dir = os.path.dirname(os.path.realpath(__file__)) filename = os.path.join(curr_dir, dirname, file) with open(filename) as f: text = f.read() d = eval(text) for k, v in d.iteritems(): self.glyphs[k] = Glyph(data=v.split('\n')[1:-1]) w = self.glyphs[k].size[0] h = self.glyphs[k].size[1] self.size = max(self.size[0], w), max(self.size[1], h)
def __init__(self, svgFileName, charsToBeLoaded=None): self.name = changeFileExtension(extractFileName(svgFileName), "") self.glyphs = {} self.defaults = Container({ "width": 556, "height": None, "x": None, "y": None }) log.openSection("Reading glyphs from %s" % svgFileName, log.DEBUG) svgData = open(svgFileName, "r").read().replace('\n', '') self.letters = u"" startPos = 0 while startPos < len(svgData): startPos = svgData.find('<glyph', startPos) if startPos >= 0: endPos = svgData.find("/>", startPos) + 2 if endPos >= 0: tag = svgData[startPos:endPos] glyph = Glyph(tag, self) if isinstance(glyph.unicode, list): unicodes = glyph.unicode else: unicodes = [glyph.unicode] for unicode in unicodes: if not charsToBeLoaded or unicode in charsToBeLoaded: self.letters += unicode self.glyphs[unicode] = glyph startPos = endPos else: log.error("Unclosed glyph tag at %d" % startPos) break else: break self.letters = "".join(sorted(self.letters)) if charsToBeLoaded and len(charsToBeLoaded) <> len(self.glyphs.keys()): log.openSection("Not all characters found!", log.WARNING) log.warning("%d characters to be loaded, %d found" % (len(charsToBeLoaded), len(self.glyphs.keys()))) log.closeSection(level=log.WARNING) log.closeSection("%d glyphs found" % len(self.glyphs.keys()), level=log.DEBUG)
def get_glyph(self): ## create glyph type = G.next_glyph.glyph.type angle = G.next_glyph.glyph.angle self.glyph = Glyph(type, angle) self.glyph.rect.topleft = self.spawn_pos ## offset horizontal 'I' if self.glyph.rect.width // G.cell_w == 4: self.glyph.rect.left -= G.cell_w ## set flags G.next_glyph.used = True self.dirty = True ## check collision on spawn if self.collision(0, 0, 0): G.state = 'finished' G.message.set_text('game over', 'press enter') G.highscores.add(G.score)
def homogenize(g): a, b, c, d = g, g.rotated_90, g.rotated_90.rotated_90, g.rotated_90.rotated_90.rotated_90 a_h = a.flip_horizontal b_h, c_h, d_h = a_h.rotated_90, a_h.rotated_90.rotated_90, a_h.rotated_90.rotated_90.rotated_90 a_w = a.flip_vertical b_w, c_w, d_w = a_w.rotated_90, a_w.rotated_90.rotated_90, a_w.rotated_90.rotated_90.rotated_90 selection = {a, b, c, d, a_h, b_h, c_h, d_h, a_w, b_w, c_w, d_w} if not (a.width == b.width == c.width == d.width): if a.width < b.width: map(selection.remove, (a, c, a_h, c_h, a_w, c_w)) else: map(selection.remove, (b, d, b_h, d_h, b_w, d_w)) representative = min(selection, key=lambda glyph: glyph.score) selection.remove(representative) return representative, selection if __name__ == "__main__": memo = {} generations = 0 this_generation = {Glyph()} for i in range(generations + 1): print(f"Gen {i} ", end="-" * 80 + "\n") next_generation = {} for glyph in this_generation: rep, selection = homogenize(glyph) m = {'representative': rep, 'all_forms': selection | {rep}} for form in selection | {rep}: memo[form] = m next_generation |= form.children
def __init__(self): # Get origin origin_path = rospy.get_param("~origin_path", "") # TODO add loading of origin self.recording_state = False # TODO make a recording button # Display size = (800, 480) # Size of WaveRacer 4inch screen pygame.init() self.display = pygame.display.set_mode(size, 0) self.box_font = pygame.font.SysFont('monospaced', 30) self.side_rect = pygame.Rect(400, 0, 800, 480) self.bottom_rect = pygame.Rect(0, 400, 800, 480) # Side box displays depth, heading, location etc. self.side_box = Glyph(self.side_rect, font=self.box_font) # Bottom box holds logs self.bottom_box = Glyph(self.bottom_rect, font=self.box_font) Macros['L'] = ('font', pygame.font.SysFont('monospaced', 50)) Macros['M'] = ('font', pygame.font.SysFont('monospaced', 40)) Macros['S'] = ('font', pygame.font.SysFont('monospaced', 30)) Macros['red'] = ('color', (255, 0, 0)) Macros['green'] = ('color', (0, 255, 0)) Macros['blue'] = ('color', (0, 0, 255)) # Variables self.H = 0. # ??? self.A = 0. # ??? self.depth = 0. # ??? self.gps_msg = NavSatFix() self.battery_state = BatteryState() self.R = 0.0 # ??? self.P = 0.0 # ??? self.cpu = 0.0 # ??? self.hdd = 0.0 # ??? self.upt = 0.0 # ??? self.recording_state = False self.img = None self.log_list = [] self.bridge = CvBridge() # Setup timer to update display screen_hz = rospy.get_param("~screen_hz", 2.0) rospy.Timer(rospy.Duration(screen_hz), self.screenUpdateCallback) # Subscribers compass_topic = "/navio/compass" gps_topic = "/navio/gps" log_topic = "/logs" img_topic = "/image_small" battery_topic = "/navio/ups" depth_topic = "/depth" rec_topic = '/recording' rospy.Subscriber(img_topic, Image, self.imgCallback) rospy.Subscriber(gps_topic, NavSatFix, self.gpsCallback) rospy.Subscriber(compass_topic, Float32, self.compassCallback) rospy.Subscriber(log_topic, String, self.logCallback) rospy.Subscriber(battery_topic, BatteryState, self.batteryCallback) rospy.Subscriber(depth_topic, Vector3Stamped, self.depthCallback) rospy.Subscriber(rec_topic, Bool, self.recCallback)