Note that there are some explanatory texts on larger screens.

plurals
  1. POGoogle Closure's Graphic module is too much slow. goog.graphics.CanvasGraphics
    primarykey
    data
    text
    <p>Recently, I study HTML Canvas using Google Closure.</p> <p>but the performance of Google Closure is terribly slow. </p> <p>when I run my code.. it almost crash down Chrome browser. </p> <p>Of course I did the same thing in HTML Canvas code not using Google Closure; It is super fast.</p> <p>Here is my canvas code using Google Closure (goog.graphics.CanvasGraphics)</p> <p>Since I am just a beginner in this module(goog.graphics.CanvasGraphics), I am not sure I did it correctly. Is there a something wrong I did? Why is it so terribly slow??!!</p> <p>It is too frustrating. </p> <pre><code>/** * @param {Document} doct */ test.main = function(doct){ var dom = new goog.dom.DomHelper(doct); /** * goog.graphics.CanvasGraphics(width, height, opt_coordWidth, opt_coordHeight, opt_domHelper) * @type {goog.graphics.CanvasGraphics} */ var canvas = new goog.graphics.CanvasGraphics(500, 500, null, null, dom); canvas.render(dom.getElement('canvasTest2')) canvas.balls = []; function drawScreen () { canvas.clear() for (var i =0; i &lt;canvas.balls.length; i++) { ball = canvas.balls[i]; ball.x += ball.xunits; ball.y += ball.yunits; var ellipse = canvas.drawEllipse(ball.x, ball.y, ball.radius, ball.radius, null, ball.solidFill); if (ball.x &gt; canvas.width || ball.x &lt; 0 ) { ball.angle = 180 - ball.angle; updateBall(ball); } else if (ball.y &gt; canvas.height || ball.y &lt; 0) { ball.angle = 360 - ball.angle; updateBall(ball); } } } function updateBall(ball) { ball.radians = ball.angle * Math.PI/ 180; ball.xunits = Math.cos(ball.radians) * ball.speed; ball.yunits = Math.sin(ball.radians) * ball.speed; } var numBalls = 80; var maxSize = 15; var minSize = 5; var maxSpeed = maxSize+5; for (var i = 0; i &lt; numBalls; i++) { var tempRadius = Math.floor(Math.random()*maxSize)+minSize; var tempX = tempRadius*2 + (Math.floor(Math.random()*canvas.width)-tempRadius*2); var tempY = tempRadius*2 + (Math.floor(Math.random()*canvas.height)-tempRadius*2); var tempSpeed = maxSpeed-tempRadius; var tempAngle = Math.floor(Math.random()*360); var tempRadians = tempAngle * Math.PI/ 180; var tempXunits = Math.cos(tempRadians) * tempSpeed; var tempYunits = Math.sin(tempRadians) * tempSpeed; var stroke = new goog.graphics.Stroke(3, '#333'); var solidFill = new goog.graphics.SolidFill('#333'); tempBall = {x:tempX,y:tempY,radius:tempRadius, speed:tempSpeed, stroke:stroke, solidFill:solidFill, angle:tempAngle, xunits:tempXunits, yunits:tempYunits} canvas.balls.push(tempBall); } setInterval(drawScreen, 32); } </code></pre>
    singulars
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload