This demo script shows how to use visual stimuli in model organism behavioural assays, such as overhead lights and images on the screen.
Below the script is split into several parts to explain how to write the zanscript (the coding language) to build a service that will use the built-in visual stimuli during an experiment.
INCLUDE zsys DEFINE TRIALS 1 DEFINE STRIPE_TRIALS 3 DEFINE SCROLLTIME 8 DEFINE QUARTER_SCROLLTIME 2 DEFINE WAIT_TIME 6 DEFINE UNIT_TIME 3 DEFINE SPRITE 5 DEFINE SPRITE_IMAGE 520 DEFINE CIRCLE 1 DEFINE SQUARE 2
- Include zsys - this must be included in all scripts
- The following group of commands DEFINE values used in the script, in this case number of trials and amount of time in seconds.
- The two DEFINE commands for sprites must be written when your script includes the use of images on the screen .
- The following two DEFINE commands enable the shapes - circle and square - to be included in the script.
SETCOLOUR(10,0.01,0.01,0.01) SETLIGHT(LIGHT1,SQUARE,300,500,1000) SETLIGHT(LIGHT2,SQUARE,1300,500,1000) SETLIGHT(LIGHT8,SPRITE,0,500,0) SETLIGHT(LIGHT9,SPRITE,0,500,0) SETLIGHT(LIGHT10,SPRITE,0,500,0) SETLIGHT(LIGHT11,SPRITE,800,0,0) LOAD(SPRITE_IMAGE,"8:blue_stripe_vertical") LOAD(SPRITE_IMAGE,"9:blue_stripe_vertical") LOAD(SPRITE_IMAGE,"10:blue_stripe_vertical") LOAD(SPRITE_IMAGE,"11:danio_small")
- The SETCOLOUR command enables you to change how an image is lit from the screen, in this instance this command will be used to change how the blue bar image is lit, so it will appear black.
- The first two SETLIGHT commands position square images on the screen, the first two numbers are the coordinates of their centre, and the third number is the size (in pixels) of the square (which is actually seen as a rectangle on the screen in this case).
- The next four SETLIGHT commands tell the unit to look for a bitmap image from the Assets directory, and load this in the position as indicated by the screen coordinates for its centre (i.e. 0,500 for three of them*) and keep each one at its original size (0 deems no change to size of image).
- The LOAD command tells the unit which bitmap image should be used for which light, i.e. LIGHT8 will be the asset "blue_stripe_vertical" and LIGHT11 will be "danio_small".
ACTION MAIN LIGHTS(ALL,OFF) INVOKE(OVERHEAD_LIGHTS,TRIALS) INVOKE(FISH_MOVEMENT,TRIALS) INVOKE(STRIPE_MOVEMENT,STRIPE_TRIALS) LIGHTS(ALL,OFF) INVOKE(BLOCK_COLOURS,TRIALS) LIGHTS(ALL,OFF) COMPLETE
The next set of ACTION MAIN commands (above) details the order of the whole experiment. In this case:
- At the beginning and end all the lights all turned off.
- The experiment comprises four parts, the parts are run sequentially, with OVERHEAD_LIGHTS starting. Three of the parts are run the same number of times as indicated by TRIALS (i.e. they run once, as defined in the first section of commands above). One of the parts, STRIPE_MOVEMENT, is run 3 times, the value defined for STRIPE_TRIALS in the first section of commands.
- COMPLETE indicates that the experiment has finished.
ACTION OVERHEAD_LIGHTS LIGHTS(LIGHT16,red) WAIT(1) LIGHTS(LIGHT16,green) WAIT(1) LIGHTS(LIGHT16,blue) WAIT(1) LIGHTS(LIGHT16,white) WAIT(1) LIGHTS(all,off) COMPLETE
The OVERHEAD_LIGHTS section details the actions for this period:
- LIGHT16 is the overhead light.
- The overhead light is turned on, in 1 second intervals, as four different colours sequentially: red, green, blue, white.
- All the lights are turned off before this section is finished (COMPLETE).
ACTION FISH_MOVEMENT LIGHTS(LIGHT11,ON) PANLIGHT(LIGHT11,800,1000,SCROLLTIME) WAIT(WAIT_TIME) LIGHTS(LIGHT11,OFF) LIGHTS(LIGHT11,MAGENTA) PANLIGHT(LIGHT11,1600,0,SCROLLTIME) WAIT(WAIT_TIME) LIGHTS(LIGHT11,OFF) LIGHTS(all,off) COMPLETE
These commands are for the FISH_MOVEMENT period as invoked in ACTION MAIN. They detail:
- LIGHT11 comes on - as defined in the first section, this is a 'sprite', a bitmap image, loaded in the Assets directory, called "danio_small" (in this case it is a small fish).
- This image pans across the screen from the position where it was originally set, as instructed by the SETLIGHT command in the first section, to the new position (co-ordinates 800,1000* on the screen). It will pan across the screen in the time as defined in the first section (i.e. SCROLLTIME).
- The unit will wait for the number of seconds as defined in the first section as WAIT_TIME before turning off LIGHT11 (i.e. the image). This period of time must be at least as long as the time alloted for the image to pan across the screen (i.e. the WAIT_TIME is 1 second longer than the SCROLLTIME).
ACTION STRIPE_MOVEMENT LIGHTS(LIGHT1,WHITE) LIGHTS(LIGHT2,WHITE) SETLIGHT(LIGHT8,SPRITE,0,500,0) LIGHTS(LIGHT8,ON) PANLIGHT(LIGHT8,1800,500,SCROLLTIME) WAIT(QUARTER_SCROLLTIME) SETLIGHT(LIGHT9,SPRITE,0,500,0) LIGHTS(LIGHT9,10) PANLIGHT(LIGHT9,1800,500,SCROLLTIME) WAIT(QUARTER_SCROLLTIME) SETLIGHT(LIGHT10,SPRITE,0,500,0) LIGHTS(LIGHT10,ON) PANLIGHT(LIGHT10,1800,500,SCROLLTIME) WAIT(QUARTER_SCROLLTIME) COMPLETE
These commands are for the STRIPE_MOVEMENT section of the experiment as invoked in ACTION MAIN. They instruct the unit to:
- Turn a white light on the screen.
- Set LIGHT8, a blue vertical bar (the image that is loaded in the assets directory) in a position across the front end of the screen.
- LIGHT8 then turns on, illuminated by the screen light.
- LIGHT 8 pans across the screen, reaching the coordinates 1800,500 in the SCROLLTIME.
- After a short period of time, QUARTER_SCROLLTIME, the next light (LIGHT9, again a blue horizontal bar) pans across the screen in a similar fashion to LIGHT8.
- The only difference is that this bar appears black because of the command - LIGHTS(LIGHT9,10) - as the control for how the image is lit is set in the first section after the command SETCOLOUR(10,0.01,0.01,0.01).
- LIGHT10, another blue horizontal bar, behaves in a similar fashion to LIGHT8.
- This ACTION is repeated 3 times (following the ACTION MAIN command - INVOKE(STRIPE_MOVEMENT,STRIPE_TRIALS), and the previous DEFINE command - STRIPE_TRIALS 3) These three lights scroll continuously across the screen three times.
ACTION BLOCK_COLOURS LIGHTS(LIGHT1,BLUE) LIGHTS(LIGHT2,GREEN) WAIT(UNIT_TIME) LIGHTS(LIGHT1,GREEN) LIGHTS(LIGHT2,BLUE) WAIT(UNIT_TIME) LIGHTS(ALL,OFF) LIGHTS(LIGHT1,BLUE) LIGHTS(LIGHT2,BLUE) WAIT(UNIT_TIME) LIGHTS(LIGHT1,GREEN) LIGHTS(LIGHT2,GREEN) WAIT(UNIT_TIME) LIGHTS(ALL,OFF) COMPLETE
The ACTION BLOCK_COLOURS gives the commands for this part of the experiment as invoked in ACTION MAIN. It details:
- The unit waits for a period (SCROLLTIME) to give the rolling images time to finish panning across the screen in the previous ACTION.
- The colours that will appear on the screen, LIGHT1 fills the front half of the screen and LIGHT2 fills the back half of the screen. The position and size of the lights is defined in SETLIGHT commands found in the first part of the code.
- The colours, blue and green, switch ends.
- The screen is then all blue, and then all green.
- The lights are turned off and the section is completed.
Here you can download the lights demo script as a .zs file. Right click on the download link below and download / save the file as a zanscript file, i.e. in the same format: lights_demo.zs. You then need to upload this zanscript file into the Zanscript directory on your unit.
You also need to download the bitmap files that are used in the script (blue_stripe_vertical.bmp and danio_small.bmp), and save these into the Assets directory on your unit. Make sure that the assets named in your script exactly match the names of the assets / bitmaps loaded into your Asset directory (including upper and lower case used).
Script download: lights_demo.zs
Run the demo
Build as a service - Once written, the zanscript is built (.zex file) and loaded on the Settings page in one of the 20 slots a service.
Run the service - The demo service can now be operated from the home page. The following video example illustrates the three ACTIONs - FISH_MOVEMENT, STRIPE_MOVEMENT and BLOCK_COLOURS.
The video is a clip from the lights test and shows how colours, images and shapes can be displayed on the screen.
* For more details about screen coordinates see the illustrated description in the Functions section of the Zanscript syntax manual.