code by reference:
`function anim(canvas, fps, clear) { var context = canvas.getContext("2d"); var interval = null; var update = null; var draw = null; this.update = function(func) { update = func; }; this.draw = function(func) { draw = func; }; var step = function() { if (clear) { context.clearRect(0, 0, canvas.width, canvas.height); } if (update !== null) { update(); } if (draw !== null) { draw(); } }; this.stop = function() { clearInterval(interval); }; this.play = function() { if (draw !== null) { draw(); } interval = setInterval(step, 1000 / fps); }; } function circle(x, y, r) { this.x = x; this.y = y; this.r = r; this.draw = function(context, color, globalAlpha) { context.globalAlpha = globalAlpha; // "ΠΏΡΠΎΠ·ΡΠ°ΡΠ½ΠΎΡΡΡ" context.fillStyle = color; // ΡΠ²Π΅Ρ Π·Π°Π»ΠΈΠ²ΠΊΠΈ context.beginPath(); context.arc(this.x, this.y, this.r, 0, Math.PI * 2, true); context.fill(); }; } function rect(x, y, width, height) { this.x = x; this.y = y; this.width = width; // ΡΠΈΡΠΈΠ½Π° this.height = height; // Π²ΡΡΠΎΡΠ° this.draw = function(context, color, globalAlpha) { context.globalAlpha = globalAlpha; // "ΠΏΡΠΎΠ·ΡΠ°ΡΠ½ΠΎΡΡΡ" context.fillStyle = color; // ΡΠ²Π΅Ρ Π·Π°Π»ΠΈΠ²ΠΊΠΈ context.fillRect(this.x, this.y, this.width, this.height); }; } function init() { var screen = new rect(0, 0, 320, 320); var ball1 = new circle(178, 25, 25); var ball3 = new circle(25, 150, 25); var vX1 = 5; var vY1 = 5; var vX3 = 5; var vY3 = 5; var canvas = document.getElementById("example"); canvas.width = screen.width; canvas.height = screen.height; var context = canvas.getContext("2d"); var game = new anim(canvas, 30, false); game.draw(function() { screen.draw(context, "#000", 0.5); ball1.draw(context, "#f00", 1); ball3.draw(context, "#fff", 1); }); game.update(function() { if (ball1.y - ball1.r < 0 || ball1.y + ball1.r > 320) // ΡΠΎΠΏΡΠΈΠΊΠΎΡΠ½ΠΎΠ²Π΅Π½ΠΈΠ΅ Ρ "ΠΏΠΎΠ»ΠΎΠΌ" ΠΈ "ΠΏΠΎΡΠΎΠ»ΠΊΠΎΠΌ" Ρ
ΠΎΠ»ΡΡΠ° { vY1 = -vY1; } if (ball1.x - ball1.r < 0 || ball1.x + ball1.r > 320) // ΡΠΎΠΏΡΠΈΠΊΠΎΡΠ½ΠΎΠ²Π΅Π½ΠΈΠ΅ Ρ Π»Π΅Π²ΠΎΠΉ ΠΈ ΠΏΡΠ°Π²ΠΎΠΉ "ΡΡΠ΅Π½ΠΊΠΎΠΉ" Ρ
ΠΎΠ»ΡΡΠ° { vX1 = -vX1; } if (ball3.y - ball3.r < 0 || ball3.y + ball3.r > 320) // ΡΠΎΠΏΡΠΈΠΊΠΎΡΠ½ΠΎΠ²Π΅Π½ΠΈΠ΅ Ρ "ΠΏΠΎΠ»ΠΎΠΌ" ΠΈ "ΠΏΠΎΡΠΎΠ»ΠΊΠΎΠΌ" Ρ
ΠΎΠ»ΡΡΠ° { vY3 = -vY3; } if (ball3.x - ball3.r < 0 || ball3.x + ball3.r > 320) // ΡΠΎΠΏΡΠΈΠΊΠΎΡΠ½ΠΎΠ²Π΅Π½ΠΈΠ΅ Ρ Π»Π΅Π²ΠΎΠΉ ΠΈ ΠΏΡΠ°Π²ΠΎΠΉ "ΡΡΠ΅Π½ΠΊΠΎΠΉ" Ρ
ΠΎΠ»ΡΡΠ° { vX3 = -vX3; } // ΡΡΠ»ΠΎΠ²ΠΈΠ΅ ΡΠΎΠΏΡΠΈΠΊΠΎΡΠ½ΠΎΠ²Π΅Π½ΠΈΡ ΡΠ°ΡΠΎΠ² Π΄ΡΡΠ³ Ρ Π΄ΡΡΠ³ΠΎΠΌ if ( Math.abs(ball1.x - ball3.x) + Math.abs(ball1.y - ball3.y) <= 50) { vX1 = -vX1; vX3 = -vX3; vY1 = -vY1; vY3 = -vY3; } ball1.x += vX1; ball1.y += vY1; ball3.x += vX3; ball3.y += vY3; }); screen.draw(context, "#000", 1); ball1.draw(context, "#f00", 1); ball3.draw(context, "#fff", 1); var click = false; // ΠΏΠΎ ΡΠ΅Π»ΡΠΊΡ ΠΌΡΡΠΈ ΠΎΡΡΠ°Π½Π°Π²Π»ΠΈΠ²Π°Π΅ΠΌ ΠΎΠ±Π½ΠΎΠ²Π»Π΅Π½ΠΈΠ΅ Ρ
ΠΎΠ»ΡΡΠ°, // Π΅ΡΠ»ΠΈ Ρ
ΠΎΠ»ΡΡ ΠΎΡΡΠ°Π½ΠΎΠ²Π»Π΅Π½ ΠΏΡΠΎΠ΄ΠΎΠ»ΠΆΠ°Π΅ΠΌ Π°Π½ΠΈΠΌΠ°ΡΠΈΡ canvas.onclick = function() { if (!click) { click = true; game.play(); } else { click = false; game.stop(); } }; } init();` If you click on the picture, the balls will begin to move and leave a trail. I did not delve into the code, the javascript syntax is not familiar. Running a similar, written in java on the Android OS, there is no such trace. In some cases, it is needed for elegance, and somewhere else on the contrary superfluous. So what is the reason for his appearance? What are the features of javascript? or monitor? In java, the system is as follows: the game scene was filled with a background pattern, drew objects, changed the coordinates of the objects, filled the background and drew again. And how is it? Maybe there is a code in the javascript library that intentionally creates this trace?
context.globalAlpha = globalAlphain therectfunction and the blur will disappear jsfiddle.net/ngz8ssjb . - Alex Krass