# Canvas
The Canvas component provides a drawing interface that allows arbitrary drawing operations. All drawing within Canvas must be completed using JavaScript.
<canvas canvas-id="myCanvas" style="border: 1px solid;"/>
const ctx = ft.createCanvasContext('myCanvas')
ctx.setFillStyle('red')
ctx.fillRect(10, 10, 150, 75)
ctx.draw()
# 1. Using Canvas
# 1.1 Creating a Canvas Drawing Context
First, we need to create a Canvas drawing context CanvasContext.
CanvasContext is a built-in object in Mini-Programs that provides various drawing methods:
const ctx = ft.createCanvasContext('myCanvas')
# 1.2 Using Canvas Context for Drawing Description
Next, we describe what content to draw within the Canvas.
Set the fill color of the drawing context to red:
ctx.setFillStyle('red')
Draw a rectangle using the fillRect(x, y, width, height) method, filled with the previously set red color:
ctx.fillRect(10, 10, 150, 75)
# 1.3 Drawing
Instruct the canvas component to render the previously described drawing:
ctx.draw()