HTML5 canvas-1 Canvas Rectangle

Source: Internet
Author: User
Tags canvas rectangle

Drawing steps

get the canvas object

var Ocanvas = document.getElementById ("Canvas");

Get Contextual context

var context = Ocanvas.getcontext ("2d");

Draw a graphic

Select a method based on demand

Draw Rectangle / border / fill color

context.linewidth=1;

Context.fillrect (X,y,width,height);

Context.strokerect (X,y,width,height);

<HTML>    <Head>        <MetaCharSet= "UTF-8">        <title>Canvas-Rectangle</title>        <Metaname= "Viewport"content= "Width=device-width,initial-scale=1,minimum-scale=1,maximum-scale=1,user-scalable=no" />    </Head>    <Body>        <CanvasID= "Canvas"width= "$"Height= "$"></Canvas>        <Scripttype= "Text/javascript">        //two necessary conditions        //1. Get the Canvas object        varOcanvas=document.getElementById ("Canvas"); //2. Get Context        varContext=Ocanvas.getcontext ("2d"); //I. Context do operations, draw graphics        //1. Color, CSS styleContext.fillstyle= "#ededed"; //2. Beginning end width height, execution, fillrect filled rectangle, filledContext.fillrect (0,0, -, -); Context.fillstyle= "Red"; Context.fillrect ( -, -, -, -); //border, Strokerect no fill, strokestyle default blackContext.strokestyle= '#40bfe0'; Context.linewidth= '4'; //the width of the box, default 1Context.strokerect ( -, -, -, -); </Script>    </Body></HTML>

HTML5 canvas-1 Canvas 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.