Canvas Rotating and Scaling Images Around a Particular Point

Transforming objects in your HTML5 Game or Experiment requires a bit of understanding regarding how they work. The behaviour and end result is not as intuitive as CSS3 transform functions like rotate() or scale(). I could quickly show you how to rotate or scale an image with its center as the origin, but it’s going to be super useful to take an indepth look at how the entire system works.

Continue reading “Canvas Rotating and Scaling Images Around a Particular Point”

HTML5 Canvas and Friction

So you started moving an object on your canvas by manipulating vx and vy, i.e., velocity on the x and y axis. But then, you just realized that in real world scenarios the speed of an object reduces with time, if there’s no continuous acceleration. Even with an acceleration of X, there will be some friction faced counter-affecting the acceleration.

Continue reading “HTML5 Canvas and Friction”

Moving/Scrolling/Sliding Background in HTML5 Canvas

Sometimes your game or canvas experiment might have one or more layers of animating backgrounds that are set in motion for the player’s movement or some other reason (like creating a parallax effect?). Just had to do something similar the other day. The problem is tricky but with a bit of thinking it seems like I came up with a proper solution!

Continue reading “Moving/Scrolling/Sliding Background in HTML5 Canvas”

HTML5 Canvas Particles Fountain Explosion with Gravity

One of my previous posts talked about implementing gravity in our canvas experiments. Eventually, we made a realistic bouncing ball. We’ll kind of extend that experiment to make a quick fountain explosion on canvas obeying gravity.

Continue reading “HTML5 Canvas Particles Fountain Explosion with Gravity”

Basics of Implementing Gravity with HTML5 Canvas

Gravity

When creating some canvas experiments like a particle emission system or a game, gravity can be a key feature to implement. Figuring out how to implement gravity on an object in terms of coding can be a bit confusing. We’ll try to comprehend it, by putting it into code in a simplified manner. I liek simplicity!

Continue reading “Basics of Implementing Gravity with HTML5 Canvas”

HTML5 Canvas Drawing Lines with Smooth Edges

In the previous post we kicked off with our painting application using HTML5 canvas. If you remember well, we ended up with a basic app where one can easily draw lines or something else with a “pencil” tool. But there was a problem. When drawing different shapes like circles, the lines/curves had jagged edges. They were not smooth or anti-aliased, whatever you want to call them. This article will aim towards solving those issues.

Continue reading “HTML5 Canvas Drawing Lines with Smooth Edges”