<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta http-equiv="X-UA-Compatible" content="IE=edge">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>Canvas</title>
</head>
<body>
<h1>繪圖</h1>
<canvas id="test_canvas" width="400" height="300" style="border: red 2px solid;">
</canvas>
<script>
function getDistance(a1, b1, a2, b2) {
return Math.sqrt((a1 - a2) ^ 2 + (b1 - b2) ^ 2)
}
var x1 = Math.random() * 300;
var y1 = Math.random() * 300;
var x2 = Math.random() * 300;
var y2 = Math.random() * 300;
var x3 = Math.random() * 300;
var y3 = Math.random() * 300;
var dataStr = `A點(diǎn):(${x1},$0{y1}), B點(diǎn):(${x2},${y2}), C點(diǎn):(${x3},${y3}),`
console.log(dataStr);
console.log(getDistance(x1, y1, x2, y2));
var test_canvas = document.getElementById("test_canvas")
var ctx = test_canvas.getContext('2d')
// ctx.fillStyle = "#dddddd"; //設(shè)置顏色
// ctx.fillRect(10, 10, 130, 130); //畫矩形
ctx.fillStyle = "#A60000";
// ctx.fillRect(40, 40,180, 130)
ctx.beginPath();
ctx.moveTo(x1, y1);
ctx.lineTo(x2, y2);
ctx.lineTo(x3, y3);
ctx.stroke();
</script>
</body>
</html>
canvas的使用
?著作權(quán)歸作者所有,轉(zhuǎn)載或內(nèi)容合作請聯(lián)系作者
【社區(qū)內(nèi)容提示】社區(qū)部分內(nèi)容疑似由AI輔助生成,瀏覽時(shí)請結(jié)合常識與多方信息審慎甄別。
平臺聲明:文章內(nèi)容(如有圖片或視頻亦包括在內(nèi))由作者上傳并發(fā)布,文章內(nèi)容僅代表作者本人觀點(diǎn),簡書系信息發(fā)布平臺,僅提供信息存儲服務(wù)。
【社區(qū)內(nèi)容提示】社區(qū)部分內(nèi)容疑似由AI輔助生成,瀏覽時(shí)請結(jié)合常識與多方信息審慎甄別。
平臺聲明:文章內(nèi)容(如有圖片或視頻亦包括在內(nèi))由作者上傳并發(fā)布,文章內(nèi)容僅代表作者本人觀點(diǎn),簡書系信息發(fā)布平臺,僅提供信息存儲服務(wù)。
相關(guān)閱讀更多精彩內(nèi)容
- 文章轉(zhuǎn)載自眾成翻譯,原文鏈接https://www.zcfy.cc/article/offscreencanvas...
- canvas標(biāo)簽用于繪制圖像(通過腳本,通常是 JavaScript)。 1、getContext() 方法可返回...
- 話不多說,在實(shí)際項(xiàng)目中生成截圖是很常見的需求,而一般的,我們都會選擇使用js庫來自動(dòng)生成(從頭造輪子太難了...)...
- 關(guān)鍵網(wǎng)站:https://transfonter.org/傳上去字體,設(shè)置一下幾個(gè)地方 點(diǎn)Download下載下來...