Search tutorials
'
Line Tutorial Page Three
In the next part, our function will look at the magnitude of our slope. If the slope is vertically oreinted or has an absolute value greater than 1, then we will draw our line 1 way, and if the line ihorizontally oriented a different way. It took me a while to realize why my lines where sometimes blurring, but it was becuase I was drawing them to several thousound pixels beyond the Stage's height, and apparently that is too much for Flash to do without some distortion.
In the next part, our function will look at the magnitude of our slope. If the slope is vertically oreinted or has an absolute value greater than 1, then we will draw our line 1 way, and if the line ihorizontally oriented a different way. It took me a while to realize why my lines where sometimes blurring, but it was becuase I was drawing them to several thousound pixels beyond the Stage's height, and apparently that is too much for Flash to do without some distortion.
// the next block is how we will draw the line
// if the absolute value of the slope is greater than 1
else if( (Math.abs( _slope ) > 1) && (_slope != 0) )
// if the absolute value of the slope is LESS than 1
else
The last step:
// if the absolute value of the slope is greater than 1
else if( (Math.abs( _slope ) > 1) && (_slope != 0) )
{// the final block is how we will draw the line
// the next few variables will be soon be used
// when we draw our line
var newDeltY:Number;
var newDeltY2:Number;
var _newX:Number;
var _bttmX:Number;
// Since Flash coutns the top of the stage as y =0
// newDeltY = the y value of our clip
newDeltY = myClip1._y;
// Now use our slope and the prior variable to find
//the x to which we want to draw our line
_newX = myClip1._x + (newDeltY/ _slope);
newDeltY2 = Stage.height- myClip1._y;
_bttmX = myClip1._x - (newDeltY2 / _slope);
// Now move pen of line to _btttmX and Stage.height
//the latter point is the bottom most point of our line
drawLineInThisClip.moveTo( _bttmX , Stage.height);
// Drw line to _newX and the top of the stage ('0')
drawLineInThisClip.lineTo(_newX,0);
}
// if the absolute value of the slope is LESS than 1
else
{} }//end of draw line function
//deltaX is from point to total right (Stage.width)
newDeltX = (Stage.width - myClip1._x);
// endY is the y value corresponding with
//newDeltX on a line with our _slope
endY = ( myClip1._y - ( newDeltX*_slope ));
staRtY = ( myClip1._y )+ (myClip1._x*_slope );
//_totalLeft is at the very top of the function and we initialized it to 0
//because we want to start at the total left of the Stage or x =0
//_totalRight we initialized to Stage.width which is the total right of the stage
// both variables are at the very top of the funtion
drawLineInThisClip.moveTo(_totalLeft, staRtY);
drawLineInThisClip.lineTo(_totalRight,endY);
}
The last step:
_root.onEnterFrame = function(){ perfectLine(_root.point1, _root.point2, 33, 'myline'); };
» Level Intermediate |
Added: 2007-01-21 Rating: 10 Votes: 3 |
» Author |
Webmaster at www.mathwarehouse.com. Visit site to see this line in various Flash based programs. |
» Download |
Download the files used in this tutorial. |
Download (21 kb) |
» Forums |
More help? Search our boards for quick answers! |