荟萃馆

位置:首页 > 设计 > 网页设计

html5使用canvas画三角形

html5如何使用canvas画三角形,就跟随本站小编一起去了解下吧,想了解更多相关信息请持续关注我们应届毕业生考试网!

html5使用canvas画三角形

<canvas id="canvas" width="500" height="500" style="background-color: yellow;"></canvas>

代码如下:

var canvas=lementById("canvas");

var cxt=ontext("2d");

nPath();

To(250,50);

To(200,200);

To(300,300);

ePath();//填充或闭合 需要先闭合路径才能画

//空心三角形

keStyle="red";

ke();

//实心三角形

nPath();

To(350,50);

To(300,200);

To(400,300);

ePath();

();

<canvas id="canvas" width="500" height="400" style="background-color: yellow;"></canvas>

代码如下:

var canvas=lementById("canvas");

var cxt=ontext("2d");

="40px 黑体";

//绘制实心字

Style="red";//填充红色

Text("hello,思思博士",10,50);

//绘制空心字

keStyle="red";//红色边

keText("hello,思思博士",10,100);

标签:html5 canvas