---
title: "AS 绘制多条平滑曲线(基于二次贝塞尔曲线)"
author: "dishell"
date: "2009-10-26T16:53:17Z"
tags: []
slug: "as"
draft: false
lastmod: "2009-10-26T16:53:17Z"
id: 504440
url: "https://dishell.iteye.com/blog/504440"
---

<span style="color:red">绘制策略：</span>在每两对点之间，加入一个新点(中间点)放在这两点的正中间。然后使用这些<span style="color:green">中间点作为起点和终点</span>，而把最初的那<span style="color:green">些点(原始点)作为控制点</span>。

```java

package
{
	import flash.display.Sprite;
	import flash.events.MouseEvent;
	
	public class MultiCurves3 extends Sprite
	{
		private var numPoints:uint = 9;
		public function MultiCurves3()
		{
			init();
		}
		
		private function init():void
		{
			var points:Array = new Array();
			for (var i:int = 0; i < numPoints; i++)
			{
				points[i] = new Object();
				points[i].x = Math.random() * stage.stageHeight;
				points[i].y = Math.random() * stage.stageHeight;
			}
			
			// find the first midpoint and move to it
			var xc1:Number = (points[0].x + points[numpoints - 1].x) / 2;
			var yc1:Number = (points[0].y + points[numpoints - 1].y) / 2;
			graphics.lineStyle(1);
			graphics.moveTo(xc1, yc1);

			// curve through the rest, stopping at midpoints
			for (i = 0; i < numPoints - 1; i ++)
			{
				var xc:Number = (points[i].x + points[i + 1].x) / 2;
				var yc:Number = (points[i].y + points[i + 1].y) / 2;
				graphics.curveTo(points[i].x, points[i].y, xc, yc);
			}
			
			// curve through the last point, back to the first midpoint
			graphics.curveTo(points[i].x, points[i].y, xc1, yc1);
		}
	}
}


```