Canvas చక్రం పింజర్స్
నాలుగవ భాగం - గంటల సూచికలను చిత్రీకరించడం
గంటలకు సూచికలు అవసరమవుతాయి. గంటల సూచికలను చిత్రీకరించడానికి ఒక JavaScript ఫంక్షన్ సృష్టించండి:
JavaScript:
function drawClock() { drawFace(ctx, radius); drawNumbers(ctx, radius); drawTime(ctx, radius); } function drawTime(ctx, radius) { const now = new Date(); let hour = now.getHours(); let minute = now.getMinutes(); let second = now.getSeconds(); // గంటల hour = hour%12; hour = (hour*Math.PI/6)+(minute*Math.PI/(6*60))+(second*Math.PI/(360*60)); drawHand(ctx, hour, radius*0.5, radius*0.07); // గంటల minute = (minute*Math.PI/30)+(second*Math.PI/(30*60)); drawHand(ctx, minute, radius*0.8, radius*0.07); // నిమిషం second = (second*Math.PI/30); drawHand(ctx, second, radius*0.9, radius*0.02); } function drawHand(ctx, pos, length, width) { ctx.beginPath(); ctx.lineWidth = width; ctx.lineCap = "round"; ctx.moveTo(0,0); ctx.rotate(pos); ctx.lineTo(0, -length); ctx.stroke(); ctx.rotate(-pos); }
కోడ్ వివరణ
గంటల, నిమిషం, నిమిషం పొందడానికి ఒక Date ఆబ్జెక్ట్ సృష్టించండి:
const now = new Date(); let hour = now.getHours(); let minute = now.getMinutes(); let second = now.getSeconds();
గంటల సమయం ప్రాంతాన్ని గణించి, దాని పొడవు (వెడల్పు యొక్క 50%) మరియు వెడల్పు (వెడల్పు యొక్క 7%) చిత్రీకరించండి:
hour = hour%12; hour = (hour*Math.PI/6)+(minute*Math.PI/(6*60))+(second*Math.PI/(360*60)); drawHand(ctx, hour, radius*0.5, radius*0.07);
అదే టెక్నిక్తో గంటల మరియు నిమిషం జాయిడ్స్ చిత్రీకరించబడతాయి.
drawHand() ప్రక్రియ సమాచారం కావాలేదు. దానిద్వారా నిర్దేశించబడిన పొడవు మరియు వెడల్పు యొక్క రేఖ చిత్రీకరించబడుతుంది.