CSS3-Canvas畫布(圖形-三角形)


<!DOCTYPE html5>
<html lang="en">
<head>
<meta charset="UTF-8">
<title>CSS3-Canvas畫布(圖形-三角形)</title>
<script>
window.onload=function () {

var canvas=document.getElementById("canvas");//獲取canvas對象

var ctx=canvas.getContext("2d"); //創建二維的繪圖上下文對象

ctx.beginPath();
ctx.linewidth=20;
ctx.lineJoin="round"; //兩條線交匯時的邊角類型(miter 尖角默認 bevel斜角 round 圓角 )
ctx.moveTo(10,10);
ctx.lineTo(100,100);
ctx.lineTo(400,10);
// ctx.lineTo(10,10);
ctx.closePath(); //closePath() 關閉路徑 閉合
ctx.strokeStyle="blue";// strokeStyle 只能填充該路徑的顏色
ctx.fillStyle="red";// fillStyle 填充字體顏色、填充路徑區域、圖形區域
ctx.fill();// fill() 填充字體
ctx.stroke();
}
</script>
</head>
<body>
<h2>Canvas畫布(圖形)</h2>
<canvas id="canvas" width="500" height="500" style="border:1px solid red ">
瀏覽器不支持canvas
</canvas>
</body>
</html>


免責聲明!

本站轉載的文章為個人學習借鑒使用,本站對版權不負任何法律責任。如果侵犯了您的隱私權益,請聯系本站郵箱yoyou2525@163.com刪除。



 
粵ICP備18138465號   © 2018-2025 CODEPRJ.COM