html5中canvas繪製矩形
<!DOCTYPE html>
<html>
<head>
<meta charset="UTF-8">
<title>canvas的例子(矩形)</title>
</head>
<body>
<canvas id="myCanvas" width="700" height="300"></canvas>
<!--
context是一個封裝了很多繪圖功能的物件,canvas元素繪製影象的時候有兩種方法,
context.fill() //填充
context.stroke() //繪製邊框
style:在進行圖形繪製前,要設定好繪圖的樣式
context.fillStyle //填充的樣式
context.strokeStyle //邊框樣式
context.lineWidth //圖形邊框寬度
顏色表示:英文名,十六進位制,rgb,rgba(1-255,1-255,1-255,透明度)
繪製矩形:
context.fillRect(x,y,width,height)
context.strokeRect(x,y,width,height)
-->
<script type="text/javascript">
var canvas=document.getElementById("myCanvas");
var context=canvas.getContext('2d');
//預設填充黑色 fillStyle=black
context.fillRect(0,0,100,100);
//預設黑色邊框strokeStyle
context.strokeRect(100,100,100,100);
//設定純色
context.fillStyle="chartreuse";
context.strokeStyle="blue";
context.fillRect(0,200,100,100);
context.strokeRect(300,100,100,100);
//設定透明度,在0-1之間,值越低越透明
context.fillStyle="rgba(255,0,0,0.1)";
context.strokeStyle="rgba(100,124,0,0.7)";
context.fillRect(200,200,100,100);
context.strokeRect(500,100,100,100);
context.fillStyle="cornflowerblue";
context.fillRect(200,0,100,100);
context.fillStyle="fuchsia";
context.fillRect(400,0,100,100);
context.fillStyle="darkorange";
context.fillRect(400,200,100,100);
context.fillStyle="cadetblue";
context.fillRect(600,0,100,100);
context.fillStyle="crimson";
context.fillRect(600,200,100,100);
context.strokeStyle="darkgray";
context.strokeRect(0,0,700,300);
//清除矩形區域
context.fillStyle="aliceblue";
context.clearRect(150,50,400,200);
</script>
</body>
</html>
<html>
<head>
<meta charset="UTF-8">
<title>canvas的例子(矩形)</title>
</head>
<body>
<canvas id="myCanvas" width="700" height="300"></canvas>
<!--
context是一個封裝了很多繪圖功能的物件,canvas元素繪製影象的時候有兩種方法,
context.fill() //填充
context.stroke() //繪製邊框
style:在進行圖形繪製前,要設定好繪圖的樣式
context.fillStyle //填充的樣式
context.strokeStyle //邊框樣式
context.lineWidth //圖形邊框寬度
顏色表示:英文名,十六進位制,rgb,rgba(1-255,1-255,1-255,透明度)
繪製矩形:
context.fillRect(x,y,width,height)
context.strokeRect(x,y,width,height)
-->
<script type="text/javascript">
var canvas=document.getElementById("myCanvas");
var context=canvas.getContext('2d');
//預設填充黑色 fillStyle=black
context.fillRect(0,0,100,100);
//預設黑色邊框strokeStyle
context.strokeRect(100,100,100,100);
//設定純色
context.fillStyle="chartreuse";
context.strokeStyle="blue";
context.fillRect(0,200,100,100);
context.strokeRect(300,100,100,100);
//設定透明度,在0-1之間,值越低越透明
context.fillStyle="rgba(255,0,0,0.1)";
context.strokeStyle="rgba(100,124,0,0.7)";
context.fillRect(200,200,100,100);
context.strokeRect(500,100,100,100);
context.fillStyle="cornflowerblue";
context.fillRect(200,0,100,100);
context.fillStyle="fuchsia";
context.fillRect(400,0,100,100);
context.fillStyle="darkorange";
context.fillRect(400,200,100,100);
context.fillStyle="cadetblue";
context.fillRect(600,0,100,100);
context.fillStyle="crimson";
context.fillRect(600,200,100,100);
context.strokeStyle="darkgray";
context.strokeRect(0,0,700,300);
//清除矩形區域
context.fillStyle="aliceblue";
context.clearRect(150,50,400,200);
</script>
</body>
</html>
相關文章
- canvas 繪製矩形Canvas
- HTML5 Canvas ( 矩形的繪製 ) rect, strokeRect, fillRectHTMLCanvas
- HTML5利用canvas繪製矩形程式碼例項HTMLCanvas
- canvas 繪製圓角矩形Canvas
- canvas 繪製矩形缺角Canvas
- canvas繪製矩形框Canvas
- canvas系列教程之繪製矩形Canvas
- canvas實現手動繪製矩形Canvas
- html5中canvas繪製圓形HTMLCanvas
- html5中canvas繪製線段HTMLCanvas
- html5中canvas線段繪製太陽花HTMLCanvas
- 微信小程式 canvas圓角矩形的繪製微信小程式Canvas
- canvas繪製圓角矩形程式碼例項Canvas
- html5中canvas繪製貝塞爾曲線HTMLCanvas
- canvas 繪製旋轉一定角度的矩形Canvas
- html5中canvas貝塞爾曲線繪製菊花HTMLCanvas
- html5中的canvas繪製橢圓的方法HTMLCanvas
- html5 canvas學習--繪製文字HTMLCanvas
- HTML5使用canvas繪製圖形HTMLCanvas
- canvas學習筆記-繪製矩形及路徑(一)Canvas筆記
- 原來 Canvas 也能直接繪製圓角矩形了Canvas
- canvas繪製旋轉一定角度的矩形效果Canvas
- canvas繪製矩形並填充顏色程式碼例項Canvas
- 使用 HTML5 Canvas 繪製的水滴效果HTMLCanvas
- SVG <rect> 繪製矩形SVG
- HTML5 Canvas使用路徑——繪製圓形HTMLCanvas
- SVG 繪製圓角矩形SVG
- HTML5 Canvas(實戰:繪製餅圖2 Tooltip)HTMLCanvas
- canvas 繪製扇形Canvas
- canvas 繪製文字Canvas
- 繪製SVG內容到Canvas的HTML5應用SVGCanvasHTML
- 在Canvas中繪製Geojson資料CanvasJSON
- canvas 繪製線條Canvas
- canvas 繪製圓形Canvas
- canvas繪製流星效果Canvas
- canvas繪製直線Canvas
- JavaScript拖動滑鼠繪製矩形方框JavaScript
- Python 在PDF中繪製線條、矩形、橢圓形Python