%slideshow.m
%
%read list of word strings from file 'WORDS.TXT'
%create a list of randomized pointers to the words in this list
%present each word in this randomized order
%
%dependencies: requires randomize_matrix.m script

config_display(0,1,[0 0 0],[1 1 1],'Helvetica',96,4,0); %640x480 window
start_cogent;

%load list of stimulus file names
[stimulus_strings]=textread('words.txt','%s');
ntrials = length(stimulus_strings);
if(ntrials <= 0)
    disp('Error loading filenames list in WORDS.TXT')
    disp('Program terminated.');
    stop_cogent;
    return
end

%generate random trial order
order=[1:ntrials]';            %create column array from 1 to ntrials
order=randomize_matrix(order); %shuffle this array

%show count-down at startup
for i = 1:ntrials
    %clear screen buffer #1
    clearpict(1);
    %fetch next string according to randomized order
    %note: need curly braces to access aray of strings
    str=num2str(stimulus_strings{ order(i) });
    %draw stimulus string in screen buffer #1
    preparestring(str,1);
    %display contents of screen buffer #1
    drawpict(1);
    %wait half second
    wait(500);
end

%now, show the list in non-random order
setforecolour(1,0,0); %select red text color
for i = 1:ntrials
    clearpict(1);
    preparestring(stimulus_strings{i},1);
    drawpict(1);
    wait(500);
end
clearpict(1); preparestring('Burma Shave',1); drawpict(1); wait(2000);

%exit COGENT mode
stop_cogent;
