# Gradient line matrix

**URL:** <https://forum.kirupa.com/t/gradient-line-matrix/324573>\
**Category:** flash\
**Created:** [August 27, 2011, 3:17pm UTC](https://forum.kirupa.com/t/gradient-line-matrix/324573 "2011-08-27T15:17:47Z")\
**Posts on this page:** 1\
**Page:** 1

<div class="post-metadata">

**Author:** ![firefly431](https://avatars.discourse-cdn.com/v4/letter/f/e99b99/32.png) [@firefly431](https://forum.kirupa.com/u/firefly431)\
**Post date:** [August 27, 2011, 3:17pm UTC](https://forum.kirupa.com/t/gradient-line-matrix/324573/1 "2011-08-27T15:17:47Z")

</div>

Hi, I’m making a lens flare effect, and I want to make a gradient line. The matrix has the right angle, but it does some weird stuff when you try to draw a line.  
Here is my code:

```auto

function drawgline(x1,y1,x2,y2,bounds:Rectangle):Shape {
	var a:Shape = new Shape();
	a.graphics.beginFill(0xFF0000);
	a.graphics.drawCircle(x1,y1,1);
	a.graphics.drawCircle(x2,y2,1);
	a.graphics.endFill();
	addChild(a);
	var mat:Matrix = new Matrix();
	mat.createGradientBox(bounds.width,bounds.height,Math.atan2(y2-y1,x2-x1),bounds.left,bounds.right);
	var sh:Shape = new Shape();
	sh.graphics.lineStyle(1);
	sh.graphics.lineGradientStyle(GradientType.LINEAR,[0xFFFFFF,0xFFFFFF,0xFFFFFF],[0,1,0],[0,50,100],mat);
	sh.graphics.moveTo(x1,y1);
	sh.graphics.lineTo(x2,y2);
	sh.filters = [new GlowFilter(0xFFFFFF,1,2,2)];
	a = sh;
	a.graphics.beginFill(0xFF0000);
	a.graphics.drawCircle(x1,y1,1);
	a.graphics.drawCircle(x2,y2,1);
	a.graphics.endFill();
	return sh;
}

```

Most of the code is for debugging.  
It’s called like:  
flare.addChild(drawgline(Math.cos(ang)\*radius,Math.sin(ang)\*radius,Math.cos(ang+Math.PI)_radius,Math.sin(ang+Math.PI)radius,new Rectangle(-radius,-radius,radius2,radius_2)));
