示例#1
0
def main():
    wdth = 1024
    hght = 768
    flds = ['Intensity','Luminance']
    args = prsr.parse_args()
    flnm = 'results/' + args.flnm

    hrl = HRL(wdth,hght,0,coords=(0,1,0,1),flipcoords=False,dpx=True,ocal=True,rfl=flnm,rhds=flds,fs=True)
    # Initializations

    ptch = hrl.newTexture(np.array([[args.lm]]))
    pwdth,phght = wdth*args.sz,hght*args.sz
    ppos = ((wdth - pwdth)/2,(hght - phght)/2)

    if args.rnd: rnd = round
    else: rnd = lambda x: x

    nitss = int(args.tmprs/args.bfrq)
    itss = [ args.bamp * rnd((1 + np.sin(2*np.pi*x)) / 2) + ((1-args.bamp)/2)
            for x in np.linspace(0,1,nitss) ]
    tsts = [ n % (nitss / args.sfrq) == 0 for n in range(nitss) ]
    cycl = zip(itss,tsts)
    slptm = int(1000.0 / args.tmprs)

    def opticalRead(its):
        print 'Current Intensity:', its
        lm = hrl.readLuminance(1,0)
        hrl.rmtx['Intensity'] = its
        hrl.rmtx['Luminance'] = lm
        hrl.writeResultLine()

    for (its,tst) in cycl * args.ncyc:

        hrl.changeBackground(its)
        ptch.draw(ppos,(pwdth,phght))
        hrl.flip()

        pg.time.wait(slptm)

        if tst:
            prcs = Process(target=opticalRead,args=(its,))
            prcs.start()

        if hrl.checkEscape(): break

    # Experiment is over!
    hrl.close