HTML Canvas Simple Experience

Source: Internet
Author: User
Tags linecap

Draw a line

var canvas = document.getElementById (' C1 ');

var context = Canvas.getcontext (' 2d ');

Context.moveto (10, 50); starting point

Context.lineto (1000,50); End

Context.linewidth = 20; line width

context.strokestyle= ' #cd3828 '; Color

Context.strokestyle= "RGB (205,40,40)";

Context.linecap = ' round '; the threads are round round .

Context.stroke (); Start Drawing

draw a second line

Context.beginpath ();

Context.moveto (20,120);

Context.lineto (200,120);

context.strokestyle= ' #eecddd ';

Context.linecap = ' butt ';

Context.stroke ();

Draw the third article

Context.beginpath ();

Context.moveto (120,210);

Context.lineto (500,210);

context.linewidth=20;

context.strokestyle= ' #defeed ';

context.linecap= ' Square ';

Context.stroke ();

Draw Triangles

Context.moveto (250, 50);

Context.lineto (50,250);

Context.lineto (450,250);

Context.lineto (250,50);

Context.linewidth = 10;

Context.strokestyle= ' Blue ';

context.linejoin= ' round '; the edge of the cohesion shape round/bevel/mitre

Context.stroke ();

Fill Triangle

Context.closepath ();

context.fillstyle= ' Red ';

Context.fill ();

Draw a rectangle

Strokerect (0,10,100,200);

FillRect (0,10,100,200);

Drawing curves

var canvas = document.getElementById (' C1 ');

var context = Canvas.getcontext (' 2d ');

drawing Arcs

Context.moveto (62,24);

var control1_x = 187;

var control1_y = 32;

var control2_x = 429;

var control2_y = 480;

var endpointx = 365;

var endpointy = 133;

Drawing Curves

Context.beziercurveto (control1_x, control1_y, control2_x, control2_y, Endpointx, Endpointy);

Context.stroke ();

Draw a square

var canvas = document.getElementById (' C1 ');

var context = Canvas.getcontext (' 2d ');

To achieve the original point graph rotation

Context.translate (100, 100);

Draw ten squares

var copies = 10;

for (var i=1; i < copies; i++) {

Context.rotate (2*MATH.PI * 1/(copies-1));

Context.rect (0,0,60,60);

}

Context.stroke ();

Color Fill

var canvas = document.getElementById (' C1 ');

var context = Canvas.getcontext (' 2d ');

the realization of the transparent degree

Context.fillstyle = "RGB (100,150,185)";

Context.linewidth = 10;

Context.strokestyle = "Red";

Draw a circle

Context.arc (0, 2*math.pi);

Context.fill ();

Context.stroke ();

Draw Triangles

Context.beginpath ();

Context.fillstyle = "Rgba (100,150,185,0.5)";

Context.moveto (215,50);

Context.lineto (15,250);

Context.lineto (315,250);

Context.closepath ();

Context.fill ();

Context.stroke ();

HTML Canvas Simple Experience

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.