+ 4
Why doesn't this code work , am trying to make 10 ball with this code by using push and loop
onload = () => { init() ball() } let w , h , cr , c w = innerWidth h = innerHeight cr = ["red","lightblue","green","yellow","orange"] cr = Math.floor(Math.random()*cr.length) const init = () => { c = document.createElement("canvas") c = c.getContext("2d") c.width = w c.height = h document.body.appendChild(c) } const ball = () => { x = Math.floor(Math.random()*w) y = Math.floor(Math.random()*h) r = 20 draw = () => { c.beginPath() c.fillStyle = cr c.arc(x,y,r,0,2*Math.PI) c.fill() c.closePath() } }
5 Respostas
+ 3
It will work because this is a code playground
https://code.sololearn.com/W3Eoch1hwAOq/?ref=app
+ 4
you mistakenly used the same variable c for both canvas and context
use separate variables
for example
cnv for canvas
ctx for context
https://www.sololearn.com/post/117756/?ref=app
https://code.sololearn.com/WKKkpq0efxai/?ref=app
+ 2
Cbr✔[ Exams ] lol very true
+ 2
Thank you so much
0
I don't understand