Example #1
0
 def test_fps(self):
     clock.set_default(clock.Clock())
     self.assertTrue(clock.get_fps() == 0)
     for i in range(10):
         time.sleep(0.2)
         clock.tick()
     result = clock.get_fps()
     self.assertTrue(abs(result - 5.0) < 0.05)
Example #2
0
 def test_fps(self):
     clock.set_default(clock.Clock())
     self.assertTrue(clock.get_fps() == 0)
     for i in range(10):
         time.sleep(0.2)
         clock.tick()
     result = clock.get_fps()
     self.assertTrue(abs(result - 5.0) < 0.05)
Example #3
0
    def on_draw(self):
        self.clear()
        clock.tick()

        self.fpstext.text = "fps: %d" % clock.get_fps()
        self.fpstext.draw()

        self.score.text = "Score: %d" % self.spaceship.kills
        self.score.draw()

        self.spaceship.draw()
        for alien in self.aliens:
            alien.draw()

        for bullet in self.bullets:
            bullet.draw()

        # Collisions
        for alien in self.aliens:
            for bullet in self.bullets:
                if distance(bullet,
                            alien) < (bullet.width / 2 + alien.width / 2):
                    bullet.dead = True
                    alien.dead = True
                    self.spaceship.kills += 1
            if distance(alien, self.spaceship) < (alien.height / 2 +
                                                  self.spaceship.height / 2):
                print("Your score is: {} kills".format(self.spaceship.kills))
                pyglet.app.exit()
Example #4
0
def wait(ms):
    a = clock.get_fps()
    ct = 0
    loopcount = (ms / 1000.0) * a
    while ct < loopcount:
        clock.tick()
        ct += 1
Example #5
0
def wait(ms):
	a = clock.get_fps()
	ct = 0
	loopcount = (ms / 1000.0) * a
	while ct < loopcount:
		clock.tick()
		ct+=1
Example #6
0
    def draw_label(self):
        """ Draw the label in the top left of the screen.

        """
        x, y, z = self.position
        pitch, yaw = self.rotation
        self.label.text = '%02d (%.2f, %.2f, %.2f) - %.2f %.2f' % (
            get_fps(), x, y, z, pitch, yaw)
        self.label.draw()
Example #7
0
def statusUpdates(dt):
    position = tuple(int(a) for a in player.getPos())
    velocity = tuple(int(a) for a in player.getVelocity())
    fps = clock.get_fps()

    status.setParameter('Vertices', world.numVertices())
    status.setParameter('Position', position)
    status.setParameter('Chunk updates', world.chunksAwaitingUpdate())
    status.setParameter('Velocity', velocity)
    status.setParameter('FPS', fps)
Example #8
0
def statusUpdates(dt):
    position = tuple(int(a) for a in player.getPos())
    velocity = tuple(int(a) for a in player.getVelocity())
    fps = clock.get_fps()

    status.setParameter("Vertices", world.numVertices())
    status.setParameter("Position", position)
    status.setParameter("Chunk updates", world.chunksAwaitingUpdate())
    status.setParameter("Velocity", velocity)
    status.setParameter("FPS", fps)
    def on_draw(self):
        self.clear()  # clearing buffer
        clock.tick()  # ticking the clock

        # showing FPS
        self.fpstext.text = "fps: %d" % clock.get_fps()
        self.fpstext.draw()

        # flipping
        self.flip()
Example #10
0
def on_draw():
    window.clear()
    set_3d()
    scene.draw()
    set_2d()
    title_label.draw()
    num_objs_label.draw()
    fps_label.text = "FPS: " + str("%.2f" % clock.get_fps())
    fps_label.draw()
    unset_2d()
Example #11
0
def statusUpdates(dt):
    position = tuple(int(a) for a in player.getPos())
    velocity = tuple(int(a) for a in player.getVelocity())
    fps = clock.get_fps()
    
    status.setParameter('Vertices', world.numVertices())
    status.setParameter('Position', position)
    status.setParameter('Chunk updates', world.chunksAwaitingUpdate())
    status.setParameter('Velocity', velocity)
    status.setParameter('FPS', fps)
Example #12
0
 def on_draw(self):
     self.clear() # clearing buffer
     clock.tick() # ticking the clock
     
     # showing FPS
     self.fpstext.text = "fps: %d" % clock.get_fps()
     self.fpstext.draw()
                
     # flipping
     self.flip()
Example #13
0
 def on_draw(self):
     """Clear the current OpenGL context, reset the model/view matrix and
     invoke the `draw()` methods of the renderers in order
     """
     if self.land.paused:
         # you may want to do something
         pass
     else:
         self.clear()
         self.land.draw()
         print 'FPS is %f' % clock.get_fps()
Example #14
0
    def test_fps_limit(self):
        clock.set_default(clock.Clock())
        clock.set_fps_limit(20)
        self.assertTrue(clock.get_fps() == 0)

        t1 = time.time()
        clock.tick()  # One to get it going
        for i in range(20):
            clock.tick()
        t2 = time.time()
        self.assertTrue(abs((t2 - t1) - 1.) < 0.05)
Example #15
0
	def draw(self,dt):

		glClear(GL_COLOR_BUFFER_BIT |GL_DEPTH_BUFFER_BIT)
		glColor3f(0.5, 0.5, 1.0)	# set the color to sky-blue
		# pyglet.gl.glColor4f(0.23,0.23,0.23,1.0) # gray
		scenario.geom_draw() # get all the drawing
		scenario.geom_update(dt)

		print 'FPS is %f' % clock.get_fps()

		return pyglet.event.EVENT_HANDLED
Example #16
0
    def test_fps_limit(self):
        clock.set_default(clock.Clock())
        clock.set_fps_limit(20)
        self.assertTrue(clock.get_fps() == 0)

        t1 = time.time()
        clock.tick() # One to get it going
        for i in range(20):
            clock.tick()
        t2 = time.time()
        self.assertTrue(abs((t2 - t1) - 1.) < 0.05)
    def update(self, entity):
        self.fps = get_fps()

        if self.fps == 0: 
            self.fps = 1
        
        entity.speedY -= self.gravity

        self.checkWorldCollision(entity)

        entity.x += entity.speedX / self.fps
        entity.y += entity.speedY / self.fps
Example #18
0
def run(runs=3):
    torus = Torus(1, 0.3, 500, 500)
    rx = ry = rz = 0
    count = 0
    w.dispatch_events()
    clock.tick()

    while not w.has_exit:
        dt = clock.tick()
        rx += dt * 1
        ry += dt * 80
        rz += dt * 30
        rx %= 360
        ry %= 360
        rz %= 360

        w.dispatch_events()

        glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT)
        glLoadIdentity()
        glTranslatef(0, 0, -4)
        glRotatef(rz, 0, 0, 1)
        glRotatef(ry, 0, 1, 0)
        glRotatef(rx, 1, 0, 0)
        torus.draw()

        w.flip()

        if count > 2.0:
            count = 0.0
            print clock.get_fps()
            runs -= 1
            if runs == 0:
                # break
                pass
        count += dt

    torus.cleanup()
    return w.has_exit
Example #19
0
    def on_draw(self):
        if not self.paused:
            self._update_image()
        self.current_page.draw()
        if self.current_transition is not None:
            if self.current_transition.state == 2:
                self.current_transition = None
            else:
                self.current_transition.update()
                self.current_transition.sprite.draw()
        self.after_draw()

        self.current_framerate = clock.get_fps()
Example #20
0
    def update(self, dt):
        self.player.cshape.center = self.player.position
        x, y = self.player.velocity
        speed_kf = 1

        diag = False
        if x != 0 and y != 0:
            diag = True
        collisions = self.parent.PLAYER_WATER_COLLISION_MANAGER.objs_colliding(
            self.player)
        if collisions:
            speed_kf = 0.33

        if diag:
            speed_kf = 0.66
            if collisions:
                speed_kf = 0.25

        cave_collisions = self.parent.PLAYER_CAVE_COLLISION_MANAGER.objs_colliding(
            self.player)
        if cave_collisions:
            cocos.director.director.pop()

        self.player.movement_precision = ((self.player.speed * speed_kf) /
                                          (clock.get_fps() or 60)) * (
                                              (clock.get_fps() or 60) / 10) * 3

        if x != 0:
            x = self.player.movement_precision * (-1 if x < 0 else 1)

        if y != 0:
            y = self.player.movement_precision * (-1 if y < 0 else 1)

        self.player.velocity = Vector2(x, y)

        if self.face != self.c_face:
            self.player.switch_face(self.face)
            self.c_face = self.face
            self.parent.set_focus(*self.player.position, force=True)
Example #21
0
def run(runs=3):
    torus = Torus(1, 0.3, 500, 500)
    rx = ry = rz = 0
    count = 0
    w.dispatch_events()
    clock.tick()

    while not w.has_exit:
        dt = clock.tick()
        rx += dt * 1
        ry += dt * 80
        rz += dt * 30
        rx %= 360
        ry %= 360
        rz %= 360

        w.dispatch_events()

        glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT)
        glLoadIdentity()
        glTranslatef(0, 0, -4)
        glRotatef(rz, 0, 0, 1)
        glRotatef(ry, 0, 1, 0)
        glRotatef(rx, 1, 0, 0)
        torus.draw()

        w.flip()

        if count > 2.:
            count = 0.
            print clock.get_fps()
            runs -= 1
            if runs == 0:
                #break
                pass
        count += dt

    torus.cleanup()
    return w.has_exit
Example #22
0
    def on_draw(self):
        self.clear()  # clearing buffer
        clock.tick()  # ticking the clock

        # showing FPS
        self.fpstext.text = "fps: %d" % clock.get_fps()
        self.fpstext.draw()

        self.spaceship.draw()
        for alien in self.aliens:
            alien.draw()

        # flipping
        self.flip()
Example #23
0
 def on_draw(self):
     self.clear() # clearing buffer
     clock.tick() # ticking the clock
     
     # showing FPS
     self.fpstext.text = "fps: %d" % clock.get_fps()
     self.fpstext.draw()
     
     self.spaceship.draw()
     for alien in self.aliens:
         alien.draw()
     
     # flipping
     self.flip()
Example #24
0
    def call_user_update(self):
        self.pypen.user_sketch.TIME = self.pypen.user_sketch.T = self.passed_time
        self.pypen.user_sketch.FRAME = self.pypen.user_sketch.F = self.frame_count
        self.pypen.user_sketch.DELTA_TIME = self.pypen.user_sketch.DT = self.delta_time
        self.pypen.user_sketch.FPS = clock.get_fps()

        self.pypen.user_sketch.WIDTH = self.pypen.user_sketch.settings.width
        self.pypen.user_sketch.HEIGHT = self.pypen.user_sketch.settings.height

        if self.pypen.user_sketch.settings._user_has_update:
            try:
                self.pypen.user_sketch.update()
            except KeyboardInterrupt as exception:
                sys.exit(self.destroy())
Example #25
0
    def draw_label(self):
        """ Draw the label in the top left of the screen.

        """
        x, y, z = self.player.position
        dx, dy, dz = self.player.get_sight_vector()
        alpha, beta = self.player.rotation
        posx, posy = self.mouse_pos
        self.label.text = '%f (%d, %d, %d) (%f, %f ,%f) (%d, %d)' % (
            clock.get_fps(), x, y, z, dx, dy, dz, alpha, beta)
        self.label.draw()
        self.zoom_label.text = str(self.player.health)
        self.zoom_label.draw()
        pass
    def main_loop(self):
        ft = font.load('Arial', 28)
        fps_text = font.Text(ft, y=10)

        while not self.has_exit:
            self.dispatch_events()

            self.update()
            self.draw()

            clock.tick()
            fps_text.text = "fps: %d" % clock.get_fps()
            fps_text.draw()

            self.flip()
Example #27
0
		def mainLoop(self):
				
				ft = font.load('Arial', 28)
				fps_text = font.Text(ft, y=10)
				
				while not self.has_exit:
						self.dispatch_events()
						self.clear
						
						clock.tick()
						
						fps_text = ("fps: %d") % (clock.get_fps())
						fps_text.draw()
						
						self.flip()
Example #28
0
    def main_loop(self):
        ft = font.load('Arial', 28)
        fps_text = font.Text(ft, y=10)

        while not self.has_exit:
            self.dispatch_events()

            self.update()
            self.draw()

            clock.tick()
            fps_text.text = "fps: %d" % clock.get_fps()
            fps_text.draw()

            self.flip()
Example #29
0
 def update(self, draw=True):
     self.tick()
     if draw:
         glClearColor(132 / 255.0, 202 / 255.0, 236 / 255.0, 1)  # why is this here (and not in draw)? (FIXME?)
         puit.gamemaster.viewport.begin()
         # glClear(GL_COLOR_BUFFER_BIT) # <-- this isn't needed. we're clearing the
         # colour buffer anyways, below. self.clear() also clears the depth
         # buffer, which isn't needed yet, but i've left it in since i want to
         # make use of that soon.
         puit.gamemaster.clear()
         self.draw()
         if Gamestate.show_fps:
             puit.gamemaster.pixelfont.draw("%.1f fps" % clock.get_fps(), 1, 1)
             puit.gamemaster.pixelfont.draw("%d obj" % len(self.objects), 1, 7)
         puit.gamemaster.viewport.end()
         puit.gamemaster.flip()
Example #30
0
	def run(self):
		self.window.set_visible()
		self.window.set_mouse_visible(False)
		self.window.set_exclusive_mouse(True)

		clock = pyglet.clock.Clock()
		fps_display = pyglet.clock.ClockDisplay()
		while not self.window.has_exit:
			self.window.dispatch_events()
			self.updateFrame()
			fps_display.draw()
			self.draw()
			self.window.flip()
			
			dt = clock.tick()

		print "fps:  %d" % clock.get_fps()
Example #31
0
def main():
	global win
	win = window.Window(width=640,height=480,visible=False)
	win.on_resize=resize
	win.on_key_press=on_key_press

	init()

	win.set_visible()
	clock=pyglet.clock.Clock()
	while not win.has_exit:
		win.dispatch_events()
		
		draw()
		win.flip()

		dt=clock.tick()
	print "fps:  %d" % clock.get_fps()
Example #32
0
    def run_window(self):
        self.win.set_visible()
        while not self.win.has_exit:
            self.win.dispatch_events()
            clock.tick()
            self.win.set_caption('Pytron v0.5 (fps: %s)' %
                                 (round(clock.get_fps())))

            glClear(GL_COLOR_BUFFER_BIT)
            glLoadIdentity()

            self.draw_header()
            self.draw_arena()

            self.run_once(True)

            self.draw_points()
            self.win.flip()
Example #33
0
    def test_compute_fps(self):
        """
        Test that the clock computes a reasonable value of
        frames per second when simulated for 10 ticks at 5 frames per second.

        Because sleep is not very precise and fps are unbounded, we
        expect a moderate error (10%) from the expected value.
        """
        ticks = 10  # for averaging
        expected_fps = 5
        seconds_per_tick = 1./expected_fps

        for i in range(ticks):
            time.sleep(seconds_per_tick)
            clock.tick()
        computed_fps = clock.get_fps()

        self.assertAlmostEqual(computed_fps, expected_fps, delta=0.1*expected_fps)
Example #34
0
def test_compute_fps():
    """
    Test that the clock computes a reasonable value of
    frames per second when simulated for 120 ticks at 60 frames per second.

    Because sleep is not very precise and fps are unbounded, we
    expect a moderate error (10%) from the expected value.
    """
    ticks = 120  # for averaging
    expected_fps = 60
    seconds_per_tick = 1. / expected_fps

    for i in range(ticks):
        time.sleep(seconds_per_tick)
        clock.tick()
    computed_fps = clock.get_fps()

    assert computed_fps == pytest.approx(expected_fps, rel=0.1 * expected_fps)
Example #35
0
def main():
    win = window.Window(width=640, height=480, visible=False)
    win.on_resize = resize

    init()

    win.set_visible()
    clock = pyglet.clock.Clock()

    while not win.has_exit:
        win.dispatch_events()

        draw()

        win.flip()
        clock.tick()

    print "fps:  %d" % clock.get_fps()
Example #36
0
	def run(self):
		self.window.set_visible()
		self.window.set_mouse_visible(False)
		self.window.set_exclusive_mouse(True)

		clock = pyglet.clock.Clock()
		fps_display = Label(x=0, y=0, anchor_y="top", font_size=14)
		while not self.window.has_exit:
			self.window.dispatch_events()
			self.updateFrame()
			fps_display.text = f"FPS: {pyglet.clock.get_fps()}"
			fps_display.draw()
			self.draw()
			self.window.flip()
			
			dt = clock.tick()

		print("fps:  %d" % clock.get_fps())
Example #37
0
    def on_draw(self):
        #TODO Cull objects outside zoom window
        self.counter += 1
        if self.counter == 60:
            self.counter = 0
            self.set_caption("OpenMelee Demo, FPS = " + str(int(clock.get_fps())))

        view = self.calcView()
        zoom, viewCenter = view

        glLoadIdentity()
        glMatrixMode(GL_PROJECTION)
        glLoadIdentity()
        
        left = -self.sizeX / zoom
        right = self.sizeX / zoom
        bottom = -self.sizeY / zoom
        top = self.sizeY / zoom
      
        gluOrtho2D(left, right, bottom, top)
        glTranslatef(-viewCenter.x, -viewCenter.y, 0)
        glMatrixMode(GL_MODELVIEW)
        glDisable(GL_DEPTH_TEST)
        glLoadIdentity()
        glClear(GL_COLOR_BUFFER_BIT)

        # Common to SDL and GL renderers:
        self.planet.draw(self.screen, view)

        for s in self.actors:
            if s:
                s.draw(self.screen, view)

        # Draw world bounding box
        c = 0.3, 0.9, 0.9
        ub = self.upperBound
        lb = self.lowerBound 
        verts = [Vec2d(lb.x, ub.y), Vec2d(lb.x, lb.y), 
                 Vec2d(ub.x, lb.y), Vec2d(ub.x, ub.y)]
        glColor3f(*c)
        glBegin(GL_LINE_LOOP)
        for v in verts:
            glVertex2f(v.x, v.y)
        glEnd()
Example #38
0
 def on_draw(self):
     self.clear() # clearing buffer
     clock.tick() # ticking the clock
     
     # showing FPS
     self.fpstext.text = "fps: %d" % clock.get_fps()
     self.fpstext.draw()
     
     self.score.text = '# Kills: %d' % self.spaceship.kills
     self.score.draw()
     
     self.spaceship.draw()
     for alien in self.aliens:
         alien.draw()
     for bullet in self.bullets:
         bullet.draw()
         
     # flipping
     self.flip()
Example #39
0
 def on_draw(self):
     self.clear() # clearing buffer
     clock.tick() # ticking the clock
     
     # showing FPS
     self.fpstext.text = "fps: %d" % clock.get_fps()
     self.fpstext.draw()
     
     self.score.text = '# Kills: %d' % self.spaceship.kills
     self.score.draw()
     
     self.spaceship.draw()
     for alien in self.aliens:
         alien.draw()
     for bullet in self.bullets:
         bullet.draw()
         
     # flipping
     self.flip()
Example #40
0
File: bww.py Project: msarch/py
	def draw(self):
		# Here we do all the drawing
		glClear(GL_COLOR_BUFFER_BIT |GL_DEPTH_BUFFER_BIT)
		glLoadIdentity()	
		glColor3f(0.5, 0.5, 1.0)	# set the color to sky-blue  
		#pyglet.gl.glColor4f(0.23,0.23,0.23,1.0) # gray
	
		for lmnt in drawing_list:
			lmnt.pygDraw()      # --- PYGLET OUTPUT
			print(lmnt)         # --- TEXT OUTPUT
			#obgeom.pdfy()      # --- PDF OUTPUT
			#obgeom.dxfy()      # --- DXF OUTPUT
			#obgeom.rhinofy()   # --- RHINO OUTPUT
			#obgeom.imagify()   # --- IMAGE OUTPUT
	
		# ... update and render ...
		print 'FPS is %f' % clock.get_fps()
		# The ``dt`` value returned gives the number of seconds (as a float) since the last "tick".
		# The `get_fps` function averages the framerate over a sliding window of approximately 1 second.
		# (You can calculate the instantaneous framerate bytaking the reciprocal of ``dt``).

		return pyglet.event.EVENT_HANDLED
Example #41
0
def main():
	global rtri,rquad
	win = window.Window(width=640,height=480,visible=False)
	win.on_resize=resize

	init()

	win.set_visible()
	clock=pyglet.clock.Clock()

	while not win.has_exit:
		win.dispatch_events()
		
		draw()

		win.flip()

		dt=clock.tick()
		rtri += 40*dt
		rquad+= 40*dt
	
	print "fps:  %d" % clock.get_fps()
Example #42
0
def main():
    global xrot, yrot, zrot, win
    win = window.Window(width=640, height=480, visible=False)
    win.on_resize = resize
    win.on_key_press = on_key_press

    init()

    win.set_visible()
    clock = pyglet.clock.Clock()

    while not win.has_exit:
        win.dispatch_events()

        draw()

        win.flip()

        dt = clock.tick()
        xrot += xspeed * dt
        yrot += yspeed * dt

    print "fps:  %d" % clock.get_fps()
Example #43
0
    def main_loop(self):
        clock.set_fps_limit(30)

        while not self.has_exit and not self._over:

            self.dispatch_events()
            self.update()
            self.clear()
            self.draw()

            # pymunk space update. updates position of all children.
            self.space.step(1/30.0)

            clock.tick()
            #Gets fps and draw it
            self.fps_label.text = "%d" % clock.get_fps()
            self.fps_label.draw()

            try:
                self.flip()
            except ctypes.ArgumentError:
                pass
        
        self._window_active = False
Example #44
0
	def main_loop(self):

		#Create a font for our FPS clock
		ft = font.load('Arial', 28)
		#The pyglet.font.Text object to display the FPS
		fps_text = font.Text(ft, y=10)

		#Schedule the Monster creation
		clock.schedule_interval(self.create_monster, 0.3)
		clock.set_fps_limit(30)

		while not self.has_exit:
			self.dispatch_events()
			self.clear()

			self.update()
			self.draw()

			#Tick the clock
			clock.tick()
			#Gets fps and draw it
			fps_text.text = ("fps: %d") % (clock.get_fps())
			fps_text.draw()
			self.flip()
Example #45
0
# -----------------------------------------------------------------------------

# 1 - Criação da janela de jogo
window = Window(width=game.SIZE[0], height=game.SIZE[1], resizable=True)
window.set_caption(game.TITLE + " - Initializing...")
window.set_mouse_visible(False)

# 2 - Instanciação do que for necessário (elementos globais)
music_player = SoundManager()  # Tocador de músicas
game.scene = SceneTitle()  # Cena inicial do jogo

# 3 - Definição das configurações principais
clock.set_fps_limit(game.FPS)
glEnable(GL_BLEND)  # Habilitar canal alpha #1
glBlendFunc(GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA)  # Habilitar canal alpha #2

# 4 - Definição do loop principal
while 1:
    pyglet.clock.tick()

    for window in pyglet.app.windows:
        window.switch_to()
        window.dispatch_events()
        game.scene.update()  # Atualização principal da cena atual do jogo
        window.dispatch_event('on_draw')
        window.flip()
        window.set_caption(game.TITLE + " - " + str(int(clock.get_fps())) +
                           " FPS")

    game.frame_count += 1
Example #46
0
                      subsequent_indent=indent))
    if style.parent:
        print_style(style.parent, '  ' + indent)


def print_element(element, indent=''):
    import textwrap
    print '\n'.join(
        textwrap.wrap(repr(element),
                      initial_indent=indent,
                      subsequent_indent=indent))
    if element.style_context:
        print_style(element.style_context, indent + '  ')
    for child in element.children:
        print_element(child, '  ' + indent)


glClearColor(1, 1, 1, 1)

window.set_visible()

while not window.has_exit:
    clock.tick()
    print 'FPS = %.2f\r' % clock.get_fps(),

    window.dispatch_events()
    glClear(GL_COLOR_BUFFER_BIT)
    layout.draw()

    window.flip()
Example #47
0
 def test_start_at_zero_fps(self):
     """
     Tests that the default clock starts
     with zero fps.
     """
     self.assertTrue(clock.get_fps() == 0)
Example #48
0
 def test_start_at_zero_fps(self):
     """
     Tests that the default clock starts
     with zero fps.
     """
     self.assertTrue(clock.get_fps() == 0)
sprites = []
numsprites = int(sys.argv[1])
for i in range(numsprites):
    x = random.randint(0, w.width - img.width)
    y = random.randint(0, w.height - img.height)
    s = BouncySprite(x, y, img.width, img.height, img)
    s.dx = random.randint(-10, 10)
    s.dy = random.randint(-10, 10)
    sprites.append(s)

view = FlatView.from_window(w, sprites=sprites)
view.fx, view.fy = w.width / 2, w.height / 2

t = 0
numframes = 0
while 1:
    if w.has_exit:
        print 'FPS:', clock.get_fps()
        print 'us per sprite:', float(t) / (numsprites * numframes) * 1000000

        break
    t += clock.tick()
    w.dispatch_events()
    for s in sprites:
        s.update()
    view.clear()
    view.draw()
    w.flip()
    numframes += 1
w.close()
Example #50
0
File: 2.py Project: rosedu/hfall
            y = H(X + s_size, Y + s_size)
            z = Y + s_size
            SetVertexColor(x, z)
            glVertex3i(x, y, z)

            x = X + s_size
            y = H(X + s_size, Y)
            z = Y
            SetVertexColor(x, z)
            glVertex3i(x, y, z)
            
    glEnd()

def draw():
    glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT)
    glLoadIdentity()

    gluLookAt(21, 16, 19, 0, 0, 0, 0, 1, 0)
    #glScalef()

    renderHM()

setup()
while not w.has_exit:
    dt = clock.tick()
    w.dispatch_events()
    draw()
    fps = clock.get_fps()
    print fps,
    w.flip()
Example #51
0
numsprites = int(sys.argv[1])
for i in range(numsprites):
    x = random.randint(0, w.width-img.width)
    y = random.randint(0, w.height-img.height)
    s = BouncySprite(x, y, img.width, img.height, img)
    s.dx = random.randint(-10, 10)
    s.dy = random.randint(-10, 10)
    sprites.append(s)

view = FlatView.from_window(w, sprites=sprites)
view.fx, view.fy = w.width/2, w.height/2

t = 0
numframes = 0
while 1:
    if w.has_exit:
        print 'FPS:', clock.get_fps()
        print 'us per sprite:', float(t) / (numsprites * numframes) * 1000000

        break
    t += clock.tick()
    w.dispatch_events()
    for s in sprites: s.update()
    view.clear()
    view.draw()
    w.flip()
    numframes += 1
w.close()


 def draw(self):
     glMatrixMode(GL_MODELVIEW)
     glLoadIdentity()
     self.fpsLabel.text = ("%.1f" % clock.get_fps())
     self.fpsLabel.draw()
Example #53
0
 def fps(self):
     return 'FPS: %i' % clock.get_fps()
Example #54
0
    global grid
    grid[(y-10)/10][(x-10)/10] = (int(button==mouse.LEFT),0)
win.on_mouse_drag = on_mouse_drag



# empty zero-filled grid
grid = [[(0,0)]*50 for i in range(50)]


while not win.has_exit:
    win.dispatch_events()
    dt = clock.tick()
    
    # set title framerate
    if drawing:
        win.set_caption('Game of Life 2d - drawing')
    else:
        win.set_caption('Game of Life 2d - evolutions per second: %s' % round(clock.get_fps()))

    # clear
    glClear(GL_COLOR_BUFFER_BIT)
    glLoadIdentity()
    
    draw_header()
    draw_arena()
    if evolving and not drawing and not show_help: evolve_grid()
    draw_grid()
    if show_help: draw_help()

    win.flip()
Example #55
0
    def main_loop(self):
        self.collision_engine = CollisionEngine()
        ft = font.load('Arial', 28)
        fps_text = font.Text(ft, y=10)


        #for i in self.scene_objects:
        #count =30    
        
        while not self.has_exit:   
            self.scene_objects[0].setRotation(10)
            #self.scene_objects[0].setRotation(20)
            #self.scene_objects[0].setRotation(30)
            #self.scene_objects[0].setRotation(90)
            #self.scene_objects[0].setRotation(100)
            #count =20
            #if count >2:count=0
            self.dispatch_events()
            self.clear()
            #pyglet.gl.glColor4f(1.0,0,0,1.0)       
            glBlendFunc (GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA)                             
            glEnable (GL_BLEND)                                                            
            #glEnable (GL_LINE_SMOOTH);                                                     
            glHint (GL_LINE_SMOOTH_HINT, GL_DONT_CARE)                                     
            glLineWidth (1)

            self.scene_objects[0].setPosition(self.mouse_position)
                        


            collisions = self.collision_engine.processCollisions(self.scene_objects)

            
            ######Deal with collisions#######
            for i in collisions:
                pass
                print i[0].name + " hit "+i[1].name                
                #i[1].positions.pop()                
                #i[1].setPosition(i[1].positions[1]) 


            debug = True
            debug = False
 
            for i in self.scene_objects:
                if debug == False:
                    #i.setRotation(45)
                    
                    i.getSprite().draw()
                if debug == False:
                    glDisable(GL_TEXTURE_2D)

                    for j in i.getCollisionTriangles():                                           
                        pyglet.gl.glColor4f(1.0,0,0,1.0)
                        pyglet.graphics.draw(2, pyglet.gl.GL_LINES,('v2i', (j[0][0]+i.pos[0],j[0][1]+i.pos[1],j[1][0]+i.pos[0],j[1][1]+i.pos[1])))
                        pyglet.graphics.draw(2, pyglet.gl.GL_LINES,('v2i', (j[1][0]+i.pos[0],j[1][1]+i.pos[1],j[2][0]+i.pos[0],j[2][1]+i.pos[1])))
                        pyglet.graphics.draw(2, pyglet.gl.GL_LINES,('v2i', (j[2][0]+i.pos[0],j[2][1]+i.pos[1],j[0][0]+i.pos[0],j[0][1]+i.pos[1])))
                    #draw bounding rectangle            
                    pyglet.gl.glColor4f(1.0,1.0,0,1.0)
                    pyglet.graphics.draw(2, pyglet.gl.GL_LINES,('v2i', (i.top_right[0]+i.pos[0],i.top_right[1]+i.pos[1],i.bottom_left[0]+i.pos[0],i.top_right[1]+i.pos[1])))
                    pyglet.graphics.draw(2, pyglet.gl.GL_LINES,('v2i', (i.top_right[0]+i.pos[0],i.top_right[1]+i.pos[1],i.top_right[0]+i.pos[0],i.bottom_left[1]+i.pos[1])))
                    pyglet.graphics.draw(2, pyglet.gl.GL_LINES,('v2i', (i.bottom_left[0]+i.pos[0],i.bottom_left[1]+i.pos[1],i.top_right[0]+i.pos[0],i.bottom_left[1]+i.pos[1])))
                    pyglet.graphics.draw(2, pyglet.gl.GL_LINES,('v2i', (i.bottom_left[0]+i.pos[0],i.bottom_left[1]+i.pos[1],i.bottom_left[0]+i.pos[0],i.top_right[1]+i.pos[1])))
                    glEnable(GL_TEXTURE_2D)
            

            clock.tick()
            fps_text.text = ("fps: %d") % (clock.get_fps())
            fps_text.draw()
            self.flip()