Time for action – saving the circle position
- Open the
untangle.data.js
file in the text editor. - Add the following
circle
object definition code in the JavaScript file:untangleGame.Circle = function(x,y,radius){ this.x = x; this.y = y; this.radius = radius; }
- Now we need an array to store the circles' positions. Add a new array to the
untangleGame
object:untangleGame.circles = [];
- While drawing every circle in the Canvas, we save the position of the circle in the
circles
array. Add the following line before calling thedrawCircle
function, inside thecreateRandomCircles
function:untangleGame.circles.push(new untangleGame.Circle(x,y,circleRadius));
- After the steps, we should have the following code in the
untangle.data.js
file:if (untangleGame === undefined) { var untangleGame = {}; } untangleGame.circles = []; untangleGame.Circle = function(x,y,radius){ this.x = x; this.y = y; this.radius = radius; }; untangleGame.createRandomCircles = function(width, height) { ...