[태그:] Dashed Line

  • 점선, 쇄선 그리기

    액션스크립트의 Graphihcs클래스를 사용해서 선을 그릴 때, 점선이나 쇄선 등을 지원하지 않아서 만들어 봤습니다.
    전에 올린 ActionScript로 점선 그리기2: Marching Ants 글에서 사용한 것과 비슷한 방식으로 BitmapDataGraphics.beginBitmapFill()을 사용했습니다.

    var bd:BitmapData;
    var DASH:BitmapData			= new BitmapData(10, 1, true, 0x0);
    var DOT:BitmapData			= new BitmapData(4, 1, true, 0x0);
    var DASH_DOT:BitmapData		= new BitmapData(16, 1, true, 0x0);
    var DASH_DOT_DOT:BitmapData	= new BitmapData(20, 1, true, 0x0);
    
    
    var c:uint = 0xFF000000;
    var rect:Rectangle = new Rectangle(0, 0, 0, 1);
    rect.width = 5;
    DASH.fillRect(rect, c);
    
    rect.width = 2;
    DOT.fillRect(rect, c);
    
    rect.width = 10;
    DASH_DOT.fillRect(rect, c);
    DASH_DOT_DOT.fillRect(rect, c);
    rect.x = 12;
    rect.width = 2;
    DASH_DOT.fillRect(rect, c);
    DASH_DOT_DOT.fillRect(rect, c);
    rect.x = 16
    DASH_DOT_DOT.fillRect(rect, c);
    
    bd = DASH;
    
    
    var line:Sprite = new Sprite();
    addChildAt(line, 0);
    var g:Graphics = line.graphics;
    
    
    function draw():void
    {
    	line.x = p1.x;
    	line.y = p1.y;
    	
    	var xx:int = p2.x - p1.x;
    	var yy:int = p2.y - p1.y;
    	
    	g.clear();
    	g.beginBitmapFill(bd, null, true);
    	g.drawRect(0, 0, Math.sqrt(xx * xx + yy * yy), 1);
    	g.endFill();
    	
    	line.rotation = Math.atan2(yy, xx) / Math.PI * 180;
    }
  • ActionScript로 점선 그리기2: Marching Ants

    어제 올렸던 대시라인 그리기에서 조금 더 기능을 추가해 봤습니다. 포토샵에서 선택영역을 지정하면 점선이 이동하는 효과가 나오는데, 그걸 적용했습니다. 행진하는 개미 ^^

    beginBitmapFill(bitmap:BitmapData, matrix:Matrix=null, repeat:Boolean=true, smooth:Boolean=false):void
    위와 같이 Graphics.beginBitmapFill() 메소드에 2번째 파라메터로 매트릭스를 지정하여 사용할 수 있습니다. 그래서 하나의 비트맵데이터를 가지고 매트릭스에 회전을 주어서 사용을 했더니, 비트맵데이터가 외곡되는 문제가 생기네요. 일단 귀찮아서 비트맵데이터 4개를 가지고 그렸는데, 최적화하는 방법은 좀 더 찾아 봐야할 듯 하네요.

    click to view the source code

  • ActionScript로 점선 그리기

    이전 포스트와 마찬가지로, 이미지 에디터에서 필요한 기능 구현하면서 만들어 본 샘플입니다. 이번에는 점선 혹은 대쉬선(dashed line)을 그리는 기능입니다.

    click to view the source code