How to fill the whole canvas with specific color?
Apply color to your canvas like Van Gogh with his sunflowers by using fillStyle
for the color and fillRect()
to cover the entire area:
This makes Picasso worry as you are setting the canvas color and make the whole thing just sparkle with it.
Canvas configuration
Before going all out Bob Ross and starting the actual happy painting, give your <canvas>
element some dimensions in HTML:
Get your brushes ready in JavaScript and then fill the canvas:
Without the annoying scrollbars, your new masterpiece will take center stage:
Dynamic canvas
The canvas can be as flexible as a yoga master. Just resize it to fit the window:
And if padding or borders are in play, bring them under control with:
Overpainting and layers
Playing with existing canvases? Use the globalCompositeOperation
property and challenge your inner Michelangelo:
You're not just painting here. You're creating layered masterpieces.
The CSS way
For a change, do the paint job without JavaScript. Simple, yet effective:
For dynamically changing the canvas color, switch back to JavaScript:
Remember, JavaScript style properties love the camel! (read camelCase)
Was this article helpful?