def on_enter(self): super(ControlLayer, self).on_enter() ft_title = font.load("Arial", 32) ft_subtitle = font.load("Arial", 18) ft_help = font.load("Arial", 16) self.text_title = font.Text(ft_title, "Transition Demos", x=5, y=480, anchor_x=font.Text.LEFT, anchor_y=font.Text.TOP) self.text_subtitle = font.Text( ft_subtitle, transition_list[current_transition].__name__, x=5, y=400, anchor_x=font.Text.LEFT, anchor_y=font.Text.TOP) self.text_help = font.Text(ft_help, "Press LEFT / RIGHT for prev/next example, " "ENTER to restart example", x=320, y=20, anchor_x=font.Text.CENTER, anchor_y=font.Text.CENTER)
def __init__(self, level): super(CutScene3, self).__init__(level) self.skybox = level.skybox_space self.camera_pos = Vec3(100, 600, 1400) self.camera_pitch = -25 self.camera_heading = 30 self.camera_heading_speed = -1 self.station_pos = Vec3() self.station_vel = Vec3() self.station_accel = Vec3() self.station_accel_accel = Vec3() self.time = 0 self.credit_line = -1 self.subcredit_line = -1 self.credit_time = 2. self.subcredit_time = 2. self.max_credit_time = 2. self.max_subcredit_time = 2. self.subcredits = [] label1_font = font.load('Arial', 36., bold=True) self.label1 = font.Text(label1_font, '', color=(1, 1, 1, 1)) label2_font = font.load('Arial', 24., bold=True) self.label2 = font.Text(label2_font, '', color=(1, 1, 1, 1))
def _draw_items( self ): width, height = director.get_window_size() fo = font.load( self.font_items, self.font_items_size ) fo_selected = font.load( self.font_items, self.font_items_selected_size ) fo_height = int( (fo.ascent - fo.descent) * 0.9 ) if self.menu_halign == CENTER: pos_x = width / 2 elif self.menu_halign == RIGHT: pos_x = width - 2 elif self.menu_halign == LEFT: pos_x = 2 else: raise Exception("Invalid halign value for menu") for idx,item in enumerate( self.items ): if self.menu_valign == CENTER: pos_y = height / 2 + (fo_height * len(self.items) )/2 - (idx * fo_height ) elif self.menu_valign == TOP: pos_y = height - (idx * fo_height ) elif self.menu_valign == BOTTOM: pos_y = 0 + fo_height * len(self.items) - (idx * fo_height ) item._init_font( pos_x, pos_y, self.font_items, self.font_items_selected_size, self.font_items_size )
def on_enter(self): super(ControlLayer, self).on_enter() ft_title = font.load("Arial", 32) ft_subtitle = font.load("Arial", 18) ft_help = font.load("Arial", 16) self.text_title = font.Text(ft_title, "Transition Demos", x=5, y=480, anchor_x=font.Text.LEFT, anchor_y=font.Text.TOP) self.text_subtitle = font.Text(ft_subtitle, transition_list[current_transition].__name__, x=5, y=400, anchor_x=font.Text.LEFT, anchor_y=font.Text.TOP) self.text_help = font.Text(ft_help, "Press LEFT / RIGHT for prev/next example, " "ENTER to restart example", x=320, y=20, anchor_x=font.Text.CENTER, anchor_y=font.Text.CENTER)
def __init__(self, handler): mode.Renderer.__init__(self, handler) font.add_file('resources/amsterdam.ttf') self.amsterdam = font.load('Amsterdam Graffiti', 45) self.amsterdam_detail = font.load('Amsterdam Graffiti', 24) if(not self.handler.menu_boxes): self.handler.menu_boxes = [] for i in range(10): self.handler.menu_boxes.append((50, 700, 575 - i * BAR_HEIGHT, 575 - (i + 1) * BAR_HEIGHT))
def __init__(self, model): self.model = model self.model.push_handlers(self) self.window = window.Window(512, 512) self.keys = key.KeyStateHandler() self.window.push_handlers(self.keys) self.fps = clock.ClockDisplay(color=(1, 0, 0, 1)) self.font = font.load(None, 24, bold=True) self.bigfont = font.load(None, 48, bold=True) self.score_view = font.Text(self.font, "Score: 0", x=16, y=496, halign='left', valign='top', color=(1, 0, 0, .8)) self.game_over = font.Text(self.bigfont, "GAME OVER", x=256, y=256, halign='center', valign='center', color=(1, 0, 0, .8)) # View objects self.ship_view = ShipView(self.model.ship) self.bullet_views = gfx.ViewObjectBag(self.model.bullets, BulletView) self.asteroid_views = gfx.ViewObjectBag(self.model.asteroids, AsteroidView) self.dust = gfx.ParticleSystem(DustParticle) self.exhaust = gfx.ParticleSystem(ExhaustParticle) self.stars = gfx.SlowParticleSystem(Star) # Generate stars for i in range(20): dist = random.uniform(5, 20) x = random.uniform(0, 512) y = random.uniform(0, 512) angle = random.uniform(0, 72) self.stars.new_particle(x=x, y=y, vx=-dist * 0.05, vy=0, radius=dist, angle=angle) # Setup GL glEnable(GL_BLEND) glBlendFunc(GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA) glEnable(GL_LINE_SMOOTH) glEnable(GL_POINT_SMOOTH) glClearColor(0, 0, 0, 0)
def __init__(self, win): helv = font.load('Helvetica', win.width / 15.0) self.text = font.Text( helv, 'Hello!', x=win.width / 2, y=win.height / 2, halign=font.Text.CENTER, valign=font.Text.CENTER, color=(1, 1, 1, 0.5), ) h = font.load('Helvetica', 15) self.help = font.Text(h, 'to exit: type "smash" and press escape', x=10, y=win.height-25, color=(1,1,1,.5)) self.fps = clock.ClockDisplay()
def calculate_size(self): self.ft = font.load(self.font, self.font_size, dpi=self.font_dpi) self.char_height = self.ft.ascent - self.ft.descent - 1 glyphs = self.ft.get_glyphs("D") for g in glyphs: self.char_width = g.width
def __init__(self, *args, **kwargs): #Let all of the arguments pass through self.win = window.Window.__init__(self, *args, **kwargs) self.maxaliens = 50 # max num of aliens simultaneously on the screen clock.schedule_interval(self.create_alien, 0.5) clock.schedule_interval(self.update, 1.0 / 30) # update at FPS of Hz #clock.set_fps_limit(30) # setting text objects ft = font.load('Tahoma', 20) #Create a font for our FPS clock self.fpstext = font.Text(ft, y=10) # object to display the FPS self.score = font.Text(ft, x=self.width, y=self.height, halign=pyglet.font.Text.RIGHT, valign=pyglet.font.Text.TOP) # reading and saving images self.spaceship_image = pyglet.image.load( 'datas/game-resources/ship3.png') self.alien_image = pyglet.image.load( 'datas/game-resources/invader.png') self.bullet_image = pyglet.image.load( 'datas/game-resources/bullet_white_16.png') # create one spaceship self.spaceship = Spaceship(self.spaceship_image, x=50, y=50) self.aliens = [] # list of Alien objects self.bullets = [] # list of Bullet objects
def ranges(self, start, end): from pyglet import font for start, end, styles in self.zip_iter.ranges(start, end): font_name, font_size, bold, italic = styles ft = font.load(font_name, font_size, bold=bool(bold), italic=bool(italic), dpi=self.dpi) yield start, end, ft
def __init__(self, *args, **kwargs): #Let all of the arguments pass through self.win = window.Window.__init__(self, *args, **kwargs) clock.schedule_interval(self.update, 1.0/30) # update at 30 Hz clock.schedule_interval(self.create_alien, 1.0/2) # update at 5 Hz # setting text objects ft = font.load('Tahoma', 20) #Create a font for our FPS clock self.fpstext = font.Text(ft, y=10) # object to display the FPS self.score = font.Text(ft, x=self.width, y=self.height, halign=pyglet.font.Text.RIGHT, valign=pyglet.font.Text.TOP) # loading image self.spaceship_image = pyglet.image.load('images/ship3.png') self.spaceship = Spaceship(self.spaceship_image, x=200, y=50) self.alien_image = pyglet.image.load('images/invader.png') self.aliens = [] self.bullet_image = pyglet.image.load('images/bullet_white_16.png') self.bullets = []
def __init__(self, client, points=9, eye=1, wait=1, randomize=1, auto=0, speed=1, level=3): super(CalibrationLayer, self).__init__(0, 0, 255, 255) self.client = client self.points = points self.eye = eye self.wait = wait self.randomize = randomize self.auto = auto self.speed = speed self.level = level self.on_success = None self.on_failure = None self.window = director.window.get_size() self.screen = director.get_window_size() self.center_x = self.screen[0] / 2 self.center_y = self.screen[1] / 2 self.win_scale = (self.screen[0] / self.window[0], self.screen[1] / self.window[1]) self.font = font.load("Cut Outs for 3D FX", 32) self.circle_img = self.font.get_glyphs("E")[0].get_texture(True) self.circle_img.anchor_x = "center" self.circle_img.anchor_y = "center" self.pnt_img = self.font.get_glyphs("Y")[0].get_texture(True) self.pnt_img.anchor_x = "center" self.pnt_img.anchor_y = "center" self.circle = Sprite(self.circle_img, color=(255, 255, 0), scale=1, opacity=0) self.spinner = Sprite( resource.image("spinner.png"), position=(self.screen[0] / 2, self.screen[1] / 2), color=(255, 255, 255) )
def __init__(self, *args, **kwargs): super(MainWindow, self).__init__(*args, **kwargs) self.keys = window.key.KeyStateHandler() self.push_handlers(self.keys) # self.set_exclusive_mouse() self.width, self.height, self.rat3d, self.ratex = 640, 480, 1.05, 0.5 self.zoom, self.expand, self.mapping, self.blend = 0, 0, 0, 1 self.fgc, self.bgc = (1.0, 1.0, 1.0, 0.9), (0.1, 0.1, 0.1, 0.1) self.loadfgc, self.loadbgc = (0.4, 0.2, 0.4, 0.3), (0.6, 0.3, 0.6, 0.9) self.instfgc, self.instbgc = (0.1, 0.1, 0.5, 0.9), (0.5, 0.9, 0.9, 0.8) self.instbkwidth, self.instbkheight = 480, 400 bmplen = (self.instbkwidth / 8) * self.instbkheight self.instbkbmp = (ctypes.c_ubyte * bmplen)(*([255] * bmplen)) self.ticktimer, self.tick, self.insttimer, self.inst = 0.5, 0.0, 30, 1 self.printing, self.solver = 1, deque() self.stat = [None, 0, Queue.Queue(512)] # (key(1-9), direc), count, queue self.cmax, self.tanim = 18, [6, 3, 1, 3] # frames in rotate moving, speeds self.tcos, self.tsin = [1.0] * (self.cmax + 1), [0.0] * (self.cmax + 1) for i in xrange(1, self.cmax): t = i * math.pi / (2.0 * self.cmax) # 0 < t < pi/2 self.tcos[i], self.tsin[i] = math.cos(t), math.sin(t) self.tcos[self.cmax], self.tsin[self.cmax] = 0.0, 1.0 # pi/2 regulation self.InitRot() self.InitAxis() self.InitGL(self.width, self.height) self.textures = [None] * (len(self.ary_norm) * 2 + 1 + len(TEXIMG_CHAR)) self.loading, self.dat = 0, [('', 0, 0)] * len(self.textures) resource.add_font(FONT_FILE) self.font = font.load(FONT_FACE, 20) self.fontcolor = (0.5, 0.8, 0.5, 0.9) self.fps_display = clock.ClockDisplay(font=self.font, color=self.fontcolor) self.fps_pos = (-60.0, 30.0, -60.0) clock.set_fps_limit(60) clock.schedule_interval(self.update, 1.0 / 60.0)
def verticalMenuLayout(menu): width, height = director.get_window_size() fo = font.load(menu.font_item['font_name'], menu.font_item['font_size']) fo_height = int((fo.ascent - fo.descent) * 0.9) if menu.menu_halign == CENTER: pos_x = width // 2 elif menu.menu_halign == RIGHT: pos_x = width - menu.menu_hmargin elif menu.menu_halign == LEFT: pos_x = menu.menu_hmargin else: raise Exception("Invalid anchor_x value for menu") for idx, i in enumerate(menu.children): item = i[1] if menu.menu_valign == CENTER: pos_y = (height + (len(menu.children) - 2 * idx) * fo_height - menu.title_height) * 0.5 elif menu.menu_valign == TOP: pos_y = (height - ((idx + 0.8) * fo_height) - menu.title_height - menu.menu_vmargin) elif menu.menu_valign == BOTTOM: pos_y = (0 + fo_height * (len(menu.children) - idx) + menu.menu_vmargin) item.transform_anchor = (pos_x, pos_y) item.generateWidgets(pos_x, pos_y, menu.font_item, menu.font_item_selected)
def render(self, dt): self.window.clear() self.set_projection() font.add_file('./font/Pure-ThinDuranGo.ttf') arial = font.load('Roman', 9, dpi=96) text = 'Hello, world!' glyphs = arial.get_glyphs(text) #gs = GlyphString(text, glyphs) # glyph_string.draw() #for g in gs: # g.blit(x, y, z=0, width=None, height=None) label = pyglet.text.Label('Hello, world a', #font_name='./font/Pure-ThinDuranGo.ttf', font_size=14, x=10, y=10 ) label.draw() #glBegin(GL_LINES) #for ob in self.model: # self.render_ob(*ob) #glEnd() self.window.flip()
def __init__(self, value, size=20, color=(1, 1, 1, 1), shadow=True, halign="left", valign="bottom", background=False, pos=euclid.Vector3(0, 0, 0), border=False, width=None, fontname=None): super(Label, self).__init__(pos) self._fixed_width = width self._value = None self._color = color self.shadow = shadow self.halign = halign self.valign = valign self.background = background self.fontname = fontname if fontname else global_fontname self.size = size self.font = font.load(self.fontname, self.size, dpi=96) self.visible = anim.constant(1) self.render_border = border self.border = 5 self.set_text(value)
def __init__(self, title, lines): super(BulletListLayer, self).__init__() x, y = director.get_window_size() self.title = text.Label( title, (x/2, y-50), font_name = 'Gill Sans', font_size = 64, anchor_x='center', anchor_y='center' ) self.add( self.title ) start_y = (y/12)*8 font_size = 52 / (len(lines)/2.2+1) font_size = min(font_size, 52) line_font = font.load('Gill Sans', font_size) tot_height = 0 max_width = 0 rendered_lines = [] step = 300/ max(len(lines),1) i = 0 for line in lines: line_text = text.Label( line, (x/2, y-150-step*i), font_name = 'Gill Sans', font_size = font_size, anchor_x='center', anchor_y='center' ) i += 1 self.add( line_text )
def render(self): fnt = font.load(self.font_name, self.font_size) w = self.window.width h = self.window.height self.labels = [ font.Text(fnt, 'This text is top-left aligned with several lines.', 0, h, width=w, halign='left', valign='top'), font.Text(fnt, 'This text is centered in the middle.', 0, h // 2, width=w, halign='center', valign='center'), font.Text( fnt, 'This text is aligned to the bottom-right of the window.', 0, 0, width=w, halign='right', valign='bottom'), ]
def __init__(self, title, lines): super(BulletListLayer, self).__init__() x, y = director.get_window_size() self.title = text.Label( title, (x // 2, y - 100), font_name='Consolas', font_size=46, anchor_x='center', anchor_y='center') self.add(self.title) start_y = (y // 12) * 8 font_size = 22 line_font = font.load('Consolas', font_size) tot_height = 0 max_width = 0 rendered_lines = [] step = 40 i = 0 for line in lines: line_text = text.Label( line, (x // 2, y - 185 - step * i), font_name='Consolas', font_size=font_size, anchor_x='center', anchor_y='center') i += 1 self.add(line_text) bgimage = Sprite('background.jpg') bgimage.scale = 0.8 bgimage.position = x/2, y/2 - 200 self.add(bgimage, z=-1)
def __init__(self, client): super(HeadPositionLayer, self).__init__() self.client = client self.screen = director.get_window_size() self.font = font.load('Cut Outs for 3D FX', 384) arrow1_img = self.font.get_glyphs("I")[0].get_texture(True) arrow1_img.anchor_x = 'center' arrow1_img.anchor_y = 'center' arrow2_img = self.font.get_glyphs("J")[0].get_texture(True) arrow2_img.anchor_x = 'center' arrow2_img.anchor_y = 'center' self.arrows = [Sprite(arrow1_img, position=(self.screen[0] / 2, self.screen[1] / 8 * 7), color=(255, 0, 0), opacity=0, scale=.75, rotation=270), Sprite(arrow1_img, position=(self.screen[0] / 2, self.screen[1] / 8 * 7), color=(255, 0, 0), opacity=0, scale=.75, rotation=90), Sprite(arrow1_img, position=(self.screen[0] / 8, self.screen[1] / 2), color=(255, 0, 0), opacity=0, scale=.75, rotation=0), Sprite(arrow1_img, position=(self.screen[0] / 8 * 7, self.screen[1] / 2), color=(255, 0, 0), opacity=0, scale=.75, rotation=180), Sprite(arrow2_img, position=(self.screen[0] / 2, self.screen[1] / 8), color=(255, 0, 0), opacity=0, scale=.75, rotation=90), Sprite(arrow2_img, position=(self.screen[0] / 2, self.screen[1] / 8), color=(255, 0, 0), opacity=0, scale=.75, rotation=270)] for arrow in self.arrows: self.add(arrow) self.head = (0,0,0)
def __init__(self): self.selected_option = None self.selected_hot = False self.label_font = font.load('Arial', 24.0, bold=True) self.labels = [] width = height = 0 for name in self.options[::-1]: if name is None: height += 30 continue label = font.Text(self.label_font, name, color=self.text_color) label.y = height + 5 width = max(width, label.width) height += label.height self.labels.append(label) height += 10 self.width = width self.height = height self.x = 0 self.y = 0 self.has_exit = False
def __init__(self, x, y, width, height, font_name='Helvetica', size=10,\ bck_color = (0.9,0.9,0.9,1.0), text_color = (0.0,0.0,0.0,1.0)): """ Initialize all the default widget properties like position, size, background and foreground color, and other generic properties """ #Ortho coords self._x, self._y = x,y #Ortho dimensions self._width, self._height = width, height #Font loader self._size = size self._font = font.load(font_name,size) #Other properties self._line_color = bck_color self._text_color = text_color self._loaded = False self._line = Sprite.Sprite(self._x, self._y, self._width,\ self._height, None, self._line_color) self._text = font.Text(self._font, "", self._x, self._y,\ halign = font.Text.LEFT, \ valign = font.Text.BOTTOM, \ color = self._text_color)
def __init__(self, *args, **kwargs): #Let all of the arguments pass through self.win = window.Window.__init__(self, *args, **kwargs) self.maxaliens = 50 # max num of aliens simultaneously on the screen clock.schedule_interval(self.create_alien, 0.5) clock.schedule_interval(self.update, 1.0/30) # update at FPS of Hz #clock.set_fps_limit(30) # setting text objects ft = font.load('Tahoma', 20) #Create a font for our FPS clock self.fpstext = font.Text(ft, y=10) # object to display the FPS self.score = font.Text(ft, x=self.width, y=self.height, halign=pyglet.font.Text.RIGHT, valign=pyglet.font.Text.TOP) # reading and saving images self.spaceship_image = pyglet.image.load('images/ship3.png') self.alien_image = pyglet.image.load('images/invader.png') self.bullet_image = pyglet.image.load('images/bullet_white_16.png') # create one spaceship self.spaceship = Spaceship(self.spaceship_image, x=50, y=50) self.aliens=[] # list of Alien objects self.bullets=[] # list of Bullet objects
def _generate_title(self): width, height = director.get_window_size() fo = font.load(self.font_item['font_name'], self.font_item['font_size']) fo_height = int( (fo.ascent - fo.descent) * 0.9 ) if self.menu_halign == CENTER: self.font_title['x'] = width // 2 elif self.menu_halign == RIGHT: self.font_title['x'] = width - self.menu_hmargin elif self.menu_halign == LEFT: self.font_title['x'] = self.menu_hmargin else: raise Exception("Invalid anchor_x value for menu") self.font_title['anchor_x'] = self.menu_halign self.font_title['anchor_y'] = "center" self.font_title['text'] = self.title self.title_label = pyglet.text.Label( **self.font_title ) self.title_height = self.title_label.content_height if self.menu_valign == CENTER: self.title_label.y = (height + len(self.children) * fo_height + self.title_height) * 0.5 elif self.menu_valign == TOP: self.title_label.y = (height - self.menu_vmargin - self.title_height //2) elif self.menu_valign == BOTTOM: self.title_label.y = (0 + fo_height * (len(self.children)) + self.title_height + self.menu_vmargin)
def get_font(self, position=None, dpi=None): from pyglet import font font_name = self.styles.get('font_name') font_size = self.styles.get('font_size') bold = self.styles.get('bold', False) italic = self.styles.get('italic', False) return font.load(font_name, font_size, bold=bool(bold), italic=bool(italic), dpi=dpi)
def draw_text(self, text, position, color, scale=1.0): if len(color) == 3: color = (color[0], color[1], color[2], 1.0) if self._p.label_font is None: self._p.label_font = font.load(self._p.font_face, self._p.font_size, bold=True, italic=False) label = font.Text( self._p.label_font, text, color=color, valign=font.Text.BASELINE, halign=font.Text.CENTER, ) pgl.glPushMatrix() pgl.glTranslatef(*position) billboard_matrix() scale_factor = 0.005 * scale pgl.glScalef(scale_factor, scale_factor, scale_factor) pgl.glColor4f(0, 0, 0, 0) label.draw() pgl.glPopMatrix()
def glont(self, family, size): if not self.families.has_key(family): self.families[family] = {} if not self.families[family].has_key(size): self.families[family][size] = font.load(family, size) return self.families[family][size]
def __init__(self, parent, title="Window", position=None, constraints=(300, 250)): """Creates the window.""" super(Window, self).__init__() # If no position is given, center the window. if position is None: self.x = (parent.width - constraints[0]) / 2 self.y = (parent.height - constraints[1]) / 2 else: self.x, self.y = position self.parent = parent self.title = title self.width, self.height = constraints # title bar dragging self._is_dragging = False self._drag_x, self._drag_y = (0, 0) # Load a font for the titlebar. self._titlebarheight = 15 self.font = font.load(None, self._titlebarheight * 0.9, dpi=72) # manage widgets as a list self.widgets = [] parent.push_handlers(self)
def __init__(self, window, view): self.window = window self.view = view self.font = font.load('Helvetica', 10) self.fps = clock.ClockDisplay(font=self.font, interval=0.2, color=(0, 0, 0, 1))
def __init__(self): super(BackgroundLayer, self).__init__() self.screen = director.get_window_size() self.batch = BatchNode() self.add(self.batch) self.shapes = {"circle":"E", "square":"K", "oval":"F", "diamond":"T", "crescent":"Q", "cross":"Y", "star":"C", "triangle":"A"} self.font = font.load('Cut Outs for 3D FX', 128) self.glyphs = self.font.get_glyphs("".join(self.shapes.values())) ratio = 1 - self.screen[1] / self.screen[0] n = int(750 * ratio) for _ in range(0, n): img = choice(self.glyphs).get_texture(True) img.anchor_x = 'center' img.anchor_y = 'center' max_o = 96 o = choice([0, max_o]) speed = uniform(1, 10) sprite = Shape(img, rotation=randrange(0, 365), scale=uniform(ratio, 3 * ratio), position=(randrange(0, self.screen[0]), randrange(0, self.screen[1])), opacity=o, color=(randrange(0, 256), randrange(0, 256), randrange(0, 256))) if o == max_o: sprite.do(Repeat(FadeTo(0, speed) + FadeTo(max_o, speed))) else: sprite.do(Repeat(FadeTo(max_o, speed) + FadeTo(0, speed))) self.batch.add(sprite)
def __init__(self, space, run_pyglet, load): space.gravity = (G_VECTOR[0], G_VECTOR[1]) self.space = space self.epoch = 0 if (run_pyglet): pyglet.window.Window.__init__(self, width=constants.W_WIDTH, height=constants.W_HEIGHT) self.wind = 0 self.run_pyglet = run_pyglet self.push_handlers(GameEventHandler(self)) self.batch_draw = pyglet.graphics.Batch() font.add_file('./resources/neon_pixel.ttf') neon_pixel = font.load('Neon Pixel-7') self.define_scenario() self.define_game_objects() signal.signal(signal.SIGINT, signal_handler) self.pole_angle = self.get_pole_angle() self.angular_velocity = 0 self.learner = AI_controller.Learner(self, load) pyglet.clock.schedule(self.update) if not (run_pyglet): filename = datetime.datetime.fromtimestamp( time.time()).strftime('%Y%m%d%H%M%S') print "Gerando arquivo para listagem das performances (%s.txt)" % filename self.performances_file = open(("./performance/%s.txt" % filename), "w+")
def __init__(self, caption="Simulation"): """Initialisiert das Fenster.""" # Fenster öffnen try: config = Config(sample_buffers=1, samples=1, double_buffer=True) super(PendulumWindow, self).__init__(config=config, resizable=True, caption=caption) except: super(PendulumWindow, self).__init__(resizable=True, caption=caption) # Schrift laden self.font_sans = font.load(None, 16) # FPS self.fps_display = clock.ClockDisplay() # Pendel aufhängen self.single_pendulum = SinglePendulum(length=9.0, phi=pi / 5) self.double_pendulum = DoublePendulum() # Einstellungsfenster self.settings_window = SettingsWindow(self, pendulum=self.double_pendulum, position=(15, 15)) self.settings_window.reset()
def render(self): font.add_file(os.path.join(base_path, 'action_man.ttf')) fnt1 = font.load('Action Man', 16) fnt2 = font.load('Arial', 16) fnt3 = font.load('Times New Roman', 16) h = fnt3.ascent - fnt3.descent + 10 self.texts = [ font.Text(fnt1, 'Action Man', 10, h * 1), font.Text(fnt1, 'Action Man longer test with more words', 10, h*2), font.Text(fnt2, 'Arial', 10, h * 3), font.Text(fnt2, 'Arial longer test with more words', 10, h*4), font.Text(fnt3, 'Times New Roman', 10, h * 5), font.Text(fnt3, 'Times New Roman longer test with more words', 10, h*6), ]
def update_pointer(self): current_label: Label = self.labels[self.index] # print(current_label, current_label.text) font_object = font.load(current_label.get_style('font'), current_label.get_style('font_size')) font_height = font_object.ascent - font_object.descent self.pointer.x = current_label.x - self.pointer.width self.pointer.y = current_label.y + font_height / 2
def render(self): font.add_file(os.path.join(base_path, 'action_man.ttf')) # Hard-code 16-pt at 100 DPI, and hard-code the pixel coordinates # we see that font at when DPI-specified rendering is correct. fnt = font.load('Action Man', 16, dpi=120) self.text = font.Text(fnt, 'The DPI is 120', 10, 10)
def __init__(self,render): #Gain access to render self.surface = render global global_render global_render = render global global_UI global_UI = self self._height_pt = 7 self._width_pt = 9.2 #Load events self.surface.w.on_key_press = on_key_press self.surface.w.on_mouse_motion = on_mouse_motion self.surface.w.on_mouse_drag = on_mouse_drag self.surface.w.on_mouse_press = on_mouse_press #Control goes to engine self.f_header = font.load("Helvetica",18) self.f_small = font.load("Helvetica",12) self.f_large = font.load("Helvetica",22) #Load some rectangles/text self.testing() self.console_text = font.Text(self.f_header,"Console Mode",\ global_render.w.width-20,20,halign=font.Text.RIGHT,\ valign = font.Text.BOTTOM,color = self.C_WHITE) self.engine_text = font.Text(self.f_header,"Engine Mode",\ global_render.w.width-20,20,halign=font.Text.RIGHT,\ valign = font.Text.BOTTOM,color = self.C_WHITE) self.current_text = self.engine_text self.load_2Dtext(self.current_text) self.switch_focus("Engine") self.add_fps() self.add_world_coords() self.loaded_UI = True self.console = Console(400,200,self.C_GRAY,self.C_LIGHTGRAY,self.C_YELLOW,self.C_RED) self.keyboard = key.KeyStateHandler() global_render.w.push_handlers(self.keyboard) self.load_full_2DUI()
def __getitem__(self, index): from pyglet import font font_name, font_size, bold, italic = self.zip_iter[index] return font.load(font_name, font_size, bold=bool(bold), italic=bool(italic), dpi=self.dpi)
def get_font(self, position=None, dpi=None): from pyglet import font font_name = self.styles.get("font_name") font_size = self.styles.get("font_size") bold = self.styles.get("bold", False) italic = self.styles.get("italic", False) return font.load(font_name, font_size, bold=bool(bold), italic=bool(italic), dpi=dpi)
def __getitem__(self, index): from pyglet import font font_name, font_size, bold, italic, stretch = self.zip_iter[index] return font.load(font_name, font_size, bold=bold, italic=italic, stretch=stretch, dpi=self.dpi)
def render(self): font.add_file(os.path.join(base_path, 'courR12-ISO8859-1.pcf')) fnt = font.load('Courier', 16) h = fnt.ascent - fnt.descent + 10 self.texts = [ font.Text(fnt, 'ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz', 10, h * 1), ]
def __init__(self, text_x, text_y, **kwargs): self.kills = 0 Sprite.__init__(self, "ship.png", **kwargs) #Create a font for our kill message self.font = font.load('Arial', 28) #The pyglet.font.Text object to display the FPS self.kill_text = font.Text(self.font, y=text_y, x=text_x)
def default_font(size=10, style='mono'): global _defaultLoaded from pyglet import font filename,face = _font_styles.get(style, _font_styles['mono']) if not _defaultLoaded: fontpath = filepath.FilePath(__file__).parent().child('data').child(filename) font.add_file(fontpath.path) _defaultLoaded = True return font.load(face, size)
def get_font(self, position=None, dpi=None): from pyglet import font font_name = self.styles.get('font_name') font_size = self.styles.get('font_size') bold = self.styles.get('bold', False) italic = self.styles.get('italic', False) stretch = self.styles.get('stretch', False) return font.load(font_name, font_size, bold=bold, italic=italic, stretch=stretch, dpi=dpi)
def render(self): font.add_file(os.path.join(base_path, 'action_man.ttf')) font.add_file(os.path.join(base_path, 'action_man_bold.ttf')) font.add_file(os.path.join(base_path, 'action_man_italic.ttf')) font.add_file(os.path.join(base_path, 'action_man_bold_italic.ttf')) fnt = font.load('Action Man', self.font_size) fnt_b = font.load('Action Man', self.font_size, bold=True) fnt_i = font.load('Action Man', self.font_size, italic=True) fnt_bi = font.load('Action Man', self.font_size, bold=True, italic=True) h = fnt.ascent - fnt.descent self.labels = [ font.Text(fnt, 'Action Man', 10, 10 + 3 * h), font.Text(fnt_i, 'Action Man Italic', 10, 10 + 2 * h), font.Text(fnt_b, 'Action Man Bold', 10, 10 + h), font.Text(fnt_bi, 'Action Man Bold Italic', 10, 10) ]
def _generate_title(self): width, height = director.get_window_size() self.font_title['x'] = width // 2 self.font_title['text'] = self.title self.title_label = pyglet.text.Label(**self.font_title) self.title_label.y = height - self.title_label.content_height // 2 fo = font.load(self.font_title['font_name'], self.font_title['font_size']) self.title_height = self.title_label.content_height
def _generate_title( self ): width, height = director.get_window_size() self.font_title['x'] = width // 2 self.font_title['text'] = self.title self.title_label = pyglet.text.Label( **self.font_title ) self.title_label.y = height - self.title_label.content_height //2 fo = font.load( self.font_title['font_name'], self.font_title['font_size'] ) self.title_height = self.title_label.content_height
def __init__(self, *args, **kwargs): #Let all of the arguments pass through self.win = window.Window.__init__(self, *args, **kwargs) clock.schedule_interval(self.update, 1.0 / 30) # update at 30 Hz # setting text objects ft = font.load('Tahoma', 20) #Create a font for our FPS clock self.fpstext = font.Text(ft, y=10) # object to display the FPS
def __init__(self, window): """Set up the game state.""" self.window = window window.push_handlers(self) self.keys = key.KeyStateHandler() window.push_handlers(self.keys) self.roomX, self.roomY = 8,8 pyglet.resource.add_font("8bitlimo.ttf") self.font = font.load('8-bit Limit O BRK', 16, bold=False, italic=False) self.hfont = font.load('8-bit Limit O BRK', 36, bold=False, italic=False) self.ts = TileSet("tiles.png", 32, 32, 32, 32) self.room = Room(self.ts, 0, 32, codemap=codemap) self.fps_display = pyglet.clock.ClockDisplay() self.ouch = pyglet.resource.media("ouch.wav", streaming=False) self.hbar = sprite.Sprite(pyglet.resource.image("health.png"), x=10, y=self.window.height-25) self.loadTitle() pyglet.clock.schedule(self.update) pyglet.clock.schedule_interval(self.checkHealth, 0.125)
def __init__(self, *args, **kwargs): #Let all of the arguments pass through self.win = window.Window.__init__(self, *args, **kwargs) clock.schedule_interval(self.update, 1.0/30) # update at 30 Hz # setting text objects ft = font.load('Tahoma', 20) #Create a font for our FPS clock self.fpstext = font.Text(ft, y=10) # object to display the FPS
def __init__(self, levelNum, sound=True): global soundtrack events.AddListener(self) self.done = False self.deathDelay = 0 self.levelNum = levelNum strLevelNum = '%02d' % levelNum triggers = data.levelTriggers['leveltriggers' + strLevelNum] if not levelNum % 2: # even levels are repeats of previous images strLevelNum = '%02d' % (levelNum - 1) self.walkMask = data.levelMasks[strLevelNum] filePath = os.path.join(data.data_dir, 'levelbg%s-?.png' % strLevelNum) self.sound = sound bgPngs = glob.glob(filePath) bgPngs.sort() self.bgImages = [data.pngs[png] for png in bgPngs] self.avatar = Avatar() self.avatar.strings = player.strings[:] self.visualEffects = visualeffects.EffectManager() self.miscSprites = [] healthFont = font.load('Oh Crud BB', 28) #self.healthText = font.Text(healthFont, x=10, y=25, text='Health:') self.healthBar = HeartMeter() self.energyBar = EnergyMeter((240, 5)) self.fpsText = font.Text(healthFont, x=650, y=25) self.triggerZones = [] for rect, clsName in triggers.items(): cls = globals().get(clsName) if not cls: if len(rect) == 4: print "ERROR: couldn't find", clsName continue zone = cls(rect, self) self.triggerZones.append(zone) if hasattr(zone, 'sprite'): self.miscSprites.append(zone.sprite) if DEBUG and hasattr(zone, 'debugSprite'): self.miscSprites.append(zone.debugSprite) self.enemySprites = {} self.startLoc = [ key for key, val in triggers.items() if val == 'start location' ][0] if levelNum == 1 and self.sound: soundtrack = \ queueSoundtrack('8bp077-01-nullsleep-her_lazer_light_eyes.mp3') soundtrack.play()
def find_resource(type, filename): """return resource given type (e.g. RESOURCE_IMAGE) and filename""" path = os.path.join(path_for_resource_type(type), filename) if type == RESOURCE_IMAGE: return image.load(path) if type == RESOURCE_FONT: return font.load(path) if type == RESOURCE_SOUND: return media.load(path, streaming=False) if type == RESOURCE_MUSIC: return media.load(path, streaming=True) assert False
def render(self): fnt = font.load('', self.font_size) h = fnt.ascent - fnt.descent w = self.window.width self.labels = [ font.Text(fnt, 'LEFT', 0, 10 + 3 * h, width=w, halign='left'), font.Text(fnt, 'CENTER', 0, 10 + 2 * h, width=w, halign='center'), font.Text(fnt, 'RIGHT', 0, 10 + h, width=w, halign='right'), ]