---
title: "五角星画法"
author: "yiminghe"
date: "2010-11-24T16:53:34Z"
tags: ["EXT", "Google", "YUI", "jQuery"]
categories: ["Web前端"]
slug: "untitled"
draft: false
lastmod: "2010-11-24T16:53:34Z"
id: 820162
url: "https://yiminghe.iteye.com/blog/820162"
---

从小都画不好的五角星原来有[画法](https://developer.mozilla.org/en/Canvas_tutorial/Compositing#Clipping_paths) 的，只要尺子和圆规就可以了：

 

![](http://dl.iteye.com/upload/attachment/352952/780ae250-cad6-30aa-8d00-85dad023e132.png)

# 步鄹：

1.首先移动中心到将要画的五角星中心

2.沿 x 轴移动起点 p1 到五角星一角所在的位置，如绿线所在右侧终点

3.顺时针旋转坐标系36度

4.再次沿 x 轴移动终点 p2 ，p2 到中心的距离小于 p1 到中心的距离，从而产生五角星凹处的效果

5.画一条线连接 p1 与  p2

6.依次执行 3,2,4,5 步共 9 次

 

# canvas 描述：

如果使用 canvas 的话就简单了

1\. 使用 [moveTo](https://developer.mozilla.org/en/Canvas_tutorial/Drawing_shapes#moveTo) 移动端点

3\. 使用 [rotate](https://developer.mozilla.org/en/Canvas_tutorial/Transformations#Rotating) 旋转坐标系

5\. 使用 [lineTo](https://developer.mozilla.org/en/Canvas_tutorial/Drawing_shapes#Lines) 链接端点画线

最后还可以使用 [fill](https://developer.mozilla.org/en/Canvas_tutorial/Drawing_shapes#Drawing_paths) 来进行五角星内部的填充

 

[demo @ google code](http://lite-ext.googlecode.com/svn/trunk/lite-ext/playground/pentagram_canvas/test.html)