Canvas entry 04-draw a rectangle

Source: Internet
Author: User

APIs used:

  • CTX. strokerect (X, Y, width, height) to a rectangular stroke
  • CTX. fillrect (X, Y, width, height) fills in a rectangle
  • CTX. clearrect (X, Y, width, height) clears the rectangular area
  • CTX. linejoin = 'round '| 'bevel' | 'miter' defines the style of the line intersection.
VaR canvas = document. getelementbyid ('canvas '), context = canvas. getcontext ('2d '); canvas. width = 1024; canvas. height = 768; // CTX. linejoin = "bevel" | "round" | "miter"; context. linejoin = 'round '; // draw the rounded rectangle context. linewidth = 30; context. font = '24px Helvetica '; context. filltext ('click anywhere to erase', 175,200); context. strokestyle = 'goldenrod '; // use chrysanthemum to draw context. fillstyle = 'rgba (255, 0.5,) '; // fill the context with translucent blue. strokerect (1, 75,100,200,200); context. fillrect (1, 325,100,200,200); context. canvas. onmousedown = function (e) {context. clearrect (0, 0, canvas. width, canvas. height );}

 

Display Effect:

 

When you click any position on the canvas, the rectangle and text will disappear.

 

Canvas entry 04-draw a rectangle

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.