کانواس کلک نمبر

ਦੂਜਾ ਹਿੱਸਾ - ਘੜੀ ਦੇ ਚਿੱਤਰਨ

ਘੜੀ ਨੂੰ ਘੜੀ ਦੇ ਚਿੱਤਰਨ ਲਈ ਇੱਕ JavaScript ਫੰਕਸ਼ਨ ਬਣਾਓ:

JavaScript:

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');

ਸੁਝਾਅ: ਇਹ ਤਿੰਨ ਰੰਗ ਸੰਜਮ ਤਿੰਨ ਡਿਜੀਟਲ ਪ੍ਰਭਾਵ ਪੈਦਾ ਕਰਦੇ ਹਨ。

ਰੈਗੈਡੀਅਨ ਨੂੰ ਡਿਜ਼ਾਇਨ ਵਸਤੂ ਦੇ ਪੇਂਟ ਸਟਾਈਲ ਵਜੋਂ ਪਰਿਭਾਸ਼ਿਤ ਕਰੋ:

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();

ایک بار دیکھو:

کدوو3 سی کام کا پورا کینواس مراجع میکسی