-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
c6629a2
commit ec635cf
Showing
53 changed files
with
925 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,137 @@ | ||
function AnalogAndDigitalClockWithSpecialTimes() | ||
figure('Name','Uhrzeit'); | ||
hold on; | ||
|
||
r = 12; | ||
theta = 0 : pi/60 : 2*pi; | ||
xcoords = r * cos(theta); | ||
ycoords = r * sin(theta); | ||
|
||
%for the perfect round circle | ||
set(gcf,'position',[0,0,500,450]) | ||
set(gcf,'color','w'); | ||
plot(xcoords,ycoords, "r"); | ||
axis equal; | ||
axis off; | ||
|
||
r = r - 2; | ||
numberIndex = 1; | ||
for grad = 60 : -30 : -270 | ||
theta = grad * pi/180; | ||
xCoordsCaption = r * cos(theta) - 2/3; | ||
yCoordsCaption = r *sin(theta); | ||
text(xCoordsCaption,yCoordsCaption,num2str(numberIndex),'color',"g", 'FontSize', 20); | ||
numberIndex = numberIndex + 1; | ||
end | ||
|
||
r = r + 2; | ||
|
||
%drawing hour line | ||
for grad = 0 : 30 : 360 | ||
theta = grad * pi/180; | ||
xCoordHourLine1 =(r - 1.2) * cos(theta); | ||
xCoordHourLine2 =r * cos(theta); | ||
xCoordsHourLine = [xCoordHourLine1 xCoordHourLine2]; | ||
yCoordHourLine1 = (r - 1.2) * sin(theta); | ||
yCoordHourLine2 = r * sin(theta); | ||
yCoordsHourLine = [yCoordHourLine1 yCoordHourLine2]; | ||
plot(xCoordsHourLine,yCoordsHourLine,'linewidth',2,'color',"k"); | ||
end | ||
|
||
%drawing minute line | ||
for grad = 0 : 6 : 360 | ||
theta = grad * pi/180; | ||
xCoordMinuteLine1 =(r - 0.6) * cos(theta); | ||
xCoordMinuteLine2 =r * cos(theta); | ||
xCoordsMinuteLine = [xCoordMinuteLine1 xCoordMinuteLine2]; | ||
yCoordMinuteLine1 = (r - 0.6) * sin(theta); | ||
yCoordMinuteLine2 = r * sin(theta); | ||
yCoordsMinuteLine = [yCoordMinuteLine1 yCoordMinuteLine2]; | ||
plot(xCoordsMinuteLine,yCoordsMinuteLine,'linewidth',1,'color',"k"); | ||
end | ||
|
||
while(true) | ||
actualTime = clock; | ||
disp(actualTime) | ||
s = actualTime(6); | ||
m = actualTime(5) + (s / 60); %adding second portion for continuous moving | ||
h = actualTime(4) + (m / 60) + (s / 3600); %adding minute and second portion for continuous moving | ||
|
||
%calcute angles for hour and minute pointer first, for checking | ||
%180° angle | ||
thetaHourPointer = (90-(360/12 * h)) * pi/180 ; | ||
thetaMinutePointer = (90-(360/60 * m)) * pi/180 ; | ||
|
||
%calculate angle difference and convert to degrees | ||
differenceAngle = abs(thetaHourPointer - thetaMinutePointer); | ||
differenceAngleInDegress = differenceAngle * 180/pi; | ||
|
||
%set fontcolor resp. plotcolor for special times | ||
if differenceAngleInDegress >= 179.999 && differenceAngleInDegress <= 180.001 | ||
color = "b"; | ||
else | ||
color = "r"; | ||
end | ||
|
||
%digital time printer inclusive fixing single string times to | ||
%stringLength 2 | ||
concateTimeString = ""; | ||
if strlength(num2str(fix(h))) == 1 | ||
concateTimeString = concateTimeString + "0" + fix(h); | ||
else | ||
concateTimeString = concateTimeString + fix(h); | ||
end | ||
|
||
concateTimeString = concateTimeString + ":"; | ||
|
||
if strlength(num2str(fix(m))) == 1 | ||
concateTimeString = concateTimeString + "0" + fix(m); | ||
else | ||
concateTimeString = concateTimeString + fix(m); | ||
end | ||
|
||
concateTimeString = concateTimeString + ":"; | ||
|
||
if strlength(num2str(fix(s))) == 1 | ||
concateTimeString = concateTimeString + "0" + fix(s); | ||
else | ||
concateTimeString = concateTimeString + fix(s); | ||
end | ||
|
||
%plot and print the digital time | ||
concateTimeString = concateTimeString + " Uhr"; | ||
disp(concateTimeString); %console output for debugging | ||
xAxes = xlim(); | ||
yAxes = ylim(); | ||
analogTime = text(xAxes(1)-4,yAxes(2),concateTimeString,'color',color, 'FontSize', 20); | ||
|
||
%drawing hour pointer | ||
xCoordHourPointer =(r - 3) * cos(thetaHourPointer); | ||
xCoordsHourPointer = [0 xCoordHourPointer]; | ||
yCoordHourPointer =(r - 3) * sin(thetaHourPointer); | ||
yCoordsHourPointer = [0 yCoordHourPointer]; | ||
hourPlot = plot(xCoordsHourPointer,yCoordsHourPointer,'linewidth',3,'color',color); | ||
|
||
%drawing minute pointer | ||
xCoordMinutePointer =(r - 0.5) * cos(thetaMinutePointer); | ||
xCoordsMinutePointer = [0 xCoordMinutePointer]; | ||
yCoordMinutePointer =(r - 0.5) * sin(thetaMinutePointer); | ||
yCoordsMinutePointer = [0 yCoordMinutePointer]; | ||
minutePlot = plot(xCoordsMinutePointer,yCoordsMinutePointer,'linewidth',2,'color',color); | ||
|
||
%drawing second pointer | ||
theta = (90 - (360/60 * s)) * pi/180 ; | ||
xCoordSecondPointer =(r - 0.5) * cos(theta); | ||
xCoordsSecondPointer = [0 xCoordSecondPointer]; | ||
yCoordSecondPointer =(r - 0.5) * sin(theta); | ||
yCoordsSecondPointer = [0 yCoordSecondPointer]; | ||
secondPlot = plot(xCoordsSecondPointer,yCoordsSecondPointer,'linewidth',1,'color',"r"); | ||
|
||
pause(0.01); | ||
delete(hourPlot); | ||
delete(minutePlot); | ||
delete(secondPlot); | ||
delete(analogTime); | ||
end | ||
end | ||
|
135 changes: 135 additions & 0 deletions
135
comp_aufg_p1/AnalogAndDigitalClockWithSpecialTimesExtended.m
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,135 @@ | ||
function AnalogAndDigitalClockWithSpecialTimesExtended() | ||
figure('Name','Uhrzeit'); | ||
hold on; | ||
|
||
r = 12; | ||
theta = 0 : pi/60 : 2*pi; | ||
xcoords = r * cos(theta); | ||
ycoords = r * sin(theta); | ||
|
||
%for the perfect round circle | ||
set(gcf,'position',[0,0,500,450]) | ||
set(gcf,'color','w'); | ||
plot(xcoords,ycoords, "r"); | ||
axis equal; | ||
axis off; | ||
|
||
r = r - 2; | ||
numberIndex = 1; | ||
for grad = 60 : -30 : -270 | ||
theta = grad * pi/180; | ||
xCoordsCaption = r * cos(theta) - 2/3; | ||
yCoordsCaption = r *sin(theta); | ||
text(xCoordsCaption,yCoordsCaption,num2str(numberIndex),'color',"g", 'FontSize', 20); | ||
numberIndex = numberIndex + 1; | ||
end | ||
|
||
r = r + 2; | ||
|
||
%drawing hour line | ||
for grad = 0 : 30 : 360 | ||
theta = grad * pi/180; | ||
xCoordHourLine1 =(r - 1.2) * cos(theta); | ||
xCoordHourLine2 =r * cos(theta); | ||
xCoordsHourLine = [xCoordHourLine1 xCoordHourLine2]; | ||
yCoordHourLine1 = (r - 1.2) * sin(theta); | ||
yCoordHourLine2 = r * sin(theta); | ||
yCoordsHourLine = [yCoordHourLine1 yCoordHourLine2]; | ||
plot(xCoordsHourLine,yCoordsHourLine,'linewidth',2,'color',"k"); | ||
end | ||
|
||
%drawing minute line | ||
for grad = 0 : 6 : 360 | ||
theta = grad * pi/180; | ||
xCoordMinuteLine1 =(r - 0.6) * cos(theta); | ||
xCoordMinuteLine2 =r * cos(theta); | ||
xCoordsMinuteLine = [xCoordMinuteLine1 xCoordMinuteLine2]; | ||
yCoordMinuteLine1 = (r - 0.6) * sin(theta); | ||
yCoordMinuteLine2 = r * sin(theta); | ||
yCoordsMinuteLine = [yCoordMinuteLine1 yCoordMinuteLine2]; | ||
plot(xCoordsMinuteLine,yCoordsMinuteLine,'linewidth',1,'color',"k"); | ||
end | ||
|
||
%get calculated special times with 180 degrees | ||
specialTimes = calculateSpecialTimes(); | ||
sizeOfSpecialTimesArray = length(specialTimes); | ||
arrayCounter = 1; | ||
while(true) | ||
color = "r"; | ||
|
||
%disp(actualTime) | ||
s = specialTimes(arrayCounter, 1); | ||
m = specialTimes(arrayCounter, 2); | ||
h = specialTimes(arrayCounter, 3); | ||
|
||
%if all values are displayed begin the animation again | ||
if arrayCounter ~= sizeOfSpecialTimesArray | ||
arrayCounter = arrayCounter + 1; | ||
else | ||
arrayCounter = 1; | ||
end | ||
|
||
%digital time printer inclusive fixing single string times to | ||
%stringLength 2 | ||
concateTimeString = ""; | ||
if strlength(num2str(fix(h))) == 1 | ||
concateTimeString = concateTimeString + "0" + fix(h); | ||
else | ||
concateTimeString = concateTimeString + fix(h); | ||
end | ||
|
||
concateTimeString = concateTimeString + ":"; | ||
|
||
if strlength(num2str(fix(m))) == 1 | ||
concateTimeString = concateTimeString + "0" + fix(m); | ||
else | ||
concateTimeString = concateTimeString + fix(m); | ||
end | ||
|
||
concateTimeString = concateTimeString + ":"; | ||
|
||
if strlength(num2str(fix(s))) == 1 | ||
concateTimeString = concateTimeString + "0" + fix(s); | ||
else | ||
concateTimeString = concateTimeString + fix(s); | ||
end | ||
|
||
%plot and print the digital time | ||
concateTimeString = concateTimeString + " Uhr"; | ||
disp(concateTimeString); %console output for debugging | ||
xAxes = xlim(); | ||
yAxes = ylim(); | ||
analogTime = text(xAxes(1)-4,yAxes(2),concateTimeString,'color',color, 'FontSize', 20); | ||
|
||
%drawing hour pointer | ||
thetaHourPointer = (90 - (360/12 * h)) * pi/180 ; | ||
xCoordHourPointer =(r - 3) * cos(thetaHourPointer); | ||
xCoordsHourPointer = [0 xCoordHourPointer]; | ||
yCoordHourPointer =(r - 3) * sin(thetaHourPointer); | ||
yCoordsHourPointer = [0 yCoordHourPointer]; | ||
hourPlot = plot(xCoordsHourPointer,yCoordsHourPointer,'linewidth',3,'color',color); | ||
|
||
%drawing minute pointer | ||
thetaMinutePointer = (90 - (360/60 * m)) * pi/180 ; | ||
xCoordMinutePointer =(r - 0.5) * cos(thetaMinutePointer); | ||
xCoordsMinutePointer = [0 xCoordMinutePointer]; | ||
yCoordMinutePointer =(r - 0.5) * sin(thetaMinutePointer); | ||
yCoordsMinutePointer = [0 yCoordMinutePointer]; | ||
minutePlot = plot(xCoordsMinutePointer,yCoordsMinutePointer,'linewidth',2,'color',color); | ||
|
||
%drawing second pointer | ||
theta = (90 - (360/60 * s)) * pi/180 ; | ||
xCoordSecondPointer =(r - 0.5) * cos(theta); | ||
xCoordsSecondPointer = [0 xCoordSecondPointer]; | ||
yCoordSecondPointer =(r - 0.5) * sin(theta); | ||
yCoordsSecondPointer = [0 yCoordSecondPointer]; | ||
secondPlot = plot(xCoordsSecondPointer,yCoordsSecondPointer,'linewidth',1,'color',"r"); | ||
|
||
pause(1); | ||
delete(hourPlot); | ||
delete(minutePlot); | ||
delete(secondPlot); | ||
delete(analogTime); | ||
end | ||
end | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,24 @@ | ||
function x = calculateAngles(hour,minute) | ||
%calculate hour angle | ||
thetaHour = (360/12 * hour) * pi/180 ; | ||
|
||
%calculate minute angle | ||
thetaMinute = (360/60 * minute) * pi/180 ; | ||
|
||
%calculate all possible angles | ||
diff1 = thetaHour - thetaMinute; | ||
diff2 = thetaMinute - thetaHour; | ||
|
||
%arc measure to degree | ||
diff1Degree = diff1 * 180/pi; | ||
diff2Degree = diff2 * 180/pi; | ||
|
||
%eliminate negative number and return minimum angle | ||
if diff1Degree < diff2Degree && diff1Degree >=0 | ||
x = diff1Degree; | ||
%disp(diff1Degree); | ||
elseif diff2Degree >=0 | ||
x = diff2Degree; | ||
%disp(diff2Degree); | ||
end | ||
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,32 @@ | ||
function x = calculateSpecialTimes() | ||
arrayIndex = 1; | ||
%iterate throw all possible times | ||
for i = 0:23 | ||
for j = 0:59 | ||
for k = 0:0.01:59 | ||
s = k; | ||
m = j + (s / 60); %adding second portion for continuous moving | ||
h = i + (m / 60) + (s / 3600); %adding minute and second portion for continuous moving | ||
|
||
%calcute angles for hour and minute pointer first, for checking | ||
%180° angle | ||
thetaHourPointer = (360/12 * h) * pi/180 ; | ||
thetaMinutePointer = (360/60 * m) * pi/180 ; | ||
|
||
%calculate angle difference and convert to degrees | ||
differenceAngle = abs(thetaHourPointer - thetaMinutePointer); | ||
differenceAngleInDegress = differenceAngle * 180/pi; | ||
%disp(differenceAngleInDegress); | ||
%write special times in an 3-D-array | ||
if differenceAngleInDegress >= 179.999 && differenceAngleInDegress <= 180.001 | ||
specialTimesArray(arrayIndex, 1) = s; | ||
specialTimesArray(arrayIndex, 2) = m; | ||
specialTimesArray(arrayIndex, 3) = h; | ||
arrayIndex = arrayIndex + 1; | ||
end | ||
end | ||
end | ||
end | ||
disp(specialTimesArray); | ||
x = specialTimesArray; | ||
end |
Oops, something went wrong.