1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146
| getContext('2d')
fillStyle('rgba(0, 0, 0, .5)') strokeStyle = color
fillRect(x, y, width, height)
strokeRect(x, y, width, height)
clearRect(x, y, width, height)
beginPath() closePath() stroke() fill()
moveTo(x, y)
lineTo(x, y)
arc(x, y, radius, startAngle, endAngle, anticlockwise)
quadraticCurveTo(cp1x, cp1y, x, y)
bezierCurveTo(cp1x, cp1y, cp2x, cp2y, x, y)
function draw() { var canvas = document.getElementById('canvas'); if (canvas.getContext){ var ctx = canvas.getContext('2d');
var rectangle = new Path2D(); rectangle.rect(10, 10, 50, 50);
var circle = new Path2D(); circle.moveTo(125, 35); circle.arc(100, 35, 25, 0, 2 * Math.PI);
ctx.stroke(rectangle); ctx.fill(circle); } }
globalAlpha = transparencyValue
fillText(text, x, y [, maxWidth])
drawImage(image, sx, sy, sWidth, sHeight, dx, dy, dWidth, dHeight)
function draw() { var ctx = document.getElementById('canvas').getContext('2d');
ctx.fillRect(0,0,150,150); ctx.save();
ctx.fillStyle = '#09F' ctx.fillRect(15,15,120,120);
ctx.save(); ctx.fillStyle = '#FFF' ctx.globalAlpha = 0.5; ctx.fillRect(30,30,90,90);
ctx.restore(); ctx.fillRect(45,45,60,60);
ctx.restore(); ctx.fillRect(60,60,30,30); }
function draw() { var ctx = document.getElementById('canvas').getContext('2d'); for (var i = 0; i < 3; i++) { for (var j = 0; j < 3; j++) { ctx.save(); ctx.fillStyle = 'rgb(' + (51 * i) + ', ' + (255 - 51 * i) + ', 255)'; ctx.translate(10 + j * 50, 10 + i * 50); ctx.fillRect(0, 0, 25, 25); ctx.restore(); } } }
function draw() { var ctx = document.getElementById('canvas').getContext('2d'); ctx.translate(75,75);
for (var i=1;i<6;i++){ ctx.save(); ctx.fillStyle = 'rgb('+(51*i)+','+(255-51*i)+',255)';
for (var j=0;j<i*6;j++){ ctx.rotate(Math.PI*2/(i*6)); ctx.beginPath(); ctx.arc(0,i*12.5,5,0,Math.PI*2,true); ctx.fill(); }
ctx.restore(); } }
function draw() { var ctx = document.getElementById('canvas').getContext('2d');
ctx.save(); ctx.scale(10, 3); ctx.fillRect(1, 10, 10, 10); ctx.restore();
ctx.scale(-1, 1); ctx.font = '48px serif'; ctx.fillText('MDN', -135, 120); }
function draw() { var ctx = document.getElementById('canvas').getContext('2d');
var sin = Math.sin(Math.PI/6); var cos = Math.cos(Math.PI/6); ctx.translate(100, 100); var c = 0; for (var i=0; i <= 12; i++) { c = Math.floor(255 / 12 * i); ctx.fillStyle = "rgb(" + c + "," + c + "," + c + ")"; ctx.fillRect(0, 0, 100, 10); ctx.transform(cos, sin, -sin, cos, 0, 0); } ctx.setTransform(-1, 0, 0, 1, 100, 100); ctx.fillStyle = "rgba(255, 128, 255, 0.5)"; ctx.fillRect(0, 50, 100, 100); }
globalCompositeOperation = type
clip()
setInterval(function, delay) setTimeout(function, delay) window.requestAnimationFrame() // 告诉浏览器——你希望执行一个动画,并且要求浏览器在下次重绘之前调用指定的回调函数更新动画。该方法需要传入一个回调函数作为参数,该回调函数会在浏览器下一次重绘之前执行。这个方法提供了更加平缓并更加有效率的方式来执行动画,当系统准备好了重绘条件的时候,才调用绘制动画帧。
|