+ 23

Can someone help me with this code?

So, I wanna do a code which makes a new circle as each second pass... function draw() { cc.beginPath() cc.fillStyle=color cc.arc(x,y,w,h, Math.PI*2, true) cc.fill() cc.closePath() } setInterval(draw, 1000); But instead of saving each circle I do (x, y, w, h are changed after each interval, but not gonna say value because it will spoil my new code), it draws the circle I want, after a second, the circle is deleted and a new one is drawn on the values... How can I save previous circles?

11th Mar 2017, 6:14 PM
Gami
Gami - avatar
4 Answers
+ 15
I'm no expert but the code seems to work fine. Here's what I tried: window.onload =function(){ x=20 y=20 w=20 h=20 c= document.getElementById("c"); cc=c.getContext("2d"); setInterval(draw, 1000); } function draw() { cc.beginPath() cc.fillStyle="red" cc.arc(x,y,w,h, Math.PI*2, true) cc.fill() cc.closePath() x+=20; y+=20; w+=20; h+=20; }
11th Mar 2017, 7:08 PM
Jafca
Jafca - avatar
+ 19
Hm, yeah, I haven't thought about that. A silly mistake ruined my code.
11th Mar 2017, 9:29 PM
Gami
Gami - avatar
+ 18
Oh, don t worry, I got it right now.... I set a rectangle which makes the background black, but it is always defined before in draw so this is why just some where visible. Thanks anyways Jafca
11th Mar 2017, 9:08 PM
Gami
Gami - avatar
+ 15
Why not make the background black in CSS or HTML? body { background-color:black; }
11th Mar 2017, 9:27 PM
Jafca
Jafca - avatar