I'm trying to draw rectangles on a HTML5 canvas. I managed to draw on the canvas but I need to do it dynamically.
x, y: coordinates of the position of the rectangle in the canvas-element.
w: width of the rectangle.
h: height of the rectangle.
f: If true, the rectangle filled without a border. If false the rectangle has a border but no filling.
var canvas = document.getElementById("c");
var context = canvas.getContext("2d");
var json = [{
"x": "50",
"y": "50",
"w": "100",
"h": "50",
"f": "true"
},
{
"x": "50",
"y": "150",
"w": "100",
"h": "50",
"f": "false"
}
];
context.beginPath();
for (var i in json) {
context.lineTo(json[i].x, json[i].y, json[i].w, json[i].h, json[i].f)
}
<canvas id="c"></canvas>