Ejemplo n.º 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")
 def create_screen(self):
     if constants.USE_RSDL:
         self.screen = RSDL.SetVideoMode(self.width*self.scale, self.height*self.scale, 32, 0)
         fmt = self.screen.c_format
         self.colors = []
         for color in self.COLOR_MAP:
             color = RSDL.MapRGB(fmt, *color)
             self.colors.append(color)
         self.blit_rect = RSDL_helper.mallocrect(0, 0, self.scale, self.scale)
Ejemplo n.º 3
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
Ejemplo n.º 4
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
Ejemplo n.º 5
0
    def __init__(self):
        start = float(time.time())
        self._neurons = []
        self._columns = []
        self._layers = [[]] * LAYERS
        self._pulse_layers = [0] * LAYERS
        self._pulse_layers[0] = 1

        self._pulse_columns = [0] * COLUMNS
        self._pulse_columns[0] = 1
        self._pulse_columns[1] = 1
        self._pulse_columns[2] = 1
        self._pulse_columns[3] = 1

        inc = 360.0 / COLUMNS
        scale = float(LAYERS)
        expansion = 1.333
        linc = scale / LAYERS
        for column in range(COLUMNS):
            colNeurons = []
            self._columns.append(colNeurons)
            X = math.sin(radians(column * inc))
            Y = math.cos(radians(column * inc))
            expanding = STEM
            width = 1.0 / scale
            for layer in range(LAYERS):
                Z = layer * linc
                r = random() * random()
                g = 0.2
                b = 0.2
                for i in range(int(expanding)):
                    x = uniform(-width, width)
                    rr = random() * random()  # DJ's trick
                    y = uniform(-width * rr, width * rr) + X
                    z = Z + Y
                    # create 50/50 exitatory/inhibitory
                    n = RecurrentSpikingModel(x=x,
                                              y=y,
                                              z=z,
                                              column=column,
                                              layer=layer,
                                              red=r,
                                              green=g,
                                              blue=b)
                    self._neurons.append(n)
                    colNeurons.append(n)
                    self._layers[layer].append(n)

                expanding *= expansion
                width *= expansion

        dendrites = 0
        interlayer = 0
        for lay in self._layers:
            for a in lay:
                for b in lay:
                    if a is not b and a._column == b._column:
                        a.attach_dendrite(b)
                        dendrites += 1
                        interlayer += 1

        intercol = 0
        for col in self._columns:
            for a in col:
                for b in col:
                    if a is not b and random() * random() > 0.75:
                        a.attach_dendrite(b)
                        intercol += 1
                        dendrites += 1

        intercore = 0
        core = self._layers[-1]
        for a in core:
            for b in core:
                if a is not b and random() * random() > 0.85:
                    a.attach_dendrite(b)
                    intercore += 1
                    dendrites += 1

        print 'brain creation time (seconds)', float(time.time()) - start
        print 'neurons per column', len(self._columns[0])
        print 'inter-layer dendrites', interlayer
        print 'inter-column dendrites', intercol
        print 'inter-neocoretex dendrites', intercore
        print 'total dendrites', dendrites
        print 'total neurons', len(self._neurons)
        for i, lay in enumerate(self._layers):
            print 'layer: %s	neurons: %s' % (i, len(lay))
        for i, col in enumerate(self._columns):
            print 'column: %s	neurons: %s' % (i, len(col))

        self._stdin = streamio.fdopen_as_stream(0, 'r', 1)
        #self._stdout = streamio.fdopen_as_stream(1, 'w', 1)
        #self._stderr = streamio.fdopen_as_stream(2, 'w', 1)

        self._width = 640
        self._height = 480
        assert RSDL.Init(RSDL.INIT_VIDEO) >= 0
        self.screen = RSDL.SetVideoMode(self._width, self._height, 32, 0)
        assert self.screen
        fmt = self.screen.c_format
        self.ColorWhite = white = RSDL.MapRGB(fmt, 255, 255, 255)
        self.ColorGrey = grey = RSDL.MapRGB(fmt, 128, 128, 128)
        self.ColorBlack = black = RSDL.MapRGB(fmt, 0, 0, 0)
        self.ColorBlue = blue = RSDL.MapRGB(fmt, 0, 0, 200)

        colors = {'white': white, 'grey': grey, 'black': black, 'blue': blue}

        x = 1
        y = 1
        for i, n in enumerate(self._neurons):
            braneRect = RSDL_helper.mallocrect(x, y, 12, 12)
            groupRect = RSDL_helper.mallocrect(x, y, 12, 2)
            spikeRect = RSDL_helper.mallocrect(x + 4, y + 4, 4, 4)
            n.setup_draw(self.screen.c_format, braneRect, groupRect, spikeRect,
                         colors)
            x += 13
            if x >= self._width - 14:
                x = 1
                y += 13
	def __init__(self):
		start = float(time.time())
		self._neurons = []
		self._columns = []
		self._layers = [ [] ] * LAYERS
		self._pulse_layers = [0] * LAYERS
		self._pulse_layers[ 0 ] = 1

		self._pulse_columns = [0] * COLUMNS
		self._pulse_columns[ 0 ] = 1
		self._pulse_columns[ 1 ] = 1
		self._pulse_columns[ 2 ] = 1
		self._pulse_columns[ 3 ] = 1


		inc = 360.0 / COLUMNS
		scale = float( LAYERS )
		expansion = 1.333
		linc = scale / LAYERS
		for column in range(COLUMNS):
			colNeurons = []
			self._columns.append( colNeurons )
			X = math.sin( radians(column*inc) )
			Y = math.cos( radians(column*inc) )
			expanding = STEM
			width = 1.0 / scale
			for layer in range(LAYERS):
				Z = layer * linc
				r = random() * random()
				g = 0.2
				b = 0.2
				for i in range(int(expanding)):
					x = uniform( -width, width )
					rr = random()*random()		# DJ's trick
					y = uniform( -width*rr, width*rr ) + X
					z = Z + Y
					# create 50/50 exitatory/inhibitory
					n = RecurrentSpikingModel(x=x, y=y, z=z, column=column, layer=layer, red=r, green=g, blue=b )
					self._neurons.append( n )
					colNeurons.append( n )
					self._layers[ layer ].append( n )

				expanding *= expansion
				width *= expansion

		dendrites = 0
		interlayer = 0
		for lay in self._layers:
			for a in lay:
				for b in lay:
					if a is not b and a._column == b._column:
						a.attach_dendrite( b )
						dendrites += 1
						interlayer += 1

		intercol = 0
		for col in self._columns:
			for a in col:
				for b in col:
					if a is not b and random()*random() > 0.75:
						a.attach_dendrite( b )
						intercol += 1
						dendrites += 1

		intercore = 0
		core = self._layers[-1]
		for a in core:
			for b in core:
				if a is not b and random()*random() > 0.85:
					a.attach_dendrite( b )
					intercore += 1
					dendrites += 1

		print 'brain creation time (seconds)', float(time.time())-start
		print 'neurons per column', len(self._columns[0])
		print 'inter-layer dendrites', interlayer
		print 'inter-column dendrites', intercol
		print 'inter-neocoretex dendrites', intercore
		print 'total dendrites', dendrites
		print 'total neurons', len(self._neurons)
		for i,lay in enumerate(self._layers):
			print 'layer: %s	neurons: %s' %(i,len(lay))
		for i,col in enumerate(self._columns):
			print 'column: %s	neurons: %s' %(i,len(col))



		self._stdin = streamio.fdopen_as_stream(0, 'r', 1)
		#self._stdout = streamio.fdopen_as_stream(1, 'w', 1)
		#self._stderr = streamio.fdopen_as_stream(2, 'w', 1)

		self._width = 640; self._height = 480
		assert RSDL.Init(RSDL.INIT_VIDEO) >= 0
		self.screen = RSDL.SetVideoMode(self._width, self._height, 32, 0)
		assert self.screen
		fmt = self.screen.c_format
		self.ColorWhite = white = RSDL.MapRGB(fmt, 255, 255, 255)
		self.ColorGrey = grey = RSDL.MapRGB(fmt, 128, 128, 128)
		self.ColorBlack = black = RSDL.MapRGB(fmt, 0, 0, 0)
		self.ColorBlue = blue = RSDL.MapRGB(fmt, 0, 0, 200)

		colors = {'white':white, 'grey':grey, 'black':black, 'blue':blue}

		x = 1; y = 1
		for i,n in enumerate(self._neurons):
			braneRect = RSDL_helper.mallocrect(x, y, 12, 12)
			groupRect = RSDL_helper.mallocrect(x, y, 12, 2)
			spikeRect = RSDL_helper.mallocrect(x+4, y+4, 4, 4)
			n.setup_draw( self.screen.c_format, braneRect, groupRect, spikeRect, colors )
			x += 13
			if x >= self._width-14:
				x = 1
				y += 13