Trig Help

Hi,

I’m working on a class that basically takes a given rectangle or square and fills that square with spaced diagonal lines, which I then animate.

I’ve got it to work via brute force kinda approach, but I draw far more lines than I need and it becomes processor heavy.

So I’m trying to work out how to use Trig to start at say the bottom left of a square and iterate up the height etc of that square, drawing a single line (hypotenuse) across the square using a given angle for the line. Because I move the lines a little, there needs to be some overlap to allow for this movement.

Anyone got any idea how to do this? My trig brain has died and I can’t seem to figure it out.

I’m trying to draw something like this http://www.noponies.com/lines.gif

Thanks in advance.

Ok, here is the class I’m using…


package {
	import flash.events.TimerEvent;
	import flash.utils.Timer;
	import fl.transitions.Tween;
	import fl.transitions.easing.*;
	import flash.display.*;

	public class angledLines2 extends Sprite {
		//vars
		private var xpos:int;
		private var ypos:int;
		public var hsize:int;
		public var vsize:int;
		private var angle:int;
		private var strokeColor:uint;
		private var strokeWeight:int;
		private var bgColor:uint;
		private var speed:int;
		private var spacing:int;
		private var mult:int;
		private var inc:int;
		//vars passed from instance call
		public function angledLines2(hsize, vsize, angle, strokeColor,strokeWeight, bgColor, spacing, distance, speed) {
			//convert angle to radians
			var radians = angle* (Math.PI/180);
			//create a mask
			var tempMask:Shape = new Shape();
			tempMask.graphics.beginFill(0x000000,90);
			tempMask.x = 0;
			tempMask.y = 0;
			tempMask.graphics.drawRect(0, 0, hsize, vsize);
			tempMask.graphics.endFill();
			
			//create a shape to draw into
			var lines:Shape = new Shape();
			lines.graphics.lineStyle(strokeWeight, strokeColor, 100);
			lines.x = 0;
			lines.y = 0;
			
			//conditional switch based on what size we want our shape.
			if(hsize >= vsize) {
				mult = hsize
				//position to draw from
				inc = -hsize-distance;
			}else{
				mult = vsize
				//position to draw from
				inc = -vsize-distance;
			}

			//draw the lines
			function drawLines() {
				for (var i=1; i <= mult/(spacing/2); i++) {
					inc+=spacing
					lines.graphics.moveTo(inc, 0);
					lines.graphics.lineTo(((vsize)* Math.sin(radians))+inc, vsize);
					
				}
				var myTween:Tween = new Tween(lines, "x", None.easeIn, 0, distance, speed, true);
				myTween.looping = true;
				lines.cacheAsBitmap = true;
				tempMask.cacheAsBitmap = true;
				addChild(lines);
				addChild(tempMask);
				//comment out the mask to see how many lines are drawn
				lines.mask = tempMask;
			}
			drawLines()
			
           
		}

	}
}

Which I call from the main timeline like so:

var bob:angledLines2 = new angledLines2(600, 600, 50, 0xFF00FD,2, 0x00FF00, 10, -30, 4);
bob.x = 100
bob.y = 100
bob.mouseEnabled = false
addChild(bob);