XML/HTML CodeCopy content to clipboard
- var canvas = document.getElementById('canvas');
- if (canvas.getContext) {
-
var context = canvas.getContext('2d');
- // Line width
-
context.lineWidth = 4;
- // Brush color
-
context.strokeStyle = 'red';
- // Fill color
-
context.fillStyle = "red";
- // Line cap type
-
context.lineCap = 'butt'; // round, square
- // Start path
- context.beginPath();
- // Starting point
- context.moveTo(10,10);
- // End point
- context.lineTo(150,50);
- // Drawing
- context.stroke();
- }
XML/HTML CodeCopy content to clipboard
- var canvas = document.getElementById('canvas');
- if (canvas.getContext) {
- context.beginPath();
- context.strokeRect(10,10,70,40);
- // Another way of rectangle
- context.rect(10,10.70,40);
- context.stroke();
-
- // solid rectangle
- context.beginPath();
- context.fillRect(10,10,70,40);
- // Another way solid rectangle
- context.beginPath();
- context.rect(10,10,70,40);
- context.fill();
- }
XML/HTML CodeCopy content to clipboard
- var canvas = document.getElementById('canvas');
- if (canvas.getContext) {
- context.beginPath();
- // Circle center coordinate x, circle center coordinate Y, arc radius, starting angle, ending angle, whether counterclockwise
- // The fourth and fifth parameters are the radians to be passed in. If you draw an angle of 30, you need to convert it into radians 30 * Math.PI / 180
- context.arc(100,100,70,0,130 * Math.PI / 180, true);
- context.stroke();
- context.fill();
- }
XML/HTML CodeCopy content to clipboard
- var canvas = document.getElementById('canvas');
- if (canvas.getContext) {
- context.beginPath();
- context.moveTo(20,20);
- context.lineTo(70,20);
- // Draw arc p1.x p1.y p2.x, p2.y arc radius for a path,
- context.arcTo(120,30,120,70, 50);
- context.lineTo(120,120);
- context.stroke();
-
- // Erase canvas artboard
- context.beginPath();
- context.fillRect(10,10,200,100);
-
- // Erase area
- context.clearRect(30,30,50,50);
- }
XML/HTML CodeCopy content to clipboard
- var canvas = document.getElementById('canvas');
- if (canvas.getContext) {
- context.beginPath();
- context.moveTo(100,100);
- context.quadraticCurveTo(20,50,200,20);
- context.stroke();
- }
XML/HTML CodeCopy content to clipboard
- var canvas = document.getElementById('canvas');
- if (canvas.getContext) {
- context.moveTo(68,130);
-
var cX1 = 20;
-
var cY1 = 10;
-
var cX2 = 268;
-
var cY2 = 10;
-
var endX = 268;
-
var endY = 170;
- context.bezierCurveTo(cX1, cY1, cX2, cY2, endX, endY);
- context.stroke();
-
- // 利用clip指定绘图区域,指定绘图区域之后,只能在绘图区域中进行绘图擦欧总
- // 绘制圆形
- context.arc(100,100,40,0, 360 * Math.PI/ 180 , true);
- // 限制区域
- context.clip();
- // 开始尝试绘制其他
- context.beginPath();
-
context.fillStyle = 'lightblue';
- // 结果矩形并没有显示出来
- context.fillRect(0,0,300,150);
- }