<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8" />
<meta name="viewport" content="width=device-width, initial-scale=1.0" />
<title>canvas 顏色</title>
<style>
#canvas {
background-color: #f9f9f9;
}
</style>
</head>
<body>
<canvas id="canvas">瀏覽器不支持 canvas </canvas>
</body>
<script>
var canvas = document.getElementById("canvas");
var ctx = canvas.getContext("2d");
canvas.height = 500;
canvas.width = 500;
// 填充 描邊 - 純色
ctx.fillStyle = "red";
ctx.strokeStyle = "green";
ctx.lineWidth = 5;
ctx.fillRect(20, 20, 100, 100);
ctx.strokeRect(20, 20, 100, 100);
// 填充 描邊 - 漸變色
// 圓形漸變:ctx.createRadialGradient(x0, y0, r0, x1, y1, r1) // 開始和結(jié)束圓的 橫、縱、半徑
var radial = ctx.createRadialGradient(320, 70, 0, 320, 70, 60);
radial.addColorStop(0, "red");
radial.addColorStop(1, "green");
ctx.fillStyle = radial;
// 線性漸變:ctx.createRadialGradient(x0, y0, x1, y1) // 開始和結(jié)束點(diǎn)的 橫、縱
var linear = ctx.createLinearGradient(200, 70, 420, 70);
linear.addColorStop(0, "red");
linear.addColorStop(1, "green");
ctx.strokeStyle = linear;
ctx.lineWidth = 10;
ctx.fillRect(220, 20, 200, 100);
ctx.strokeRect(220, 20, 200, 100);
</script>
</html>
canvas 顏色 繪制
?著作權(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)書系信息發(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)書系信息發(fā)布平臺(tái),僅提供信息存儲(chǔ)服務(wù)。
相關(guān)閱讀更多精彩內(nèi)容
- fillStyle 屬性設(shè)置或返回用于填充繪畫的顏色、漸變或樣式 strokeStyle 屬性設(shè)置或返回用于筆觸的...
- 應(yīng)用場(chǎng)景:在很多時(shí)候,前端開發(fā)過(guò)程中需要?jiǎng)討B(tài)的獲取圖片的主要的顏色值,并根據(jù)主色調(diào)去調(diào)整主題樣式的顏色或者模擬出一...
- fn1(){ var myChart = echarts.init(document.getElementById...
- 自己學(xué)習(xí)用學(xué)習(xí)Canvas時(shí)候 首先了解Canvas的坐標(biāo) 基本格式 繪制直線 多邊形 注意: 在沒(méi)有用 cxt...