screenMode = 0;
screenRes = 2;
white = [1 1 1];
black = [0 0 0];
fontName = 'Helvetica';
fontSize = 20;
number_of_buffers = 5;
rand('seed',sum(100*clock));
config_display(screenMode, screenRes, black ,white, fontName, fontSize, number_of_buffers);
config_keyboard;
clc;
disp('drawing and displaying an animation in real time');
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
enough = 0;
while ~enough
for i = 1 : nFrames
cgpenwid(5);
dotX = 0;
dotY = 0;
endLineX = r * cos(i * pi/12);
endLineY = r * sin(-i * pi/12);
cgellipse(dotX,dotY,10,10,[1 1 1], 'f');
cgdraw(dotX,dotY, endLineX,endLineY,[1 1 1]);
cgflip(0,0,0);
wait(100);
cgflip(0,0,0);
end
wait(1000);
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
for i = 1 : nFrames
cgpenwid(5);
dotX = 0;
dotY = 0;
endLineX = r * cos(i * pi/12);
endLineY = r * sin(-i * pi/12);
cgmakesprite(i,spriteWidth,spriteHeight,0, 0, 0);
cgsetsprite(i);
cgellipse(dotX,dotY,10,10,[1 1 1],'f');
cgdraw(dotX,dotY, endLineX,endLineY,[1, 1, 1]);
end
cgsetsprite(0);
for i = 1 : nFrames
cgdrawsprite(i,0,0,600,600);
cgflip(0,0,0);
wait(100);
cgflip(0,0,0);
end
wait(1000);
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
for i = 1 : nFrames
cgfreesprite(i);
end
stop_cogent
clc;