<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<title>hello</title>
</head>
<body>
<canvas width="600px" height="600px" id="mycanvas"></canvas>
<script type="text/javascript">
var canvas=document.getElementById('mycanvas');
if(canvas.getContext){
var ctx=canvas.getContext('2d');
}
////繪制線
ctx.beginPath();
ctx.moveTo(50,50);
ctx.lineTo(100,100);
ctx.lineTo(80,90);
ctx.lineWidth=2;
//線條顏色
ctx.strokeStyle='#ff0000';
ctx.stroke();
////繪制矩形(實(shí)心)
ctx.clearRect(60,50,20,20);
//清除指定矩形區(qū)域
ctx.fillRect(160,150,70,80);
ctx.strokeStyle='orange'
ctx.strokeRect(170,160,50,50);
////繪制文本
ctx.font='Bold 20px Arial';
ctx.textAlign='left';
ctx.fillStyle='brown';
ctx.fillText('hello canvas',0,200);
////繪制空心文本
ctx.strokeStyle='gray';
ctx.strokeText('hello.canvas',0,260);
////繪制圓
ctx.beginPath();
ctx.arc(80,360,40,0,Math.PI*2,true);
ctx.fillStyle='yellow';
ctx.fill();
////繪制空心圓
ctx.beginPath();
ctx.arc(180,360,40,0,Math.PI*2,true);
ctx.strokeStyle='green';
ctx.lineWidth=1.0;
ctx.stroke();
////繪制漸變色,填充矩形
var myGradient=ctx.createLinearGradient(0,700,160,160);
myGradient.addColorStop(0,'red');
myGradient.addColorStop(1,'yellow');
ctx.fillStyle=myGradient;
//繪制陰影
ctx.shadowOffsetX=2;
ctx.shadowOffsetY=2;
ctx.shadowBlur=3;
ctx.shadowColor='rgba(22,22,22,.5)';
ctx.fillRect(0,420,160,160);
</script>
</body>
</html>
H5-canvas 入門(mén)
最后編輯于 :
?著作權(quán)歸作者所有,轉(zhuǎn)載或內(nèi)容合作請(qǐng)聯(lián)系作者
【社區(qū)內(nèi)容提示】社區(qū)部分內(nèi)容疑似由AI輔助生成,瀏覽時(shí)請(qǐng)結(jié)合常識(shí)與多方信息審慎甄別。
平臺(tái)聲明:文章內(nèi)容(如有圖片或視頻亦包括在內(nèi))由作者上傳并發(fā)布,文章內(nèi)容僅代表作者本人觀點(diǎn),簡(jiǎn)書(shū)系信息發(fā)布平臺(tái),僅提供信息存儲(chǔ)服務(wù)。
【社區(qū)內(nèi)容提示】社區(qū)部分內(nèi)容疑似由AI輔助生成,瀏覽時(shí)請(qǐng)結(jié)合常識(shí)與多方信息審慎甄別。
平臺(tái)聲明:文章內(nèi)容(如有圖片或視頻亦包括在內(nèi))由作者上傳并發(fā)布,文章內(nèi)容僅代表作者本人觀點(diǎn),簡(jiǎn)書(shū)系信息發(fā)布平臺(tái),僅提供信息存儲(chǔ)服務(wù)。
相關(guān)閱讀更多精彩內(nèi)容
- 在這之前 你需要了解一下方法的使用: beginPath() closePath() moveTo() lineT...
- canvas用于在網(wǎng)頁(yè)上繪制圖形。(通常通過(guò)腳本語(yǔ)言javascript) 1.在HTML中創(chuàng)建 2.在js中獲取...
- 簡(jiǎn)介 是 HTML5 新增的元素之一,它允許腳本語(yǔ)言動(dòng)態(tài)渲染位圖像。最初是由 Apple 引入,用于 Mac OS...
- 在這之前 需要你懂得以下方法的使用: beginPath() moveTo() lineTo() closePat...