Why is requestAnimationFrame better than setInterval or setTimeout

High quality animation. The question is most simply answered with. requestAnimationFrame produces higher quality animation completely eliminating flicker and shear that can happen when using setTimeout or setInterval, and reduce or completely remove frame skips. Shear is when a new canvas buffer is presented to the display buffer midway through the display scan resulting in … Read more

Resize image with javascript canvas (smoothly)

You can use down-stepping to achieve better results. Most browsers seem to use linear interpolation rather than bi-cubic when resizing images. (Update There has been added a quality property to the specs, imageSmoothingQuality which is currently available in Chrome only.) Unless one chooses no smoothing or nearest neighbor the browser will always interpolate the image … Read more

Accessing JPEG EXIF rotation data in JavaScript on the client side

If you only want the orientation tag and nothing else and don’t like to include another huge javascript library I wrote a little code that extracts the orientation tag as fast as possible (It uses DataView and readAsArrayBuffer which are available in IE10+, but you can write your own data reader for older browsers): function … Read more

Real mouse position in canvas

The Simple 1:1 Scenario For situations where the canvas element is 1:1 compared to the bitmap size, you can get the mouse positions by using this snippet: function getMousePos(canvas, evt) { var rect = canvas.getBoundingClientRect(); return { x: evt.clientX – rect.left, y: evt.clientY – rect.top }; } Just call it from your event with the … Read more

Is there any reason for using WebGL instead of 2D Canvas for 2D games/apps?

Looking at this question from another side: How does a developer choose one technology over another? integrates better in their already built system is easier to use is faster has more capabilities or better suits their needs cost more platform-independent So I’ll discuss the differences between canvas and webGL APIs regarding these qualities. Both canvas … Read more

Changing three.js background to transparent or other color

I came across this when I started using three.js as well. It’s actually a javascript issue. You currently have: renderer.setClearColorHex( 0x000000, 1 ); in your threejs init function. Change it to: renderer.setClearColorHex( 0xffffff, 1 ); Update: Thanks to HdN8 for the updated solution: renderer.setClearColor( 0xffffff, 0); Update #2: As pointed out by WestLangley in another, … Read more

how to draw smooth curve through N points using javascript HTML5 canvas?

The problem with joining subsequent sample points together with disjoint “curveTo” type functions, is that where the curves meet is not smooth. This is because the two curves share an end point but are influenced by completely disjoint control points. One solution is to “curve to” the midpoints between the next 2 subsequent sample points. … Read more

How to fix getImageData() error The canvas has been tainted by cross-origin data?

As others have said you are “tainting” the canvas by loading from a cross origins domain. https://developer.mozilla.org/en-US/docs/HTML/CORS_Enabled_Image However, you may be able to prevent this by simply setting: img.crossOrigin = “Anonymous”; This only works if the remote server sets the following header appropriately: Access-Control-Allow-Origin “*” The Dropbox file chooser when using the “direct link” option … Read more

Hata!: SQLSTATE[HY000] [1045] Access denied for user 'divattrend_liink'@'localhost' (using password: YES)