Canvas ຕົວແຫຼວປະຕູ
ບົດທີສອງ - ການສະແດງເວລາ:
ວົງວຽນຕ້ອງມີເວລາ. ສ້າງຫົວຫນ້າ 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');
ຄຳແນະນຳ: ສາມເຄື່ອງສັນສີນັ້ນສາມາດການສະແດງ 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();