Notice: This page requires JavaScript to function properly.
Please enable JavaScript in your browser settings or update your browser.
Aprende Rectangles and Filled Shapes | Canvas Setup and Drawing Fundamentals
JavaScript Canvas Drawing and Animation

bookRectangles and Filled Shapes

index.html

index.html

copy

The fillStyle property allows you to set the color, gradient, or pattern used to fill shapes drawn on the canvas. You can assign a color using a string like "#ff0000" for red or "rgba(52, 152, 219, 0.5)" for a semi-transparent blue. Similarly, strokeStyle sets the color, gradient, or pattern for the outlines of shapes. Both properties accept CSS color values, enabling a wide variety of visual effects.

index.html

index.html

copy

To remove part of your drawing or reset a specific area, use clearRect(x, y, width, height). This method erases everything within the defined rectangle, allowing you to clear mistakes, update animations, or manage dynamic content efficiently. For example, calling ctx.clearRect(0, 0, canvas.width, canvas.height) will clear the entire canvas.

1. Which method would you use to draw a filled rectangle?

2. What property is used to set the color for filling shapes?

question mark

Which method would you use to draw a filled rectangle?

Select the correct answer

question mark

What property is used to set the color for filling shapes?

Select the correct answer

¿Todo estuvo claro?

¿Cómo podemos mejorarlo?

¡Gracias por tus comentarios!

Sección 1. Capítulo 5

Pregunte a AI

expand

Pregunte a AI

ChatGPT

Pregunte lo que quiera o pruebe una de las preguntas sugeridas para comenzar nuestra charla

Suggested prompts:

Can you explain the difference between fillStyle and strokeStyle with examples?

How do I use gradients or patterns with fillStyle and strokeStyle?

What happens if I use clearRect on a part of the canvas that hasn't been drawn on yet?

Awesome!

Completion rate improved to 5.88

bookRectangles and Filled Shapes

Desliza para mostrar el menú

index.html

index.html

copy

The fillStyle property allows you to set the color, gradient, or pattern used to fill shapes drawn on the canvas. You can assign a color using a string like "#ff0000" for red or "rgba(52, 152, 219, 0.5)" for a semi-transparent blue. Similarly, strokeStyle sets the color, gradient, or pattern for the outlines of shapes. Both properties accept CSS color values, enabling a wide variety of visual effects.

index.html

index.html

copy

To remove part of your drawing or reset a specific area, use clearRect(x, y, width, height). This method erases everything within the defined rectangle, allowing you to clear mistakes, update animations, or manage dynamic content efficiently. For example, calling ctx.clearRect(0, 0, canvas.width, canvas.height) will clear the entire canvas.

1. Which method would you use to draw a filled rectangle?

2. What property is used to set the color for filling shapes?

question mark

Which method would you use to draw a filled rectangle?

Select the correct answer

question mark

What property is used to set the color for filling shapes?

Select the correct answer

¿Todo estuvo claro?

¿Cómo podemos mejorarlo?

¡Gracias por tus comentarios!

Sección 1. Capítulo 5
some-alt