Guest User

Untitled

a guest
Aug 17th, 2018
79
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.99 KB | None | 0 0
  1. function makeClock(month, day, year, t)
  2.  
  3. hold on
  4.  
  5. %makes circle
  6. th = linspace(0,2.*pi);
  7. x1 = cos(th);
  8. y1 = sin(th);
  9. plot(x1, y1, 'k')
  10.  
  11. %makes dot in middle
  12. plot(0, 0, 'ko')
  13.  
  14. %finds hour and mins
  15. hour = str2num(t(1:2));
  16. min = str2num(t(4:5));
  17.  
  18. %creates hour/min hands
  19. xhour = [0 0];
  20. yhour = [0 0.6];
  21. xmin = [0 0];
  22. ymin = [0 0.9];
  23.  
  24. %rotates hour/min hands
  25. hrot = -((hour./12) .* (360));
  26. mrot = -((min./60) .* (360));
  27.  
  28. %uses rotateLine to create hourr hand
  29. [newhourx newhoury] = rotateLine(xhour,yhour,hrot);
  30. plot(newhourx,newhoury)
  31.  
  32. %uses rotateLine to create min hand
  33. [newminx newminy] = rotateLine(xmin,ymin,mrot);
  34. plot(newminx,newminy,'r')
  35.  
  36. %uses showDate to create title
  37. strdate = showDate(month, day, year);
  38. title(sprintf('Today Is %s, And The Time Is %s', strdate, t))
  39.  
  40. %use circular_Rotate to create tick marks on clock
  41. x = [0, 0];
  42. y = [1, 0.9];
  43. circular_Rotate(x, y, 12)
  44.  
  45. %graph attributes
  46. axis square
  47.  
  48. end
  49.  
  50. %helper fcn
  51. function [date] = showDate(month, day, year)
  52.  
  53. switch month
  54. case 1
  55. MM = 'Jan';
  56. case 01
  57. MM = 'Jan';
  58. case 2
  59. MM = 'Feb';
  60. case 02
  61. MM = 'Feb';
  62. case 3
  63. MM = 'Mar';
  64. case 03
  65. MM = 'Mar';
  66. case 4
  67. MM = 'Apr';
  68. case 04
  69. MM = 'Apr';
  70. case 5
  71. MM = 'May';
  72. case 05
  73. MM = 'May';
  74. case 6
  75. MM = 'Jun';
  76. case 06
  77. MM = 'Jun';
  78. case 7
  79. MM = 'Jul';
  80. case 07
  81. MM = 'Jul';
  82. case 8
  83. MM = 'Aug';
  84. case 08
  85. MM = 'Aug';
  86. case 9
  87. MM = 'Sep';
  88. case 09
  89. MM = 'Sep';
  90. case 10
  91. MM = 'Oct';
  92. case 11
  93. MM = 'Nov';
  94. case 12
  95. MM = 'Dec';
  96. end
  97. day = num2str(day);
  98. Yr = num2str(year);
  99.  
  100. date = [MM,' ',day,',',Yr];
  101. end
  102.  
  103. %helper fcn
  104. function circular_Rotate(x,y,num)
  105. th=360/num;%finds the angle for each curve that is to be plotted
  106. P=[x;y];
  107. R=[cosd(th),-sind(th);sind(th),cosd(th)];
  108. numtimes=1:num;
  109. hold on;
  110. for i=1:length(numtimes)
  111. RP=R*P;
  112. newP=RP;
  113. plot(newP(1,:),newP(end,:));
  114. P=newP;
  115. end
  116. axis square;
  117. end
  118.  
  119. %also helper fcn
  120. function [out, out2] = rotateLine (x, y, th)
  121.  
  122.  
  123.  
  124. out = x.*cosd(th)-y.*sind(th);
  125. out2 = x.*sind(th)+y.*cosd(th);
  126.  
  127. end
Add Comment
Please, Sign In to add comment