当前位置: 首页>>代码示例>>Python>>正文


Python graphics.Graphics类代码示例

本文整理汇总了Python中graphics.Graphics的典型用法代码示例。如果您正苦于以下问题:Python Graphics类的具体用法?Python Graphics怎么用?Python Graphics使用的例子?那么, 这里精选的类代码示例或许可以为您提供帮助。


在下文中一共展示了Graphics类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。

示例1: timer

 def timer(self):
     print "Time: ", self.time
     print '==============\n'
     g = Graphics(config.MAP)
     g.print_grid()
     sleep(config.SLEEP_TIME)
     self.time += 1
开发者ID:yeswanth,项目名称:Ants,代码行数:7,代码来源:main.py

示例2: loop

def loop():
	g = Graphics()
	last_paint = 0

	pygame.key.set_repeat(500, 100)

	model = type('Model', (object,), {})
	model.exit = False
	model.new_scene = 'main_menu'
	model.wait = False	

	t = time.time()
	while not model.exit:
		
		while model.new_scene != None:
			next_scene = model.new_scene
			model.new_scene = None
			clazz = scenes[next_scene]
			#give the scene a handle to the mixer
			scene = clazz(model)

		events = pygame.event.get()
		keymap = {}
		for event in events:
			if event.type == pygame.KEYDOWN:
				if event.type == pygame.QUIT or (event.type == pygame.KEYDOWN and event.key == pygame.K_ESCAPE):
					return
			
		scene.update(events, time_passed = time.time() - t)
		t = time.time()

		if time.time() - last_paint > 1/30.0 or model.wait:
			#print 'fps: ', 1.0/(time.time() - last_paint)
			last_paint = time.time()
			g.paint(scene, model)
开发者ID:Spacejoker,项目名称:one-week-one-man,代码行数:35,代码来源:main.py

示例3: due_picture

def due_picture():
    data_list = db.run_query("due.sql")
    new_list = DueDate.time_converter(data_list)
    return_list = DueDate.make_dict(new_list)

    Graphics.setup(mode="RGBA", size=(1024, 1024), color=(255, 255, 255, 200))
    Graphics.make_image(return_list, "due.png")
开发者ID:CodecoolBP20161,项目名称:python-data-visualisation-dog-five,代码行数:7,代码来源:main.py

示例4: __init__

  def __init__(self, asset_path, fps, loc):
      """
        asset_path: the full path to the directory containing the art assets for this animation
      """
      model = [ (0,0), (0,100), (100,100), (100,0) ]
      super(AnimatedActor,self).__init__( model )
      gfx = Graphics()
      self._textures = list()
      image_names = os.listdir(asset_path)
      image_names.sort()
      for each in image_names:  
        path = os.path.join( asset_path, each ) #use path.join to insure cross platform
        self._textures.append( gfx.texture_register(path) )#register the texture with the graphics

        #we need to scale, and the scale factor needs to come from somewhere
#      for i,v in enumerate(self.images):
#        self.images[i] = pygame.transform.scale(v,( v.get_height()/3, v.get_width()/3    ))


      # Track the time we started, and the time between updates.
      # Then we can figure out when we have to switch the image.
      self._start = pygame.time.get_ticks()
      self._delay = 1000 / fps
      self._last_update = 0
      self._frame = 0

        # Call update to set our first image.
      self.update(pygame.time.get_ticks())
      self.loc = loc

      self.alive = True
      self.repeat = False
开发者ID:doggerelverse,项目名称:gelly,代码行数:32,代码来源:animatedactor.py

示例5: __init__

    def __init__(self, game= 0, playersave= 0):
        self.type  = "player"
        self.game = game
#        self.chunkno = 0
#        self.spawn = (240,260)    #spawn coordinates
        self.velx, self.vely, self.kbvelx, self.kbvely = 0, 0, 0, 0
        self.size = (24,48)        #size of the player sprite, used for hitbox logic etc. This cannot be changed without changing the logic in the hitbox functions!
        self.screensize = (32,48)

        self.upperbody = Graphics.loadplayerimages()[0]
        self.lowerbody = Graphics.loadplayerimages()[1]
        self.playervarsa()
        if not playersave:
            self.playervarsb_make()
            self.spawn = False
        else:
            self.playervarsb_load(playersave)
        
        #playerstatus variables
        self.walking, self.working, self.jumping, self.falling, self.knockedback = False, False, False, False, False
        self.walksound, self.worksound = False, False
        self.rect = pygame.Rect((0, 0), (40, 48))
        self.attrect = pygame.Rect((-100, -100), self.size)
        self.walkanimation = False
        self.workanimation = True
        self.dir = 0
开发者ID:FlyOHolic,项目名称:PyBlox,代码行数:26,代码来源:game.py

示例6: Display

class Display(object):
    """
    The display manager owns the pygame screen object, and the translation
    between world coordinates and screen coordinates. It also dispatches to the
    Graphics class to draw various kinds of objects.

    Architecturally, the display manager looks at the environment, and shows it
    as it chooses, rather than having the environment tell the display manager
    how to show its various pieces.
    """
    def __init__(self, environment, screen_size):
        self.environment = environment
        self.screen_size = screen_size
        self.pixels_per_unit = 15 # TEMP, hardcoded zoom level.
        flags = pg.HWSURFACE | pg.DOUBLEBUF
        if FULLSCREEN:
            flags |= pg.FULLSCREEN
        self.screen = pg.display.set_mode(tuple(self.screen_size), flags)

        self.screen_origin = vec.div(self.screen_size, 2)

        self.widgets = []

        if SHOW_JOYSTICK:
            for i, inp in enumerate(self.environment.inputs):
                self.widgets.append(JoystickWidget(self, inp, i))
        if SHOW_INFO:
            self.fps = 0.0
            self.widgets.append(InfoWidget(self))

        self.widgets.append(HealthWidget(self, self.environment.players))

        self.graphics = Graphics(self)

    def draw(self):
        self.screen.fill(BG_COLOR)

        for o in self.environment.objects:
            self.graphics.draw(o)
        for widget in self.widgets:
            widget.draw(self.screen)

        pg.display.flip()

    def to_screen(self, pos):
        """Convert pos to screen coordinates.

        Takes a tuple a world position, and returns a tuple for the
        screen position.
        """
        x, y = vec.add(
            self.screen_origin,
            vec.mul(pos, self.pixels_per_unit),
        )
        return (int(x), int(y))

    def set_fps(self, fps):
        self.fps = fps
开发者ID:christian-oudard,项目名称:momentum_game,代码行数:58,代码来源:display.py

示例7: renderhud

    def renderhud(inventory, inventoryqty, inventoryselected, inventoryopen, windowsize, fps, playerhealth):    #Creates the heads up display surface
        '''Creates and returns HUD'''
        #in: list of 40xint, int 0-9 , bool, tuple of 2 int
        #out: Surface object
        invsurf = pygame.Surface(windowsize, pygame.SRCALPHA, 32)
        text = pygame.font.Font(None, 15).render("FPS:" + str(fps)[0:4], 1, (84, 101, 112))
        invsurf.blit(text, (20,10)) 
        
        slotsize = (40,40)
        slotcolor = (42,42,160)
        slotnumcolor = (220, 220, 220)
        slotnumcolorselected = (40, 200, 40)
        slotnumsize = 16
        slotalpha = 180
        slotoffset = (8,8)
        slotoffset0 = (20, 20)
        
        #inventory
        if not inventoryopen:
            for slot in range(10):
                    slotimg = pygame.Surface(slotsize)
                    slotimg.fill(slotcolor)
#                    if inventory[slot] < 256:
                    slotimg.blit(Graphics.toolimg(inventory[slot]), (0,0))
                    slotimg.set_alpha(slotalpha)
                    slotimg.blit(pygame.font.Font(None, slotnumsize).render(str((slot +1)if slot < 9 else 0), 1, slotnumcolor if not slot == inventoryselected else slotnumcolorselected), (2,2))
                    slotimg.blit(pygame.font.Font(None, slotnumsize).render(str(inventoryqty[slot]), 1, slotnumcolor if not slot == inventoryselected else slotnumcolorselected), (2,28))
                    invsurf.blit(slotimg, (slot * (slotsize[0] + slotoffset[0]) + slotoffset0[0], slotoffset0[1]))

        elif inventoryopen:
            for row in range(4):
                for slot in range(10):
                    slotimg = pygame.Surface(slotsize)
                    slotimg.fill(slotcolor)
                    slotimg.blit(Graphics.toolimg(inventory[slot + 10*row]), (0,0))
                    slotimg.set_alpha(slotalpha)
                    if row ==0:
                        slotimg.blit(pygame.font.Font(None, slotnumsize).render(str(slot +1), 1, slotnumcolor if not slot == inventoryselected else slotnumcolorselected), (2,2))
                    slotimg.blit(pygame.font.Font(None, slotnumsize).render(str(inventoryqty[slot +10*row]), 1, slotnumcolor if not slot == inventoryselected else slotnumcolorselected), (2,28))
                    invsurf.blit(slotimg, (slot * (slotsize[0] + slotoffset[0]) + slotoffset0[0], row * (slotsize[1] + slotoffset[1]) + slotoffset0[1]))
        
        #health hearts
        for i in range(playerhealth[1] / 20):
            if playerhealth[0] / 20:
                playerhealth[0] -=20
                invsurf.blit(Graphics.hearts[0], (windowsize[0] - 46, 20 + 32 *i))
            elif playerhealth[0] / 10:
                playerhealth[0] -=10
                invsurf.blit(Graphics.hearts[1], (windowsize[0] - 46, 20 + 32 *i))
            else:
                invsurf.blit(Graphics.hearts[2], (windowsize[0] - 46, 20 + 32 *i))
                
        return invsurf
开发者ID:FlyOHolic,项目名称:PyBlox,代码行数:53,代码来源:game.py

示例8: get_graphics

    def get_graphics(self):
        url = os.path.join(self._task_master.get_bundle_path(), 'html-content',
                           self._uri)

        graphics = Graphics()
        webkit = graphics.add_uri('file://' + url, height=self._height)
        graphics.set_zoom_level(self._zoom_level)

        self._task_master.activity.set_copy_widget(webkit=webkit)
        self._task_master.activity.set_paste_widget()

        return graphics, self._prompt
开发者ID:cottonpaul,项目名称:OneSupport,代码行数:12,代码来源:tasks.py

示例9: game_loop

    def game_loop(self):
        clock = pygame.time.Clock()

        #Initialize
        self.scoreboard = Scoreboard()
        self.timer = CountDown()
        self.control = Control()
        self.graphics = Graphics(self.scoreboard, self.timer);
        self.player = Player(self.graphics)
        self.world = World(self.graphics, self.player) 
        self.logic = Logic(self.player, self.world, self.graphics, self.scoreboard, self.timer, self.control)
        
        while globalvars.run_game:
            delta = clock.tick(30) # fps

            # Catch input event
            for event in pygame.event.get():
                if event.type == QUIT:
                    return
                else:
                    self.control.update(event)
                
            # Update 
            self.logic.update(delta)
            self.world.update(delta)
            self.graphics.update(self.screen, delta)
            
            # Render
            self.graphics.draw(self.screen, delta);
            self.screen.blit(self.player.speedmsg, (0, 35))
            self.screen.blit(self.player.rotmsg, (0, 55))            
              
            pygame.display.flip()        
开发者ID:ivanvenosdel,项目名称:colored-shapes,代码行数:33,代码来源:main.py

示例10: __init__

    def __init__(self):
        ''' Initialize starting state'''
        self.graphics = Graphics()
        self.log = logging.getLogger("Game");
        logging.basicConfig(filename='main.log', level=DEBUG_LEVEL)
        self.log_handler = CursesHandler(self.graphics.windows["log"])
        self.log_handler.setLevel(DEBUG_LEVEL)
        self.log.addHandler(self.log_handler)
        self.commands = Commands(self)
        self.cursor_pos = [0,0]
        self.game_mode = GameModes.normal
        self.world = World(log_handler=self.log_handler)

        try:
            # Try to load a level from a text file and add it to the world
            # self.world.add_level(self.world.read_level('../data/testworld'))
            # self.world.get_current_level().add_entity(entity.creatures.SpaceOrk(5,5))
            self.world.add_level(
                    self.world.generate_level(
                        self.graphics.max_x, self.graphics.world_height))

            #Place player at spawn
            self.player = entity.creatures.Player(1,1)
            for ent in self.world.get_current_level().entities:
                if ent.__class__ == entity.world.PlayerSpawn:
                    self.player = entity.creatures.Player(ent.position[0],ent.position[1])

            self.world.get_current_level().add_entity(self.player)
        except Exception:
            # use better exception
            self.exit(1)

        self.log.debug("Game started")
开发者ID:ottopasuuna,项目名称:cyberogue,代码行数:33,代码来源:game.py

示例11: __init__

 def __init__(self, scripts, useGraphics = False, synchronizeGraphics = False, maximumRounds = DEFAULT_MAXIMUM_ROUNDS, decay = 1, minimumRounds = 0):
     '''
     Constructor for Game class.
     
     @param scripts: A dict of robotBehavior objects keyed to the script's name.
     @param useGraphics: The Graphics object being used to render the graphics object. If graphics is None, no graphical display will be done.
     @param synchronizeGraphics: If graphics are being used, making this True will cause the game loop to update at the same rate as the graphics loop,
     rather than running as fast as it can. This is available for debugging purposes.
     @param maximumRounds: The maximum number of rounds in the game.
     @param decay: The decay rate of the game, i.e. the probability that the next round will take place.
     @param minimumRounds: The minimum number of rounds in the game.
     '''
     
     # ====================
     # INITIALIZE VARIABLES
     # ====================
     
     # initialize passed in variables
     self.maximumRounds = maximumRounds
     self.decay = decay
     self.minimumRounds = minimumRounds
     self.scripts = scripts
     
     # if graphics are being used, initialize graphics
     if useGraphics: 
         self.graphics = Graphics()
         self.synchronizeGraphics = synchronizeGraphics
开发者ID:CSSDePaul,项目名称:Computerized-Robot-Arena-Program,代码行数:27,代码来源:game.py

示例12: updateblockgraphix

    def updateblockgraphix(self, blx, bly):     #updates graphics when a block changes
        self.newtex = Graphics.blocktexture((self.blocks[blx][bly] & 65280) >>8)[(self.blocks[blx][bly] & 240) >> 4]
#        self.surface.blit(self.newtex if not self.blocks[blx][bly] & 0b11110000 == 0b11110000 else pygame.transform.flip(self.newtex, np.random.randint(0, 1), np.random.randint(0, 1)), (blx * 16, bly * 16))
#        self.surface.blit(pygame.transform.flip(self.newtex, np.random.randint(0, 2), np.random.randint(0, 2)) if self.blocks[blx][bly] & 0b11110000 == 0b11110000 else self.newtex, (blx * 16, bly * 16))          #flips
        self.surface.blit(pygame.transform.flip(pygame.transform.rotate(self.newtex, np.random.randint(0, 4) *90), np.random.randint(0, 2), np.random.randint(0, 2))  if self.blocks[blx][bly] & 0b11110000 == 0b11110000 else self.newtex, (blx * 16, bly * 16))          #flips
        if settings.game["debugmode"]:        
            pygame.draw.line(self.surface, Color.red, (0,0), (0,1024))
            pygame.draw.line(self.surface, Color.red, (0,0), (1024,0))
开发者ID:FlyOHolic,项目名称:PyBlox,代码行数:8,代码来源:game.py

示例13: Actor

class Actor( object ):
  """
    Base Class for Actors. Actors are any objects with an onscreen representation.

    Actor class contains:
     model    : wireframe model representing the onscreen actor
     rectangle: bounding rectangle, projection of model on to the plane, used for intersection 
                and collision detection            
     texture  : image to texture the model
  """
  def __init__( self, model, texture=None, drawmode='polygon', offset=(0,0) ):
    """
      Initialize the actor
      INPUT:
            - model: unknown representation of this Actor's model, dependent on graphics system
            - texture: unknow representation of the texture to apply to this Actor's model
            - bounding_rect: rectangular projection of this actor's model onto the plane, used
                             for intersection and collision
            - gfx_sys: graphics system reference TODO: get rid of this
    """
    self._model = model #TODO assume array
    #self._boundrect = bounding_rect #TODO assume array
    self._texpath = texture #TODO assume path
    self._mode = drawmode
    self._gfxsys = Graphics()
    self._offset = offset
    if texture: 
      self._texid = self._gfxsys.texture_register( self._texpath )
    else:
      self._texid = None
    self._position = (0,0)
#=================================================================================================
  def draw( self, pos, name ):
    """
      Request that this object be drawn at pos
    """
    self._position = (pos[0]+self._offset[0],pos[1]+self._offset[1])
    #print self._position
    self._gfxsys.blit( self._model, self._position, name, self._texid, self._mode )
#=================================================================================================
  def updatepos( self, pos ):
    """
      update this actor's position outside of a draw call
    """
    self._position = pos
开发者ID:doggerelverse,项目名称:gelly,代码行数:45,代码来源:actor.py

示例14: _load_intro_graphics

 def _load_intro_graphics(self, file_name='generic-problem.html',
                          message=None):
     center_in_panel = Gtk.Alignment.new(0.5, 0, 0, 0)
     url = os.path.join(self.bundle_path, 'html-content', file_name)
     graphics = Graphics()
     if message is None:
         graphics.add_uri('file://' + url)
     else:
         graphics.add_uri('file://' + url + '?MSG=' +
                          utils.get_safe_text(message))
     graphics.set_zoom_level(0.667)
     center_in_panel.add(graphics)
     graphics.show()
     self.set_canvas(center_in_panel)
     center_in_panel.show()
开发者ID:cottonpaul,项目名称:OneSupport,代码行数:15,代码来源:activity.py

示例15: main

def main():
	# Parse arguments
	argparser = argparse.ArgumentParser()
	argparser.add_argument('-g', '--graphics', action="store_true")
	flags = argparser.parse_args()

	# Let there be light! (create an N-particle universe)
	universe = Universe(N_PARTICLES)
	print universe
	
	# Create graphics 
	if flags.graphics and graphics_imported:
		graph = Graphics(universe, GRAPHICS_DIR)
		graph.save_plot()
	
	# Incremenent time
	for i in xrange(50):
		print 'Computing step', i+1
		universe.increment_time()
		if flags.graphics and graphics_imported:
			graph.save_plot()
开发者ID:jonathangray92,项目名称:universe-simulator,代码行数:21,代码来源:main.py


注:本文中的graphics.Graphics类示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。