Drawing a Rectangle

CanvasIf you're looking to draw a rectangle on a canvas, you can use techniques we've looked at before to simply draw four lines at right angles. But you don't need to; there are build in methods to do this for you.

You could easily draw a simple rectangle by using the lineTo() method:

context = canvasTag.getContext('2d');
context.lineTo(200, 0); context.lineTo(200, 100); context.lineTo(0, 100); context.lineTo(0, 0); context.stroke();

While this isn't difficult, it takes four lines of code to draw. There is an easier way: you can use the Context.rect() method to simplify drawing a rectangle. See below.

context = canvasTag.getContext('2d');
context.rect(0, 0, 200, 100); context.stroke();


Prologic Corporation said...

This is a good article & good site.Thank you for sharing this article. It is help us following categorize:
healthcare, e commerce, programming, it consulting, retail, manufacturing, CRM, digital supply chain management, Delivering high-quality service for your business applications,
Solutions for all Industries,
Getting your applications talking is the key to better business processes,
Rapid web services solutions for real business problems,
Web-based Corporate Document Management System,
Outsourcing Solution,
Financial and Operations Business Intelligence Solution,


Robert Morris said...

nice post.

Web Development Company

tbcreations said...

Hello dear.You have written a great post. Going to share with my followers on twitter. Thanks for sharing.
Rochester NY Graphic Design
Rochester NY Web Design
Rochester NY Web Development

Jian Zhuo said...

cheap jordans
lebron james shoes 2016
coach outlet
kate spade handbags
coach factory outlet
ralph lauren
jimmy choo
polo ralph lauren outlet online
nike roshe
michael kors outlet clearance

Jian Zhuo said...

oakley sunglasses on sale
michael kors outlet online
kate spade purses
adidas running shoes
pandora charms
ralph lauren outlet online
rolex watches
pandora jewelry outlet
polo ralph lauren