Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- function makeClock(month, day, year, t)
- hold on
- %makes circle
- th = linspace(0,2.*pi);
- x1 = cos(th);
- y1 = sin(th);
- plot(x1, y1, 'k')
- %makes dot in middle
- plot(0, 0, 'ko')
- %finds hour and mins
- hour = str2num(t(1:2));
- min = str2num(t(4:5));
- %creates hour/min hands
- xhour = [0 0];
- yhour = [0 0.6];
- xmin = [0 0];
- ymin = [0 0.9];
- %rotates hour/min hands
- hrot = -((hour./12) .* (360));
- mrot = -((min./60) .* (360));
- %uses rotateLine to create hourr hand
- [newhourx newhoury] = rotateLine(xhour,yhour,hrot);
- plot(newhourx,newhoury)
- %uses rotateLine to create min hand
- [newminx newminy] = rotateLine(xmin,ymin,mrot);
- plot(newminx,newminy,'r')
- %uses showDate to create title
- strdate = showDate(month, day, year);
- title(sprintf('Today Is %s, And The Time Is %s', strdate, t))
- %use circular_Rotate to create tick marks on clock
- x = [0, 0];
- y = [1, 0.9];
- circular_Rotate(x, y, 12)
- %graph attributes
- axis square
- end
- %helper fcn
- function [date] = showDate(month, day, year)
- switch month
- case 1
- MM = 'Jan';
- case 01
- MM = 'Jan';
- case 2
- MM = 'Feb';
- case 02
- MM = 'Feb';
- case 3
- MM = 'Mar';
- case 03
- MM = 'Mar';
- case 4
- MM = 'Apr';
- case 04
- MM = 'Apr';
- case 5
- MM = 'May';
- case 05
- MM = 'May';
- case 6
- MM = 'Jun';
- case 06
- MM = 'Jun';
- case 7
- MM = 'Jul';
- case 07
- MM = 'Jul';
- case 8
- MM = 'Aug';
- case 08
- MM = 'Aug';
- case 9
- MM = 'Sep';
- case 09
- MM = 'Sep';
- case 10
- MM = 'Oct';
- case 11
- MM = 'Nov';
- case 12
- MM = 'Dec';
- end
- day = num2str(day);
- Yr = num2str(year);
- date = [MM,' ',day,',',Yr];
- end
- %helper fcn
- function circular_Rotate(x,y,num)
- th=360/num;%finds the angle for each curve that is to be plotted
- P=[x;y];
- R=[cosd(th),-sind(th);sind(th),cosd(th)];
- numtimes=1:num;
- hold on;
- for i=1:length(numtimes)
- RP=R*P;
- newP=RP;
- plot(newP(1,:),newP(end,:));
- P=newP;
- end
- axis square;
- end
- %also helper fcn
- function [out, out2] = rotateLine (x, y, th)
- out = x.*cosd(th)-y.*sind(th);
- out2 = x.*sind(th)+y.*cosd(th);
- end
Add Comment
Please, Sign In to add comment