|
| 1 | +from smile.common import * |
| 2 | +from smile.scale import scale as s |
| 3 | + |
| 4 | + |
| 5 | +@Subroutine |
| 6 | +def HappyQuest(self, config): |
| 7 | + with Parallel(): |
| 8 | + Label(text="How happy are you at this moment?\nPress F to move left, Press J to move right.", |
| 9 | + font_size=s(config.INST_FONT_SIZE), |
| 10 | + halign='center', |
| 11 | + center_y=exp.screen.center_y + s(300)) |
| 12 | + sld = Slider(min=-10, max=10, value=0, width=s(config.SLIDER_WIDTH)) |
| 13 | + Label(text="unhappy", font_size=s(config.INST_FONT_SIZE), |
| 14 | + center_x=sld.left, center_y=sld.center_y - s(100)) |
| 15 | + Label(text="happy", font_size=s(config.INST_FONT_SIZE), |
| 16 | + center_x=sld.right, center_y=sld.center_y - s(100)) |
| 17 | + Label(text='Press Spacebar to lock-in your response.', |
| 18 | + top=sld.bottom - s(250), font_size=s(config.INST_FONT_SIZE)) |
| 19 | + |
| 20 | + with UntilDone(): |
| 21 | + with Loop(): |
| 22 | + ans = KeyPress(keys=config.RESP_KEYS) |
| 23 | + with If(ans.pressed == config.RESP_KEYS[0]): |
| 24 | + with If(sld.value - config.HAPPY_SPEED <= -10): |
| 25 | + UpdateWidget(sld, value=-10) |
| 26 | + with Else(): |
| 27 | + UpdateWidget(sld, value=sld.value - config.HAPPY_SPEED) |
| 28 | + with Elif(ans.pressed == config.RESP_KEYS[1]): |
| 29 | + with If(sld.value + config.HAPPY_SPEED >= 10): |
| 30 | + UpdateWidget(sld, value=10) |
| 31 | + with Else(): |
| 32 | + UpdateWidget(sld, value=sld.value + config.HAPPY_SPEED) |
| 33 | + Wait(.05) |
| 34 | + with UntilDone(): |
| 35 | + KeyPress(keys=['SPACEBAR']) |
| 36 | + Log(name="happy", |
| 37 | + value=sld.value) |
| 38 | + |
| 39 | + |
| 40 | + |
| 41 | +if __name__ == "__main__": |
| 42 | + import config |
| 43 | + |
| 44 | + exp = Experiment() |
| 45 | + |
| 46 | + HappyQuest(config) |
| 47 | + |
| 48 | + exp.run() |
0 commit comments