+ 2

Why am i not getting a square?

I am on android phone and ctx.fillRect(posx,posy,posx+5,posy+5); is making a rectangle not square. https://code.sololearn.com/WBOm4adsUrE1/?ref=app

8th Jul 2020, 6:57 AM
Sameer Crestha
Sameer Crestha - avatar
3 Respuestas
+ 1
You can't use css to set the width or height of canvas or it will result in it being stretched. You can use .setAttribute('width', '500'); instead. Also note fillrect(x, y, width, height)
8th Jul 2020, 7:27 AM
JME
+ 6
I have tried to make it square... you can further modify by changing posx,posy, height and width.. https://code.sololearn.com/WMnTTwxdo4QK/?ref=app
8th Jul 2020, 8:37 AM
Aditya
Aditya - avatar
0
In your CSS just remove the styles you have given for canvas. Remove #canvas { //All styles defined her }
8th Jul 2020, 7:31 AM
Shobhith J B
Shobhith J B - avatar