示例#1
0
 def setup_method(self, meth):
     if not conftest.option.view:
         py.test.skip("'--view' not specified, "
                      "skipping tests that open a window")
     assert RSDL.Init(RSDL.INIT_VIDEO) >= 0
     self.screen = RSDL.SetVideoMode(640, 480, 32, 0)
     assert self.screen
     self.is_interactive = sys.stdout.isatty()
示例#2
0
def test_surface_basic():
    assert RSDL.Init(RSDL.INIT_VIDEO) >= 0
    surface = RSDL.CreateRGBSurface(0, 150, 50, 32, r_uint(0x000000FF),
                                    r_uint(0x0000FF00), r_uint(0x00FF0000),
                                    r_uint(0xFF000000))
    assert surface
    assert rffi.getintfield(surface, 'c_w') == 150
    assert rffi.getintfield(surface, 'c_h') == 50
    RSDL.FreeSurface(surface)
    RSDL.Quit()
示例#3
0
def entry_point(argv=None):
    RSDL.Init(RSDL.INIT_VIDEO) >= 0
    screen = RSDL.SetVideoMode(WIDTH, HEIGHT, 32, 0)
    event = lltype.malloc(RSDL.Event, flavor='raw')
    paintpattern = 0
    try:
        while True:
            ok = RSDL.WaitEvent(event)
            assert rffi.cast(lltype.Signed, ok) == 1
            c_type = rffi.getintfield(event, 'c_type')
            if c_type == RSDL.KEYDOWN:
                p = rffi.cast(RSDL.KeyboardEventPtr, event)
                if rffi.getintfield(p.c_keysym, 'c_sym') == RSDL.K_ESCAPE:
                    print 'Escape key'
                    break
            paintpattern += 1
            update_screen(screen, paintpattern)
    finally:
        lltype.free(event, flavor='raw')

    return 0
示例#4
0
def test_sdl_init():
    assert RSDL.Init(RSDL.INIT_VIDEO) >= 0
    RSDL.Quit()
示例#5
0
def test_delay_getticks():
    assert RSDL.Init(RSDL.INIT_VIDEO) >= 0
    RSDL.Delay(10)
    i = RSDL.GetTicks()
    assert i >= 10
    RSDL.Quit()
示例#6
0
def test_get_keyname():
    assert RSDL.Init(RSDL.INIT_VIDEO) >= 0
    assert RSDL.GetKeyName(RSDL.K_PLUS)[0] == '+'
    assert RSDL.GetKeyName(RSDL.K_RIGHTPAREN)[0] == ')'
    assert RSDL.GetKeyName(RSDL.K_z)[0] == 'z'
示例#7
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
示例#8
0
 def init_sdl(self):
     assert RSDL.Init(RSDL.INIT_VIDEO) >= 0
     self.event = lltype.malloc(RSDL.Event, flavor='raw')