ကင်းဗတ် နာရီ
ဤအခန်းများတွင် HTML canvas ကို အသုံးပြု၍ analog နာရီတစ်ခုကို တည်ဆောက်ပါမည်။
အပိုင်း ၁ - Canvas ဖန်တီးပါ။
နာရီသည် HTML ကွန်တိန်နာတစ်ခု လိုအပ်သည်။ HTML ကင်းဗတ်တစ်ခုကို ဖန်တီးပါ-
HTML ကုဒ်
<!DOCTYPE html>
<html>
<body>
<canvas id="canvas" width="400"
height="400" style="background-color:#333"></canvas>
<script>
var canvas = document.getElementById("canvas");
var ctx = canvas.getContext("2d");
var radius = canvas.height / 2;
ctx.translate(radius, radius);
radius = radius * 0.90
drawClock();
function drawClock() {
ctx.arc(0, 0, radius, 0 , 2 * Math.PI);
ctx.fillStyle = "white";
ctx.fill();
}
</script>
</body>
</html>
ကုဒ်ဖြင့် ရှင်းပြထားသည်။
သင့်စာမျက်နှာသို့ HTML <canvas> အစိတ်အပိုင်းတစ်ခုကို ထည့်ပါ-
<canvas id="canvas" width="400"
height="400" style="background-color:#333"></canvas>
HTML ကင်းဗတ်ဒြပ်စင်မှ ပတ္တူအရာဝတ္ထု (var canvas) ဖန်တီးပါ-
var canvas =
document.getElementById("canvas");
ပတ္တူအရာဝတ္တုအတွက် 2d ပုံဆွဲသောအရာ (var ctx) ဖန်တီးပါ-
var ctx = canvas.getContext("2d");
ကင်းဗတ်စ်၏အမြင့်ကို အသုံးပြု၍ နာရီအချင်းဝက်ကို တွက်ချက်ပါ-
var radius
= canvas.height / 2;
နာရီအချင်းဝက်ကို တွက်ချက်ရန် ကင်းဗတ်အမြင့်ကို အသုံးပြု၍ ကင်းဗတ်အရွယ်အစားအားလုံးအတွက် နာရီကို အလုပ်လုပ်စေသည်။
ကင်းဗတ်စ်၏ အလယ်ဗဟိုသို့ (0.0) အနေအထား (ပုံဆွဲအရာဝတ္တု၏) ကို ပုံဖော်ပါ။
ctx.translate(radius, radius);
နာရီကို ကင်းဗတ်စ်အတွင်း ကောင်းမွန်စွာဆွဲရန် နာရီအချင်းဝက် (90%) သို့ လျှော့ချပါ-
radius = radius * 0.90;
နာရီကိုဆွဲရန် လုပ်ဆောင်ချက်တစ်ခုကို ဖန်တီးပါ။
function drawClock() {
ctx.arc(0, 0, radius, 0 , 2 * Math.PI);
ctx.fillStyle =
"white";
ctx.fill();
}