Jump to content
Search Community

Function for custom Bezier Plugin

protoemocional test
Moderator Tag

Recommended Posts

Hello folks,

 

I improvised a function for the Bezier plugin that may accomodate more easily to a given stage's dimensions.

 

This function is only working for straight lines though, in which either x or y stays the same from the original point and the destination point. Its made to produce a triangular wave along a given line, to give an effect that is opposite to easing...

 

I have 2 questions now:

 

- I'm pretty sure there must be a more efficiente algorithm for producing th tirangular sequence, maybe similar to an actual triangular wave algorithm? I mean that one needs to go from 0 to 3 to 0 to -3 to 0 to 3, etc.... Please, if anyone sees something to fix or to optimize, post it!

 

- The implementation has a bug; it will not complete a given sequence from the array unless the Tween function assigns sufficient time to do so.

 

Please, if anyone can help me, we could contribute something to this community!

BTW, great job to Mr. GreenSock!

 

 

var arr:Array= [];

//f.x and f.y are the destination points, d.x and d.y are the origin poins
Bezier(f.x,d.x,f.y,d.y);


function Bezier(x2:int,x1:int,y2:int,y1:int):void {
var lx:int=x2-x1; //length of line x
var len:int=lx>0?lx:y2-y1; //if line x = 0, line length of line y
var lp:int=Math.round(len/20);  //number of points for the triangle
var xyes:Boolean=lx>0?true:false;  //boolean to pass x or y value length
var up:Boolean=true;   //boolean for the pattern making, wether negative or positive

var ori:int=xyes==true?x1:y1;   //first point of origin
var sine:int=y1;               //point of origin, in this case the y coordinate
var f:int=0;              //int flag for change

trace(sine);


for (var ii:int= 0; ii < lp; ii++) {
	ori+=lp;

	arr.push({x:ori, y:sine});
	if (up) {
		if (sine==126) {
			sine+=3;
		} else {
			sine-=3;
		}
		f++;
		if (f==2) {
			up = !up;
			f=0;
		}
	} else {
		if (sine==126) {
			sine-=3;
		} else {
			sine+=3;
		}
		f++;
		if (f==2) {
			up = !up;
			f=0;
		}
	}
}
}

TweenLite.to(d, 0.5, {bezier:arr});

Link to comment
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now
  • Recently Browsing   0 members

    • No registered users viewing this page.
×
×
  • Create New...