कैनवस घड़ी नंबर
- पिछला पृष्ठ घड़ी व्याख्या
- अगला पृष्ठ घड़ी नंबर
दूसरा भाग - क्लॉक केंद्र को चित्रित करना
क्लॉक को क्लॉक केंद्र की जरूरत है। क्लॉक केंद्र को चित्रित करने के लिए जेसक्रिप्ट फ़ंक्शन को बनाएं:
जेसक्रिप्ट:
function drawClock() { drawFace(ctx, radius); } function drawFace(ctx, radius) { const grad = ctx.createRadialGradient(0, 0 ,radius * 0.95, 0, 0, radius * 1.05); grad.addColorStop(0, '#333'); grad.addColorStop(0.5, 'white'); grad.addColorStop(1, '#333'); ctx.beginPath(); ctx.arc(0, 0, radius, 0, 2 * Math.PI); ctx.fillStyle = 'white'; ctx.fill(); ctx.strokeStyle = grad; ctx.lineWidth = radius*0.1; ctx.stroke(); ctx.beginPath(); ctx.arc(0, 0, radius * 0.1, 0, 2 * Math.PI); ctx.fillStyle = '#333'; ctx.fill(); }
कोड व्याख्या
क्लॉक केंद्र को चित्रित करने के लिए drawFace() फ़ंक्शन को बनाएं:
function drawClock() { drawFace(ctx, radius); } function drawFace(ctx, radius) { }
सफेद वृत्त को चित्रित करें:
ctx.beginPath(); ctx.arc(0, 0, radius, 0, 2 * Math.PI); ctx.fillStyle = 'white'; ctx.fill();
दूरीवर्ती ग्रेडिएंट (मूल क्लॉक व्यास का 95% और 105%) को बनाएं:
grad = ctx.createRadialGradient(0, 0, radius * 0.95, 0, 0, radius * 1.05);
3 रंगों को बनाएं जो क्रमश: वृत्त के अंतरीच्छवि, मध्यीच्छवि और बाह्यीच्छवि के लिए हैं:
grad.addColorStop(0, '#333'); grad.addColorStop(0.5, 'white'); grad.addColorStop(1, '#333');
टीप: इन तीन रंगों के सहारे 3D इफेक्ट पैदा हो सकते हैं。
ग्रेडिएंट को ड्राइंग ऑब्जेक्ट के स्ट्राइंग स्टाइल के रूप में परिभाषित करें:
ctx.strokeStyle = grad;
ड्राइंग ऑब्जेक्ट की लाइन वाइड्थ (व्यास का 10%) को परिभाषित करें:
ctx.lineWidth = radius * 0.1;
वृत्त आकृति बनाएं:
ctx.stroke();
क्लॉक केंद्र को चित्रित करें:
ctx.beginPath(); ctx.arc(0, 0, radius * 0.1, 0, 2 * Math.PI); ctx.fillStyle = '#333'; ctx.fill();
अन्य संदर्भ
- पिछला पृष्ठ घड़ी व्याख्या
- अगला पृष्ठ घड़ी नंबर