PsyScriptIcon.png PsyScript: getting experiments done

$query\n"; } $result = mysql_query($database, $query, $connection) or die("ack! query failed: " ."
  • errorno=".mysql_errno() ."
  • error=".mysql_error() ."
  • query=".$query ); return $result; } $Base = "http://www.maccs.mq.edu.au"; $URL= $PHP_SELF; $connection = mysql_connect('localhost', 'tim', 'connect2'); if (!$connection) { print("Cannot connect to database. Call Tim.
    "); exit(); } $result=safe_db_query("Counters","SELECT * FROM Count WHERE Base='$Base' AND URL='$URL'", $connection); while ($row = mysql_fetch_row($result)) { $ChkBase=$row[0]; $ChkURL=$row[1]; $ChkCount=$row[2]; $Count=$ChkCount; } if ($ChkURL == ""){ safe_db_query("Counters","INSERT INTO Count VALUES ('$Base','$URL','0')", $connection); $Count=0; } $Count++; safe_db_query("Counters","UPDATE Count SET Number='$Count' WHERE Base='$Base' AND URL='$URL'"); $result=safe_db_query("Counters","SELECT * FROM Count WHERE Base='$Base' AND URL='$URL'", $connection); while ($row = mysql_fetch_row($result)) { $Base=$row[0]; $URL=$row[1]; $Count=$row[2]; } echo $Count; */ ?>hits
  • Using the Drawing Commands

    1: Drawing on screen

    The easiest way to learn the drawing commands is to use them for a practical task: here I will draw two response buttons on the screen for a subject to click in.

    Using the built-in drawing commands, we can accomplish this in just a few lines:

    tell application "PsyScript"
       
    reset all
       
    activate
       
    begin experiment
       
    set word size to 28
       
    set word color to {32000, 32000, 32000}
       
    draw rectangle in {50, 50, 150, 100} corner rounding {5, 5} using {pen color:green} with filling
       
    draw rectangle in {160, 50, 260, 100} corner rounding {5, 5} using {pen color:red} with filling
       
    do trial "'YES'(?1) 'NO'(?2) " given {{100, 85}, {210, 85}}
       
    end experiment
    end tell

     

    Running this script shows this image on screen:

    drawExample.png

    You can learn about the other drawing commands for ovals and lines and beier curves by looking in the PsyScript dictionary and in the "example scripts folder": they are pretty self explanatory.

    2: Creating permanent stimuli

    To create an image as a permanent stimulus (i.e., loaded into memory for display later), you simply wrap your drawing commands inside line to create a new permanent stimulus with the dimensions you want(like a blank canvas in memory), set the drawing target to point to this stimulus, then after doing any drawing you need, setting the drawing target back to the screen ("null"). Now the permanent stimulus contains your drawing and is available just like any other permanent stimulus.

    Example permanent stimulus creation and drawing offscreen:

    tell application "PsyScript"
       
    set stim1 to (make new permanent stimulus with properties ¬
          {
    type:picture stimulus, name:"yes_no", dimensions:{500, 400}, pixel depth:(get screen depth)})
       
    set drawing target to stim1
    -- insert your drawing commands here
       
    activate
       
    begin experiment
       
    do trial "•yes_no" --call your stimulus by its "name" property
       
    end experiment
    end tell

    To save the drawing as a file object, just save the object to file, as shown below.

    tell application "PsyScript"
       
    set newStimulus to (make new permanent stimulus with properties ¬
          {
    type:picture stimulus, name:"yes_no", dimensions:{500, 400}, pixel depth:(get screen depth)})
       
    set drawing target to stim1
       --
    insert your drawing commands here
       
    save newStimulus output to file "Smiley Face" if exists overwrite
    end tell

    The drawing system uses a pen to draw one of a set of objects

    The pen has a color and size, which you can set on a default basis using

       set default drawing settings to {pen size:{4, 4}, pen color:yellow}

    Colors can be set using predefined names {blue,red, yellow etc.}, or as RGB lists

    RGB stands for building colors by mixing RED, GREEN, and BLUE. Each component color has an intensity which you set between 0 (not at all) and 65535 (100%). 65535 looks funny until you realise it is 2^16.

    So saying pen color:{0, 65535, 0} is the same as saying pen color:green

    You can override the default pen settings for each drawing action by adding a using {pen properties statement} to a particular drawing command (see examples below).

    You can draw rectangles, ovals, arcs, and lines: Simple examples of drawing are

       draw rectangle in {0, 0, 300, 300} with filling
       
    draw rectangle in {0, 0, 300, 300} using {pen color:{0, 0, 65535}} without filling
       
    draw line from {50, 40} to {100, 40}
       draw oval in {50, 50, 100, 100} without filling
       
    draw line from {200, 40} to {250, 40}
       
    draw oval in {200, 50, 250, 100} using {pen color:white} with filling
       
    draw oval in {200, 50, 250, 100} without filling
       
    draw rectangle in {125, 62, 175, 212} corner rounding {8, 16} with filling
       
    draw arc in {50, 170, 250, 270} starting angle 90 arc angle 180 using {pen color:red, pen size:{8, 32}} without filling

    Where to next?

    Check out the examples in "showing stimuli:image creation"

    MACCS PsyScriptIcon.png Documentation Downloads FAQ Mailing List
    Last change:
    Advanced Search

    Applescript in a Nutshell : A Desktop Quick Reference

    AppleScript for Applications: Visual QuickStart Guide

    AppleScript For Dummies

    Applescript for the Internet Visual Quickstart Guide

    Applescript Language Guide; English Dialect

    Danny Goodman's Applescript Handbook