Beispiel #1
0
    def test_blit_rect(self):
        surface = RSDL.CreateRGBSurface(0, 150, 50, 32,
                                        r_uint(0x000000FF),
                                        r_uint(0x0000FF00),
                                        r_uint(0x00FF0000),
                                        r_uint(0xFF000000))
        fmt = surface.c_format
        color = RSDL.MapRGB(fmt, 255, 0, 0)
        RSDL.FillRect(surface, lltype.nullptr(RSDL.Rect), color)
        
        paintrect = RSDL_helper.mallocrect(75, 0, 150, 50)
        dstrect = lltype.malloc(RSDL.Rect, flavor='raw')
        try:
            color = RSDL.MapRGB(fmt, 255, 128, 0)
            RSDL.FillRect(surface, paintrect, color)

            rffi.setintfield(dstrect, 'c_x',  10)
            rffi.setintfield(dstrect, 'c_y',  10)
            rffi.setintfield(dstrect, 'c_w', 150)
            rffi.setintfield(dstrect, 'c_h',  50)
            RSDL.BlitSurface(surface, lltype.nullptr(RSDL.Rect), self.screen, dstrect)
            RSDL.Flip(self.screen)
        finally:
            lltype.free(dstrect, flavor='raw')
            lltype.free(paintrect, flavor='raw')
        RSDL.FreeSurface(surface)
        self.check("Half Red/Orange rectangle(150px * 50px) at the top left, 10 pixels from the border")
Beispiel #2
0
 def draw(self, surf):
     #if self._braneRect:
     fmt = surf.c_format
     b = int(self._brane * 6)
     if b > 255: b = 255
     elif b < 0: b = 0
     color = RSDL.MapRGB(fmt, 0, 0, b)
     RSDL.FillRect(surf, self._braneRect, color)
     RSDL.FillRect(surf, self._groupRect, self._group_color)
     if self._draw_spike:
         RSDL.FillRect(surf, self._spikeRect, self._sdl_colors['white'])
     else:
         RSDL.FillRect(surf, self._spikeRect,
                       color)  #self._sdl_colors['black'])
     self._draw_spike = False
Beispiel #3
0
 def test_fillrect_full(self):
     fmt = self.screen.c_format
     for colorname, r, g, b in [('dark red', 128, 0, 0),
                                ('yellow', 255, 255, 0),
                                ('blue', 0, 0, 255)]:
         color = RSDL.MapRGB(fmt, r, g, b)
         RSDL.FillRect(self.screen, lltype.nullptr(RSDL.Rect), color)
         RSDL.Flip(self.screen)
         self.check("Screen filled with %s" % colorname)
Beispiel #4
0
 def setup_method(self, meth):
     self.dst_surf = RSDL.CreateRGBSurface(0, 300, 300, 32,
                                           r_uint(0x000000FF),
                                           r_uint(0x0000FF00),
                                           r_uint(0x00FF0000),
                                           r_uint(0x00000000))
     self.src_surf = RSDL.CreateRGBSurface(0, 50, 50, 32,
                                           r_uint(0x000000FF),
                                           r_uint(0x0000FF00),
                                           r_uint(0x00FF0000),
                                           r_uint(0x00000000))
     fmt = self.src_surf.c_format
     self.black = RSDL.MapRGB(fmt, 0, 0, 0)
     self.red = RSDL.MapRGB(fmt, 255, 0, 0)
     self.blue = RSDL.MapRGB(fmt, 0, 0, 255)
     RSDL.FillRect(self.src_surf, lltype.nullptr(RSDL.Rect), self.red)
Beispiel #5
0
    def test_set_color_key(self):
        # prepare
        fillrect = RSDL_helper.mallocrect(10, 10, 30, 30)
        RSDL.FillRect(self.src_surf, fillrect, self.blue)
        lltype.free(fillrect, flavor='raw')
        assert RSDL.SetColorKey(self.src_surf, RSDL.SRCCOLORKEY,
                                self.blue) == 0

        # draw
        RSDL_helper.blit_complete_surface(self.src_surf, self.dst_surf, 0, 0)

        # check
        for position, color in (((0, 0), self.red), ((10, 10), self.black),
                                ((20, 20), self.black), ((40, 40), self.red)):
            fetched_color = RSDL_helper.get_pixel(self.dst_surf, position[0],
                                                  position[1])
            assert fetched_color == color
Beispiel #6
0
 def loop(self):
     self._active = True
     fmt = self.screen.c_format
     RSDL.FillRect(self.screen, lltype.nullptr(RSDL.Rect), self.ColorGrey)
     layers = self._layers
     neurons = self._neurons
     pulse_layers = self._pulse_layers
     screen = self.screen
     loops = 0
     now = start = float(time.time())
     while self._active:
         #Bjitdriver.can_enter_jit( layers=layers, neurons=neurons, pulse_layers=pulse_layers, loops=loops )
         #Bjitdriver.jit_merge_point( layers=layers, neurons=neurons, pulse_layers=pulse_layers, loops=loops)
         now = float(time.time())
         self._fps = loops / float(now - start)
         for i, lay in enumerate(self._layers):
             if self._pulse_layers[i] and False:
                 #print 'pulse layer: %s neurons: %s ' %(i, len(lay))
                 for n in lay:
                     if random() * random() > 0.8:
                         n.spike(now)
         for i, col in enumerate(self._columns):
             if self._pulse_columns[i]:
                 for n in col:
                     n.spike(now)
         for n in self._neurons:
             n.iterate()
             n.draw(self.screen)
         #r,w,x = rpoll.select( [self._stdin], [], [], 1 )	# wait
         rl, wl, xl = rpoll.select([0], [], [], 0.000001)  # wait
         if rl:
             cmd = self._stdin.readline().strip('\n').strip(' ')
             self.do_command(cmd)
         loops += 1
         self._iterations = loops
         #print loops		# can not always print in mainloop, then select can never read from stdin
         RSDL.Flip(self.screen)
         #self._fps = float(time.time()) - now
     #return loops
     return 0