Author: Knida

Hello 1/2562

Hello 1/2562

สวัสดค่ะเด็ก ๆ ยินดีต้อนรับทุกคนสู่เทอมใหม่นะคะ บางคนก็เป็นนิสิตใหม่ ปี 1 บางคนก็ขึ้นเป็นรุ่นพี่แล้ว ขอให้ทุกคนตั้งใจเรียนรู้ เล่น อย่างเป็นระบบนะคะ

เป็นกำลังใจให้ทุกคนค่ะ

Draw a Circle using javaScript

วาดภาพวงกลม
[html]
<!DOCTYPE html>
<html>
<body>
<canvas id="myCanvas" width="300" height="300" style="border:1px solid #d3d3d3;">
Your browser does not support the HTML5 canvas tag.</canvas>
<script>
var c = document.getElementById("myCanvas");
var ctx = c.getContext("2d");
var centerX = c.width / 2;
var centerY = c.height / 2;
var radius = 70;
var color =0;
function drawCircle(){
ctx.fillStyle = ‘TOMATO’;
ctx.beginPath();
ctx.arc(centerX, centerY, radius, 0, 2 * Math.PI);
ctx.fill();
ctx.lineWidth = 2;
ctx.strokeStyle = ‘RED’;
ctx.stroke();
}
drawCircle();
</script></p>
</body>
</html>
[/html]

Growing a Circle

มาวาดวงกลมด้วย JavaScript ที่มีรัศมีตั้งแต่ 0 – 70 กัน กำหนดให้เป็น Animation โดยใช้
[js] requestAnimationFrame(drawCircle); [/js]
 
[html]</pre>
<!DOCTYPE html>
<html>
<body>
<canvas id="myCanvas" width="300" height="300" style="border:1px solid #d3d3d3;">
Your browser does not support the HTML5 canvas tag.</canvas>
<script>
var c = document.getElementById("myCanvas");
var ctx = c.getContext("2d");
var centerX = c.width / 2;
var centerY = c.height / 2;
var radius = 0;
var color =0;
function drawCircle(){
ctx.fillStyle = ‘hsl(‘+color++ +’,100%,50%)’;
ctx.beginPath();
ctx.arc(centerX, centerY, radius, 0, 2 * Math.PI);
ctx.fill();
radius += 1;
if(radius<100){
requestAnimationFrame(drawCircle);
}
ctx.lineWidth = 2;
ctx.strokeStyle = ‘RED’;
ctx.stroke();
}
drawCircle();
</script>
</body>
</html>
[/html]