如何在 HTML5 画布上绘制多边形? [英] How to draw polygons on an HTML5 canvas?

查看:15
本文介绍了如何在 HTML5 画布上绘制多边形?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我需要知道如何在画布上绘制多边形.不使用 jQuery 或类似的东西.

I need to know how to draw polygons on a canvas. Without using jQuery or anything like that.

推荐答案

使用 moveTolineTo 创建路径 (现场演示):

Create a path with moveTo and lineTo (live demo):

var ctx = canvas.getContext('2d');
ctx.fillStyle = '#f00';
ctx.beginPath();
ctx.moveTo(0, 0);
ctx.lineTo(100,50);
ctx.lineTo(50, 100);
ctx.lineTo(0, 90);
ctx.closePath();
ctx.fill();

这篇关于如何在 HTML5 画布上绘制多边形?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆