本文主要是介绍canvas画正六边形,希望对大家解决编程问题提供一定的参考价值,需要的开发者们随着小编来一起学习吧!
效果图如下:
代码如下:
<!DOCTYPE html>
<html>
<head><title>正六边形</title><meta charset="utf-8">
</head>
<body><canvas id="canvas" width="400" height="400"></canvas>
</body>
<script type="text/javascript">var canvas = document.querySelector('#canvas'),context = canvas.getContext('2d');// 定义边长、颜色、边数、canvas大小var length = 100, fillColor = '#000', vertices = 6, size = 1000;canvas.width = size;canvas.height = size;var getDegree = function(vertices, index) {return 360 / vertices * (i + 0.5) +
这篇关于canvas画正六边形的文章就介绍到这儿,希望我们推荐的文章对编程师们有所帮助!