0

I need help drawing two shapes in JS

I draw my black circle just fine, but when I add a square it turns the the circle blue as well. When I draw a line with those it puts a line with them connecting to to lines and messes up the context.fillStyle PLEASE HELP!! https://code.sololearn.com/Wf50eY68m9t4/?ref=app

15th Dec 2022, 5:39 PM
Paxton Programer
5 odpowiedzi
+ 6
You need to create seperate variables for each of your rendering context2d objects. Currently you only have one context variable for all of your rendered objects. var context = canvas.getContext('2d'); context.fillStyle = "blue"; Instead I would seperate the objects and give each identifiable names. const canvas = document.getElementById("canvas"); const square = canvas.getContext("2d"); square.fillStyle = "blue"; square.fillRect(10, 10, 50, 50); const circle = canvas.getContext("2d"); circle.fillStyle = 'black'; circle.beginPath(); circle.arc(200, 40, 30, 0, 2 * Math.PI); circle.fill();
15th Dec 2022, 7:47 PM
Chris Coder
Chris Coder - avatar
16th Dec 2022, 10:47 PM
Chris Coder
Chris Coder - avatar
0
I can't get it to work can you check on my code?
16th Dec 2022, 12:50 PM
Paxton Programer
0
If you edit my code, would it show on my device? If so, can you edit it so it is fixed? Thanks.
16th Dec 2022, 12:55 PM
Paxton Programer
0
Thank you a lots
17th Dec 2022, 12:54 PM
Paxton Programer