小编Bru*_*ise的帖子

怎么画在画布上读一个json?

我试图通过一个HTML5 canvas.我设法画在画布上,但我需要动态地做.这是我的JavaScript代码:

var c=document.getElementById("yellow");
var ctx=c.getContext("2d");

ctx.beginPath();
ctx.moveTo(247,373);
ctx.lineTo(0,390);
ctx.lineTo(5,21);
ctx.lineTo(245,0);
ctx.lineTo(247,373);
ctx.closePath();
ctx.fillStyle="#ffca05";
ctx.globalAlpha=0.7;
ctx.strokeStyle = '#ffca05';
ctx.fill();
ctx.stroke();
Run Code Online (Sandbox Code Playgroud)

我需要从中读取数据json array并使用这些坐标绘制.

[{"x":"247", "y":"373"}, {"x":"0", "y":"390"},{"x":"5", "y":"21"},{"x":"245", "y":"0"}, {"x":"247", "y":"373"}]
Run Code Online (Sandbox Code Playgroud)

html javascript json html5-canvas

6
推荐指数
1
解决办法
4372
查看次数

标签 统计

html ×1

html5-canvas ×1

javascript ×1

json ×1