sca;
close all;
clear;
PsychDefaultSetup(2);
screens = Screen('Screens');
screenNumber = max(screens);
white = WhiteIndex(screenNumber);
black = BlackIndex(screenNumber);
grey = white / 2;
darkGrey = white / 8;
lightGrey = white / 2.1;
red = [white 0 0];
green = [0 white 0];
blue = [0 0 white];
[window, windowRect] = PsychImaging('OpenWindow', screenNumber, black);
[screenXpixels, screenYpixels] = Screen('WindowSize', window);
ifi = Screen('GetFlipInterval', window);
[xCenter, yCenter] = RectCenter(windowRect);
Screen('BlendFunction', window, 'GL_SRC_ALPHA', 'GL_ONE_MINUS_SRC_ALPHA');
Screen('TextFont', window, 'Ariel');
Screen('TextSize', window, 75);
numNums = 12;
textBoundsAll = nan(numNums, 4);
for i = 1:12
[~, ~, textBoundsAll(i, :)] = DrawFormattedText(window, num2str(i), 0, 0, white);
end
topPriorityLevel = MaxPriority(window);
Priority(topPriorityLevel);
clockDiameter = screenYpixels * 0.8;
clockRadius = clockDiameter / 2;
numHours = 12;
numMins = 60;
anglePerHour = 360 / numHours;
anglePerMin = 360 / numMins;
anglePerSec = anglePerMin;
numColour = rand(1, 3) ./ 2 + 0.5;
clockFaceScale = 1.2;
hourHandScale = .7;
minHandScale = .8;
secHandScale = .9;
clockTickScale = .95;
vbl = Screen('Flip', window);
waitframes = 1;
time = 0;
while ~KbCheck
matClock = clock;
yearNum = matClock(1);
monthNum = matClock(2);
dayNum = matClock(3);
hourNum = matClock(4);
minsNum = matClock(5);
secsNum = round(matClock(6));
clockRect = CenterRectOnPointd([0 0 clockDiameter clockDiameter] * clockFaceScale, xCenter, yCenter);
Screen('FillOval', window, darkGrey,...
clockRect, clockDiameter * 1.1);
Screen('FrameOval', window, lightGrey, clockRect, 6);
for i = 0:numMins - 1
minAngle = i * anglePerMin;
xposEnd = clockRadius * clockFaceScale * sind(minAngle);
yposEnd = clockRadius * clockFaceScale * cosd(minAngle) * -1;
xposStart = clockRadius * clockFaceScale * clockTickScale * sind(minAngle);
yposStart = clockRadius * clockFaceScale * clockTickScale * cosd(minAngle) * -1;
if mod(i, 15)
Screen('DrawLines', window, [xposStart yposStart; xposEnd yposEnd]', 6, lightGrey, [xCenter yCenter], 2);
else
Screen('DrawLines', window, [xposStart yposStart; xposEnd yposEnd]', 8, white, [xCenter yCenter], 2);
end
end
for i = 1:numHours
xpos = xCenter - clockRadius * sind(anglePerHour * i - 180);
ypos = yCenter + clockRadius * cosd(anglePerHour * i - 180);
DrawFormattedText(window, num2str(i),...
xpos - ((textBoundsAll(i, 3) - textBoundsAll(i, 1)) / 2),...
ypos + ((textBoundsAll(i, 4) - textBoundsAll(i, 2)) / 2), numColour);
end
hourNum = mod(hourNum, 12);
hourAngle = hourNum * anglePerHour;
xposHour = clockRadius * hourHandScale * sind(hourAngle);
yposHour = clockRadius * hourHandScale * cosd(hourAngle) * -1;
Screen('DrawLines', window, [0 0; xposHour yposHour]', 18, green, [xCenter yCenter], 2);
Screen('DrawDots', window, [xposHour yposHour]', 20, green, [xCenter yCenter], 2);
minAngle = minsNum * anglePerMin;
xposMin = clockRadius * minHandScale * sind(minAngle);
yposMin = clockRadius * minHandScale * cosd(minAngle) * -1;
Screen('DrawLines', window, [0 0; xposMin yposMin]', 12, red, [xCenter yCenter], 2);
Screen('DrawDots', window, [xposMin yposMin]', 20, red, [xCenter yCenter], 2);
secAngle = secsNum * anglePerSec;
xposSec = clockRadius * secHandScale * sind(secAngle);
yposSec = clockRadius * secHandScale * cosd(secAngle) * -1;
Screen('DrawLines', window, [0 0; xposSec yposSec]', 2, blue, [xCenter yCenter], 2);
Screen('DrawDots', window, [xposSec yposSec]', 20, blue, [xCenter yCenter], 2);
Screen('DrawDots', window, [0 0]', 25, white, [xCenter yCenter], 2);
vbl = Screen('Flip', window, vbl + (waitframes - 0.5) * ifi);
time = time + ifi;
if time >= 1
numColour = rand(1, 3) ./ 2 + 0.5;
time = 0;
end
end
sca;