function data = clock_sprites();
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
% COGENT: CONFIGURATION
% display parameters
screenMode = 0;                 % 0 for small window, 1 for full screen, 2 for second screen if attached
screenRes = 2;                  % 800 x 600 resolution
white = [1 1 1];                % foreground colour (optional)
black = [0 0 0];                % background colour (optional)
fontName = 'Helvetica';         % font parameters (optional)
fontSize = 20;
number_of_buffers = 5;          % how many offscreen buffers to create
rand('seed',sum(100*clock));    % seeds the random number generator with the clock time

% call config_... to set up cogent environment, before starting cogent
config_display(screenMode, screenRes, black ,white, fontName, fontSize, number_of_buffers);   % open graphics window
config_keyboard;                % this enables collection of keyboard responses
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
clc;




disp('drawing and displaying an animation in real time');
input('Press ENTER to start');
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
% EXAMPLE One: Drawing lines and circles
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
start_cogent
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
cgtext('Press any key to Start',0,0);
cgflip;
waitkeydown(inf);
cgflip(0,0,0);cgflip(0,0,0);
wait(500);
clearkeys;
r = 100;
nFrames = 20
enough = 0;
while ~enough

    for i = 1 : nFrames
        cgpenwid(5);
        % assign a random location to the circle
        dotX = 0;
        dotY = 0;

        % assign end point of the line
        endLineX = r * cos(i * pi/12);
        endLineY = r * sin(-i * pi/12);

        % draw circle
        cgellipse(dotX,dotY,10,10,[1 1 1], 'f');
        % draw line
        cgdraw(dotX,dotY, endLineX,endLineY,[1 1 1]);
        cgflip(0,0,0);
        wait(100);
        cgflip(0,0,0);
    end


    wait(1000);
    % next trial
    cgtext('Press any key to continue - Escape to stop',0,0);
    cgflip;
    [k,t,n] = waitkeydown(inf);
    cgflip(0,0,0);cgflip(0,0,0);
    if k(n) == 52
        enough = 1;
    end
end

%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
stop_cogent
clc;







disp('drawing an animation in advance and then displaying it');
input('Press ENTER to start');
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
start_cogent
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
cgtext('Press any key to Start',0,0);
cgflip;
waitkeydown(inf);
cgflip(0,0,0);cgflip(0,0,0);
wait(500);
clearkeys;
r            = 100;
nFrames      = 20;
spriteWidth  = 300;
spriteHeight = 300;

enough = 0;
while ~enough
    % step one: prepare your sprites
    for i = 1 : nFrames
        cgpenwid(5);
        % assign a random location to the circle
        dotX = 0;
        dotY = 0;

        % assign end point of the line
        endLineX = r * cos(i * pi/12);
        endLineY = r * sin(-i * pi/12);

        % (Key,Width,Height<,R,G,B>)
        cgmakesprite(i,spriteWidth,spriteHeight,0, 0, 0);
        cgsetsprite(i);
        % draw circle
        cgellipse(dotX,dotY,10,10,[1 1 1],'f');
        % draw line
        cgdraw(dotX,dotY, endLineX,endLineY,[1, 1, 1]);
    end



    % step two: display your constructed images
    cgsetsprite(0);
    for i = 1 : nFrames
        cgdrawsprite(i,0,0,600,600);
        cgflip(0,0,0);
        wait(100);
        cgflip(0,0,0);
    end



    % step three
    wait(1000);
    % next trial
    cgtext('Press any key to continue - Escape to stop',0,0);
    cgflip;
    [k,t,n] = waitkeydown(inf);
    cgflip(0,0,0);cgflip(0,0,0);
    if k(n) == 52
        enough = 1;
    end
end

% empty your sprites
for i = 1 : nFrames
    cgfreesprite(i);
end

%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
stop_cogent
clc;