Example #1
0
from smile.state import Parallel, Wait, Serial, Meanwhile, Loop, Debug
from smile.audio import Beep, SoundFile, init_audio_server
import os

init_audio_server(sr=44100,
                  nchnls=1,
                  buffersize=256,
                  duplex=1,
                  audio='portaudio',
                  jackname='pyo',
                  input_device=None,
                  output_device=None)

exp = Experiment(debug=True)

Wait(1.0)
with Loop([440, 500, 600, 880]) as l:
    Beep(freq=l.current, volume=0.4, duration=1.0)
    Debug(freq=l.current)
Beep(freq=[440, 500, 600], volume=0.1, duration=1.0)
Debug(freq=[440, 500, 600])

Beep(freq=880, volume=0.1, duration=1.0)
Debug(freq=880)

with Parallel():
    Beep(freq=440, volume=0.1, duration=2.0)
    Debug(freq=440)

    with Serial():
        Wait(1.0)
Example #2
0
from smile.mouse import MouseRecord, MouseCursor, MousePress, MouseWithin
from smile.video import Label


def print_dt(state, *args):
    print(args)


exp = Experiment(show_splash=True)

with Parallel():
    MouseRecord()
    MouseCursor()
with UntilDone():
    Wait(2.0)
    MouseCursor("smile/face-smile.png", (125, 125), duration=5.0)

    with Parallel():
        lbl1 = Label(text="Click me", blocking=False)
        with Loop(10):
            Debug(mw=MouseWithin(lbl1))
            Wait(1.0)

    Debug(name='Mouse Press Test')

    exp.last_pressed = ''

    with Loop(conditional=(exp.last_pressed != 'RIGHT')):
        kp = MousePress(buttons=['LEFT', 'RIGHT'], correct_resp='RIGHT')
        Debug(pressed=kp.pressed, rt=kp.rt, correct=kp.correct)
Example #3
0
                envelope='Circular',
                std_dev=7.5,
                contrast=0.75,
                color_one='green',
                color_two='orange')
    lbl = Label(text='Grating!', bottom=g.top)
with UntilDone():
    # kp = KeyPress()
    with Parallel():
        g.slide(phase=-8 * math.pi,
                frequency=10.,
                bottom=exp.screen.bottom,
                duration=6.)
        g.slide(rotate=90, duration=2.0)
        with Serial():
            Wait(2.0)
            lbl.slide(top=g.bottom, duration=4.)

with Parallel():
    g = Grating(width=1000,
                height=1000,
                frequency=10,
                envelope='Linear',
                std_dev=20,
                contrast=0.4,
                color_one='blue',
                color_two='red')
    lbl = Label(text='Grating!', bottom=g.top)
with UntilDone():
    kp = KeyPress()
    with Parallel():
Example #4
0
from smile.experiment import Experiment
from smile.state import Wait, Debug
from smile.video import Label
from smile.freekey import FreeKey

exp = Experiment()

Wait(.5)

fk = FreeKey(Label(text='XXXXXX', font_size=40), max_resp=1)
Debug(responses=fk.responses)

Label(text='Done', font_size=32, duration=2.0)

fk2 = FreeKey(Label(text='??????', font_size=30))
Debug(responses=fk2.responses)

Wait(1.0)

exp.run()
Example #5
0
Debug(width=exp.screen.width, height=exp.screen.height)

with Loop(5) as loop:
    Log(a=1, b=2, c=loop.i, name="aaa")
Log({"q": loop.i, "w": loop.i}, x=4, y=2, z=1, name="bbb")
Log([{"q": loop.i, "w": n} for n in range(5)], x=4, y=2, z=1, name="ccc")

exp.for_the_thing = 3
dtt = DoTheThing(3, 4, name="first")
Debug(foo=dtt.foo, name="outside DoTheThing")
dtt = DoTheThing(3, 4, d="bbbbbbb", c=exp.for_the_thing)
Debug(foo=dtt.foo, name="outside DoTheThing")

with DoTheOtherThing():
    PrintTraceback(name="top of body")
    Wait(2.0)
    PrintTraceback(name="bottom of body")

Wait(1.0)
dvt = _DelayedValueTest(1.0, 42)
Done(dvt)
Debug(dvt_out=dvt.value_out)

exp.bar = False
with Parallel():
    with Serial():
        Wait(2.0)
        # force variable assignment
        # to wait until correct time
        Func(lambda: None)
        exp.bar = True
Example #6
0
def DoTheThing(self, a, b, c=7, d="ssdfsd"):
    PrintTraceback(name="inside DoTheThing")
    self.foo = c * 2
    Wait(1.0)
    Debug(a=a, b=b, c=c, d=d, foo=self.foo,
          screen_size=self.exp.screen.size, name="inside DoTheThing")
Example #7
0
from smile.experiment import Experiment
from smile.state import Debug, Wait, Log, Loop
from smile.pulse import Pulse

# set up default experiment
exp = Experiment()

with Loop(15):
    pulse = Pulse(code='S1')
    Wait(duration=1.0, jitter=1.0)
    Log(name='pulse',
        pulse_on=pulse.pulse_on,
        pulse_code=pulse.code,
        pulse_off=pulse.pulse_off)

# print something
Debug(width=exp.screen.width, height=exp.screen.height)

# run the exp
exp.run(trace=False)
Example #8
0
                  chan_path='Dev1/ao1',
                  chan_des="mychan2")

NIPulse(
    task1,
    push_vals=[1.0],
    width=0.10,
)
NIPulse(
    task2,
    push_vals=[.5],
    width=0.10,
)

# Wait for the experiment to start!
Wait(2.)

with Parallel():

    Label(text="We will now push 10 markers.", blocking=False)
    with Loop(10, blocking=False):

        ni1 = NIPulse(
            task1,
            push_vals=[1.0],
            width=0.10,
        )
        Wait(1.0)
        ni2 = NIPulse(
            task2,
            push_vals=[.5],
Example #9
0
from smile.experiment import Experiment
from smile.state import Wait, Debug, Loop, UntilDone, Log, Meanwhile
from smile.keyboard import Key, KeyRecord, KeyPress


exp = Experiment()

with Meanwhile():
    KeyRecord(name="record_all_key_presses")

Debug(name='Press T+G+D or SHIFT+Q+R')
Wait(until=((Key("T") & Key("G") & Key("D")) |
            (Key("SHIFT") & Key("Q") & Key("R"))))
Debug(name='Key Press Test')

exp.last_pressed = ''

with Loop(conditional=(exp.last_pressed != 'K')):
    kp = KeyPress(keys=['J', 'K'], correct_resp='K')
    Debug(pressed=kp.pressed, rt=kp.rt, correct=kp.correct)
    exp.last_pressed = kp.pressed
    Log(pressed=kp.pressed, rt=kp.rt)

KeyRecord()
with UntilDone():
    kp = KeyPress(keys=['J', 'K'], correct_resp='K')
    Debug(pressed=kp.pressed, rt=kp.rt, correct=kp.correct)
    Wait(1.0)

    kp = KeyPress()
    Debug(pressed=kp.pressed, rt=kp.rt, correct=kp.correct)
Example #10
0
from smile.experiment import Experiment
from smile.state import Wait, Parallel, Loop
from smile.video import Label
from smile.socket_interface import init_socket_outlet, SocketPush
# Initialize the outlet
OUTLET = init_socket_outlet(uniq_ID='SocketMarket',
                            server='localhost',
                            port=1234)

exp = Experiment()

# Signal the beginning of the experiment.
SocketPush(socket=OUTLET, msg="<TRIGGER>300</TRIGGER>")

# Wait for the experiment to start!
Wait(2.)

with Parallel():

    Label(text="We will now push 10 markers.", blocking=False)
    with Loop(10, blocking=False):

        # Create the push state
        push_out = SocketPush(socket=OUTLET, msg="<TRIGGER>55</TRIGGER>")

        # Log send_time if you want easy access
        # Log(name="MARKERS",
        #     push_time=push_out.send_time)

        Wait(1.)
Example #11
0
                   "coherence": 0.5,
                   "direction": 0,
                   "direction_variance": 0,
                   "speed": 50,
                   "lifespan": .6,
                   "lifespan_variance": .5
               }, {
                   "coherence": 0.1,
                   "direction": 180,
                   "direction_variance": 10,
                   "speed": 400,
                   "speed_variance": 200
               }]]
exp = Experiment(background_color=("purple", .3))

Wait(.5)

g = MovingDots(radius=300,
               scale=10,
               num_dots=4,
               motion_props=[{
                   "coherence": 0.25,
                   "direction": 0,
                   "direction_variance": 0
               }, {
                   "coherence": 0.25,
                   "direction": 90,
                   "direction_variance": 0
               }, {
                   "coherence": 0.25,
                   "direction": 180,