This is similar to progressive animation. Updating / promoting this animation from an executable function usually does not work immediately (updating the screen when this function completes).
Your canvas code is (automatically) wrapped in the onload function: window.onload=function(){ /*your code here*/ }; .
The last line of this function is alert('done!'); , so naturally you will get a warning before updating the screen and you will see zero.
One solution is to first set and display the boot image, and then using setTimeOut (say setTimeOut ), it displays the canvas, ending this canvas function with another setTimeOut to delete the boot image again.
Note: as you probably know, your code will generate (many) hexadecimal colors like #3df5 and #5d8a6 , both of which are invalid colors! You also used 16777215, but Math.random () needs to be multiplied by 16777216. To fix this, you can try:
color='#'+((Math.random()+1)*16777216|0).toString(16).substr(1);
It reads well about random colors.
See this JSFiddle result for an example.
Hope this helps.
source share