jinming7981
幼苗
共回答了20个问题采纳率:95% 举报
html:CSS:#c{
background-color:rgba(134, 179, 225, 1);
}JS:
window.onload = init;
var ctx = null;
var recX = 150,
recY = 150,
angle = -35;
function init() {
var cvs = document.getElementById('c');
ctx = cvs.getContext('2d');
drawRectangle();
drawCircle(-100, 0, 50, '#fff');
drawCircle(100, 0, 50, 'rgba(134, 179, 225, 1)');
}
function setPos() {
ctx.translate(recX, recY);
ctx.rotate(angle * Math.PI / 180);
}
function drawRectangle() {
ctx.save();
setPos();
ctx.fillStyle = '#fff';
ctx.fillRect(-100, -50, 200, 100);
ctx.restore();
}
function drawCircle(x, y, r, fillStyle) {
ctx.save();
ctx.beginPath();
setPos();
ctx.fillStyle = fillStyle;
ctx.arc(x, y, r, 0, Math.PI * 2, true);
ctx.closePath();
ctx.fill();
ctx.restore();
}
1年前
3