Languages
[Edit]
EN

JavaScript - fill canvas with two different colors horizontally

0 points
Created by:
nickkk0
647

In this article, we would like to show you how to fill a canvas with two different colors horizontally using JavaScript.

Quick solution:

 

1. Practical example

Edit

In this example, we present how to use fillRect() method to fill the canvas with two different colors.

 

2. Reusable function

Edit

In this section, we present a reusable function that fills the canvas with two specified colors.

 

References

Edit
  1. CanvasRenderingContext2D.fillRect() - Web APIs | MDN

Alternative titles

  1. JavaScript - multiple horizontal background colors for HTML canvas
1
Donate to Dirask
Our content is created by volunteers - like Wikipedia. If you think, the things we do are good, donate us. Thanks!
Join to our subscribers to be up to date with content, news and offers.

JavaScript - HTML5 canvas tutorial

Native Advertising
🚀
Get your tech brand or product in front of software developers.
For more information Contact us
Dirask - we help you to
solve coding problems.
Ask question.

❤️💻 🙂

Join