| 1 |
package |
|---|
| 2 |
{ |
|---|
| 3 |
import com.nitoyon.potras.*; |
|---|
| 4 |
import flash.display.*; |
|---|
| 5 |
import flash.geom.*; |
|---|
| 6 |
import flash.events.*; |
|---|
| 7 |
|
|---|
| 8 |
[SWF(width="320",height="320")] |
|---|
| 9 |
public class AjustVertex extends Sprite |
|---|
| 10 |
{ |
|---|
| 11 |
[Embed(source='data1.gif')] |
|---|
| 12 |
private var Data1:Class; |
|---|
| 13 |
|
|---|
| 14 |
private static const SCALE:int = 8; |
|---|
| 15 |
|
|---|
| 16 |
public function AjustVertex() |
|---|
| 17 |
{ |
|---|
| 18 |
var bmp:Bitmap = new Data1(); |
|---|
| 19 |
bmp.scaleX = bmp.scaleY = SCALE; |
|---|
| 20 |
var bmd:BitmapData = bmp.bitmapData; |
|---|
| 21 |
addChild(bmp); |
|---|
| 22 |
|
|---|
| 23 |
var i:int = 0; |
|---|
| 24 |
var j:int = 0; |
|---|
| 25 |
|
|---|
| 26 |
var pathList:Array = PathList.create(bmp.bitmapData); |
|---|
| 27 |
drawPath(bmd, pathList); |
|---|
| 28 |
|
|---|
| 29 |
var lons:Array = []; |
|---|
| 30 |
var sprite:Sprite = new Sprite(); |
|---|
| 31 |
addChild(sprite); |
|---|
| 32 |
|
|---|
| 33 |
var movePos:Function = function(pt:Point):void |
|---|
| 34 |
{ |
|---|
| 35 |
pt.x *= SCALE; pt.x += SCALE / 2; |
|---|
| 36 |
pt.y *= SCALE; pt.y += SCALE / 2; |
|---|
| 37 |
} |
|---|
| 38 |
|
|---|
| 39 |
for(i = 0; i < pathList.length; i++) |
|---|
| 40 |
{ |
|---|
| 41 |
var sums:Array = ProcessPath.calcSums(pathList[i].priv as Array) as Array; |
|---|
| 42 |
lons[i] = ProcessPath.calcLon(pathList[i].priv as Array); |
|---|
| 43 |
var po:Array = ProcessPath.bestPolygon(pathList[i].priv as Array, lons[i], sums); |
|---|
| 44 |
var vertex:Array = ProcessPath.adjustVertices(pathList[i].priv as Array, sums, po); |
|---|
| 45 |
|
|---|
| 46 |
for(j = 0; j < vertex.length; j++) |
|---|
| 47 |
{ |
|---|
| 48 |
var num:int = po[j]; |
|---|
| 49 |
var pt:Point = pathList[i].priv[num].clone(); |
|---|
| 50 |
movePos(pt); |
|---|
| 51 |
|
|---|
| 52 |
sprite.graphics.beginFill(0x000000); |
|---|
| 53 |
sprite.graphics.lineStyle(); |
|---|
| 54 |
sprite.graphics.drawCircle(pt.x, pt.y, 2); |
|---|
| 55 |
sprite.graphics.endFill(); |
|---|
| 56 |
|
|---|
| 57 |
pt = vertex[j].clone(); |
|---|
| 58 |
movePos(pt); |
|---|
| 59 |
var s:Sprite = createCross(); |
|---|
| 60 |
s.x = pt.x; |
|---|
| 61 |
s.y = pt.y; |
|---|
| 62 |
addChild(s); |
|---|
| 63 |
} |
|---|
| 64 |
} |
|---|
| 65 |
} |
|---|
| 66 |
|
|---|
| 67 |
public static function drawPath(bmd:BitmapData, pathList:Array):void |
|---|
| 68 |
{ |
|---|
| 69 |
bmd.fillRect(new Rectangle(0, 0, bmd.width, bmd.height), 0xffffffff); |
|---|
| 70 |
for(var i:int = 0; i < pathList.length; i++) |
|---|
| 71 |
{ |
|---|
| 72 |
for(var j:int = 0; j < pathList[i].priv.length; j++) |
|---|
| 73 |
{ |
|---|
| 74 |
var pt:Point = pathList[i].priv[j] as Point; |
|---|
| 75 |
if(pt) |
|---|
| 76 |
{ |
|---|
| 77 |
bmd.setPixel(pt.x, pt.y, 0x999999); |
|---|
| 78 |
} |
|---|
| 79 |
} |
|---|
| 80 |
} |
|---|
| 81 |
} |
|---|
| 82 |
|
|---|
| 83 |
private function createCross():Sprite |
|---|
| 84 |
{ |
|---|
| 85 |
var s:Sprite = new Sprite(); |
|---|
| 86 |
s.graphics.lineStyle(2, 0xffffff); |
|---|
| 87 |
s.graphics.moveTo(-5, 0) |
|---|
| 88 |
s.graphics.lineTo(5, 0); |
|---|
| 89 |
s.graphics.moveTo(0, -5); |
|---|
| 90 |
s.graphics.lineTo(0, 5); |
|---|
| 91 |
s.graphics.lineStyle(1, 0x0066cc); |
|---|
| 92 |
s.graphics.moveTo(-5, 0) |
|---|
| 93 |
s.graphics.lineTo(5, 0); |
|---|
| 94 |
s.graphics.moveTo(0, -5); |
|---|
| 95 |
s.graphics.lineTo(0, 5); |
|---|
| 96 |
return s; |
|---|
| 97 |
} |
|---|
| 98 |
} |
|---|
| 99 |
} |
|---|