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 update_screen(screen, paintpattern): fmt = screen.c_format white = RSDL.MapRGB(fmt, 255, 255, 255) black = RSDL.MapRGB(fmt, 0, 0, 0) RSDL.LockSurface(screen) pattern[paintpattern % pl](screen, black, white) RSDL.UnlockSurface(screen) RSDL.Flip(screen) RSDL.Delay(10)
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)
def test_bit_pattern(self): HEIGHT = WIDTH = 10 fmt = self.screen.c_format white = RSDL.MapRGB(fmt, 255, 255, 255) black = RSDL.MapRGB(fmt, 0, 0, 0) RSDL.LockSurface(self.screen) for i in xrange(WIDTH): for j in xrange(HEIGHT): k = j*WIDTH + i if k % 2: c = white else: c = black RSDL_helper.set_pixel(self.screen, i, j, c) RSDL.UnlockSurface(self.screen) RSDL.Flip(self.screen) self.check("Upper left corner 10x10 field with vertical black/white stripes")
def setup_draw(self, format, braneRect, groupRect, spikeRect, colors): self._braneRect = braneRect self._groupRect = groupRect self._spikeRect = spikeRect self._sdl_colors = colors r, g, b = self._color self._group_color = RSDL.MapRGB(format, int(r * 255), int(g * 255), int(b * 255))
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)
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
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