function set_canvas(width, height) { var canvas = document.createElement('canvas') ; canvas.setAttribute('width', width) ; canvas.setAttribute('height', height) ; return canvas ; } function set_stage(width, height) { var stage = document.createElement('div') ; stage.style.width = width ; stage.style.height = height ; stage.style.position = 'relative' ; stage.style.margin = 0 ; stage.style.transformOrigin = "0 0"; // scale from top left return stage ; } function draw_circle(ctx, circ) { ctx.beginPath() ; var x = circ.x ; var y = circ.y ; var r = circ.radius ; ctx.arc(x, y, r, 0, Math.PI * 2, true) ; ctx.fillStyle = circ.color ; ctx.fill() ; ctx.closePath() ; } var gameDiv = document.getElementById('#game_div') ; // assume there is some element called game_div var bgclr = '#FFF' ; document.body.style.backgroundColor = bgclr ; document.body.style.overflowY = 'hidden'; document.body.style.margin = 0 ; gameDiv.style.margin = 0 ; gameDiv.style.height = '100%' ; gameDiv.style.width = '100%' ; gameDiv.style.font = '13pt courier'; gameDiv.style.fontWeight = 'bold'; gameDiv.style.backgroundColor = bgclr ; gameDiv.style.overflowY = 'hidden'; gameDiv.style.color = '#ccc'; gameDiv.style['-webkit-user-select'] = 'none'; gameDiv.style['-moz-user-select'] = 'none'; gameDiv.style['user-select'] = 'none' ; var size = 100 ; var width = size ; var height = size ; var dur = 500 ; // transition duration in milliseconds var perf = window.performance ; var canvas = set_canvas(width, height) ; canvas.setAttribute('id', 'vizCanvas') ; canvas.style.position = 'absolute' ; var hiddenCanvas = set_canvas(width, height) ; hiddenCanvas.style.display = 'none' ; // hide this canvas var context = canvas.getContext('2d') ; // context.webkitImageSmoothingEnabled = false ; context.mozImageSmoothingEnabled = false ; context.imageSmoothingEnabled = false ; context.font = "48px Arial" ; context.globalAlpha = 1.0 ; var stage = set_stage(width, height) ; stage.appendChild(canvas) ; gameDiv.appendChild(stage) ; var circ = {x: width * 0.5, y: height * 0.5, radius: width * 0.5, color: '#39A'} ; draw_circle(context, circ) ;