不显示,请帮看看错在哪里?

来源:5-3 使用图片、画布或者video

v小方

2016-03-31 17:03

<canvas id="canvas" style="border:1px solid #aaa; display:block; margin:50 auto;">

    浏览器不支持Canvas,请更换浏览器再试

    </canvas>

    

    <script>

window.onload = function () {

var canvas = document.getElementById("canvas");

canvas.width = 800;

canvas.height = 800;

var context = canvas.getContext("2d");

var backCanvas = createBackgroundCanvas();

var pattern = context.createPattern(backCanvas, "repeat");

context.fillStyle = pattern;

context.fillRect(0, 0, 800, 800);

}

function createBackgroundCanvas() {

var backCanvas = document.createElement("canvas");

backCanvas.width = 100;

backCanvas.height = 100;

var backCanvasContext = backCanvas.getContext("2d");

drawStar(backCanvasContext, 50, 50, 50, 0);

return backCanvas;

}

function drawStar(cxt, x, y, R, rot) {


cxt.save();

cxt.translate(x, y);

cxt.rotate(rot / 180 * Math.PI);

cxt.scale(R, R);

starPath(cxt);

cxt.fillStyle = "#fb3";

cxt.lineJoin = "round";

cxt.fill();

cxt.restore();

}

</script>


写回答 关注

1回答

  • v小方
    2016-03-31 23:46:37

    终于找开了,starPath(cxt);未定义

Canvas绘图详解

Canvas系列教程第二课,详解Canvas各接口,让同学彻底掌握Canvas绘图

72881 学习 · 422 问题

查看课程

相似问题