Can't generate Rectangle in canvas using map values | Sololearn: Learn to code for FREE!
New course! Every coder should learn Generative AI!
Try a free lesson
+ 1

Can't generate Rectangle in canvas using map values

I successfully generated two random values and insert them in a map named "m" and then I try to create a canvas rectangle based on those values. The first x and y values work but the second one always goes wherever it wants? I'll put the code below and the part for where the values and rectangle are generated can be found below the circle class. https://code.sololearn.com/Wa24A14a3A11

11th Mar 2021, 6:13 AM
EthanE230
EthanE230 - avatar
1 Answer
+ 2
canvas_context.rect method expect (x,y,width,height) as arguments, but you provide (x1,y1,x2,y2)... simple fix: k.rect(m.get("x1"),m.get("y1"),m.get("x2")-m.get("x1"),m.get("y2")-m.get("y1"));
11th Mar 2021, 6:22 AM
visph
visph - avatar