0

How to make shape generator?

I am missing something here and dont know what. function draw_shape(x, y, color, w, h) { this.x = x; this.y = y; this.color = color; this.width = w; this.height = h; color = ctx.fillStyle; ctx.fillRect(ctx.x, ctx.y, height, width); } draw_shape(20, 40, "red", 100, 75);

31st Jul 2022, 3:59 AM
pHANTOM|sTEELE
2 Respuestas
+ 1
pHANTOM|sTEELE You missed to get canvas object 'ctx' and also should be ctx.fillStyle = color; x, y are not exist in ctx so ctx.x and ctx.y are wrong. define 'canvas' element in html. <canvas id = 'canvas'></canvas> function draw_shape(x, y, color, w, h) { var canvas = document.getElementById('canvas'); var ctx = canvas.getContext('2d'); this.x = x; this.y = y; this.color = color; this.width = w; this.height = h; ctx.fillStyle = color; ctx.fillRect(x, y, height, width); } window.onload = function () { draw_shape(20, 40, "red", 100, 75); }
31st Jul 2022, 5:02 AM
A͢J
A͢J - avatar
+ 1
yea thx had that backwards...
31st Jul 2022, 5:45 AM
pHANTOM|sTEELE