Time for action – putting the circle drawing code into a function
Let's make a function to draw the circle and then draw some circles in the Canvas. We are going to put code in different files to make the code simpler:
- Open the
untangle.drawing.js
file in our code editor and put in the following code:if (untangleGame === undefined) { var untangleGame = {}; } untangleGame.drawCircle = function(x, y, radius) { var ctx = untangleGame.ctx; ctx.fillStyle = "GOLD"; ctx.beginPath(); ctx.arc(x, y, radius, 0, Math.PI*2, true); ctx.closePath(); ctx.fill(); };
- Open the
untangle.data.js
file and put the following code into it:if (untangleGame === undefined) { var untangleGame = {}; } untangleGame.createRandomCircles = function(width, height) { // randomly draw ...
Get HTML5 Game Development by Example : Beginner's Guide - Second Edition now with the O’Reilly learning platform.
O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.