CanvasContext.rect

Draw a rect. Use fill() or stroke() to draw the rect to canvas.

Parameters

It is Object type.

FieldTypeDescription
xNumberThe x coordinate of left-upper corner of the rect
yNumberThe y coordinate of left-upper corner of the rect
widthNumberThe width of the rect
heightNumberThe height of the rect

Sample Code

copy
//.js
const ctx = my.createCanvasContext('awesomeCanvas')
ctx.rect(20, 20, 250, 80)
ctx.setFillStyle('blue')
ctx.fill()
ctx.draw()