console
function draw() {
var canvas = document.getElementById('mycanvas');
if (canvas.getContext) {
var ctx = canvas.getContext('2d');
ctx.beginPath()
ctx.fillStyle = "red"
ctx.arc(75, 25, 8, 0, 2 * Math.PI)
ctx.closePath()
ctx.fill()
ctx.beginPath()
ctx.fillStyle = "green"
ctx.arc(25, 25, 8, 0, 2 * Math.PI);
ctx.closePath()
ctx.fill()
ctx.beginPath()
ctx.fillStyle = "orange"
ctx.arc(25, 62.5, 8, 0, 2 * Math.PI);
ctx.closePath()
ctx.fill()
ctx.beginPath()
ctx.fillStyle = "blue"
ctx.arc(25, 100, 8, 0, 2 * Math.PI);
ctx.closePath()
ctx.fill()
ctx.beginPath()
ctx.fillStyle = "pink"
ctx.arc(50, 100, 8, 0, 2 * Math.PI);
ctx.closePath()
ctx.fill()
ctx.beginPath()
ctx.fillStyle = "yellow"
ctx.arc(50, 120, 8, 0, 2 * Math.PI);
ctx.closePath()
ctx.fill()
ctx.beginPath()
ctx.fillStyle = "silver"
ctx.arc(30, 125, 8, 0, 2 * Math.PI);
ctx.closePath()
ctx.fill()
ctx.beginPath()
ctx.fillStyle = "purple"
ctx.arc(60, 120, 8, 0, 2 * Math.PI);
ctx.closePath()
ctx.fill()
ctx.beginPath()
ctx.fillStyle = "white"
ctx.arc(65, 100, 8, 0, 2 * Math.PI);
ctx.closePath()
ctx.fill()
ctx.beginPath()
ctx.fillStyle = "grey"
ctx.arc(125, 100, 8, 0, 2 * Math.PI);
ctx.closePath()
ctx.fill()
ctx.beginPath()
ctx.fillStyle = "brown"
ctx.arc(125, 62.5, 8, 0, 2 * Math.PI);
ctx.closePath()
ctx.fill()
ctx.beginPath()
ctx.fillStyle = "lavender"//熏衣色
ctx.arc(125, 25, 8, 0, 2 * Math.PI);
ctx.closePath()
ctx.fill()
ctx.beginPath()
ctx.fillStyle = "red"
ctx.arc(75, 25, 8, 0, 2 * Math.PI);
ctx.closePath()
ctx.fill()
// 二次贝塞尔曲线
ctx.beginPath();
ctx.moveTo(75, 25);
ctx.quadraticCurveTo(25, 25, 25, 62.5);
ctx.quadraticCurveTo(25, 100, 50, 100);
ctx.quadraticCurveTo(50, 120, 30, 125);
ctx.quadraticCurveTo(60, 120, 65, 100);
ctx.quadraticCurveTo(125, 100, 125, 62.5);
ctx.quadraticCurveTo(125, 25, 75, 25);
ctx.stroke();
}
}
window.onload = () => {
draw()
}
/*
quadraticCurveTo(cp1x, cp1y, x, y)
绘制二次贝塞尔曲线,cp1x,cp1y为一个控制点,x,y为结束点。
*/
<div class="drawWrapper">
<canvas id="mycanvas" width="200" height="200"></canvas>
</div>
.drawWrapper #mycanvas {
border: 1px solid black;
}