Conclusion

So…there you have it! You just saw a quick overview of how to draw rectangles on the canvas using rect, fillRect, and strokeRect. You may be wondering which of the three methods you’ll want to use. If you need to just draw a rectangle quickly, either the fillRect (solid shape) or strokeRect (outline of a shape) methods are fine. For drawing a rectangle as part of a series of other draw commands, the rect method is your best friend. In case it matters, I almost always use the rect method for the unfortunate times I need to draw a rectangle or square :P