hi, i’m looking to recreate something like the line that follows the mouse on this page:
http://www.agualuca.com/agua.html
I assume that it uses the drawing api and the curveto command. however after much googling i cannot find any tutorials that resemble it.
can anyone help me?
cheers
willgoldstone7:
hi, i’m looking to recreate something like the line that follows the mouse on this page:
http://www.agualuca.com/agua.html
I assume that it uses the drawing api and the curveto command. however after much googling i cannot find any tutorials that resemble it.
can anyone help me?
cheers
thats a pretty sweet drawing effect
i had wondered what you thought of it!
var points:Array = new Array();
var prev_xmouse:Number;
var prev_ymouse:Number;
this.onEnterFrame = function():Void {
this.clear();
this.lineStyle(1, 0x99CC00);
var dx:Number = this._xmouse - prev_xmouse;
var vx:Number = dx ? dx : Math.random() * randSet(-1, 1);
var dy:Number = this._ymouse - prev_ymouse;
var vy:Number = dy ? dy : Math.random() * randSet(-1, 1);
var pLen:Number = points.push({x:this._xmouse, y:this._ymouse, vx:vx / 10, vy:vy / 10, life:getTimer()});
for (var i:Number = 0; i < pLen; i++) {
if (getTimer() - points*.life > 1000) {
points.splice(i--, 1)[0];
} else {
if (i && points*) {
points*.x += points*.vx;
points*.y += points*.vy;
var cx:Number = points[i - 1].x;
var cy:Number = points[i - 1].y;
this.curveTo(cx, cy, (points*.x + cx) / 2, (points*.y + cy) / 2);
} else {
this.moveTo(points*.x, points*.y);
}
}
}
prev_xmouse = this._xmouse;
prev_ymouse = this._ymouse;
};
function randSet():Number {
return arguments[Math.floor(Math.random() * arguments.length)];
}
http://www.ffiles.com/view_listing.php?sid=381&cat=74
:hoser:
You my good fellow, rock.
thanks!
TheCanadian:
ActionScript Code:
[FONT=Courier New][LEFT][COLOR=#000000]**var**[/COLOR] points:[COLOR=#0000FF]Array[/COLOR] = [COLOR=#000000]**new**[/COLOR] [COLOR=#0000FF]Array[/COLOR][COLOR=#000000]([/COLOR][COLOR=#000000])[/COLOR];
[COLOR=#000000]var [/COLOR] prev_xmouse:[COLOR=#0000FF]Number[/COLOR];
[COLOR=#000000]var [/COLOR] prev_ymouse:[COLOR=#0000FF]Number[/COLOR];
[COLOR=#0000FF]this[/COLOR].[COLOR=#0000FF]onEnterFrame[/COLOR] = [COLOR=#000000]function [/COLOR]COLOR=#000000 [/COLOR]:[COLOR=#0000FF]Void[/COLOR] [COLOR=#000000]{[/COLOR]
[COLOR=#0000FF]this[/COLOR].[COLOR=#0000FF]clear[/COLOR]COLOR=#000000 [/COLOR];
[COLOR=#0000FF]this[/COLOR].[COLOR=#0000FF]lineStyle[/COLOR][COLOR=#000000]([/COLOR][COLOR=#000080]1[/COLOR], 0x99CC00[COLOR=#000000])[/COLOR];
[COLOR=#000000]var [/COLOR] dx:[COLOR=#0000FF]Number[/COLOR] = [COLOR=#0000FF]this[/COLOR].[COLOR=#0000FF]_xmouse[/COLOR] - prev_xmouse;
[COLOR=#000000]var [/COLOR] vx:[COLOR=#0000FF]Number[/COLOR] = dx ? dx : [COLOR=#0000FF]Math[/COLOR].[COLOR=#0000FF]random[/COLOR]COLOR=#000000 [/COLOR] * randSet[COLOR=#000000]([/COLOR]-[COLOR=#000080]1[/COLOR], [COLOR=#000080]1[/COLOR][COLOR=#000000])[/COLOR];
[COLOR=#000000]var [/COLOR] dy:[COLOR=#0000FF]Number[/COLOR] = [COLOR=#0000FF]this[/COLOR].[COLOR=#0000FF]_ymouse[/COLOR] - prev_ymouse;
[COLOR=#000000]var [/COLOR] vy:[COLOR=#0000FF]Number[/COLOR] = dy ? dy : [COLOR=#0000FF]Math[/COLOR].[COLOR=#0000FF]random[/COLOR]COLOR=#000000 [/COLOR] * randSet[COLOR=#000000]([/COLOR]-[COLOR=#000080]1[/COLOR], [COLOR=#000080]1[/COLOR][COLOR=#000000])[/COLOR];
[COLOR=#000000]var [/COLOR] pLen:[COLOR=#0000FF]Number[/COLOR] = points.[COLOR=#0000FF]push[/COLOR][COLOR=#000000]([/COLOR][COLOR=#000000]{[/COLOR]x:[COLOR=#0000FF]this[/COLOR].[COLOR=#0000FF]_xmouse[/COLOR], y:[COLOR=#0000FF]this[/COLOR].[COLOR=#0000FF]_ymouse[/COLOR], vx:vx / [COLOR=#000080]10[/COLOR], vy:vy / [COLOR=#000080]10[/COLOR], life:[COLOR=#0000FF]getTimer[/COLOR]COLOR=#000000 [/COLOR][COLOR=#000000]}[/COLOR][COLOR=#000000])[/COLOR];
[COLOR=#0000FF]for[/COLOR] [COLOR=#000000]([/COLOR][COLOR=#000000]var [/COLOR] i:[COLOR=#0000FF]Number[/COLOR] = [COLOR=#000080]0[/COLOR]; i < pLen; i++[COLOR=#000000])[/COLOR] [COLOR=#000000]{[/COLOR]
[COLOR=#0000FF]if[/COLOR] [COLOR=#000000]([/COLOR][COLOR=#0000FF]getTimer[/COLOR]COLOR=#000000 [/COLOR] - points[COLOR=#000000][[/COLOR]i[COLOR=#000000]][/COLOR].[COLOR=#000080]life[/COLOR] > [COLOR=#000080]1000[/COLOR][COLOR=#000000])[/COLOR] [COLOR=#000000]{[/COLOR]
points.[COLOR=#0000FF]splice[/COLOR][COLOR=#000000]([/COLOR]i–, [COLOR=#000080]1[/COLOR][COLOR=#000000])[/COLOR][COLOR=#000000][[/COLOR][COLOR=#000080]0[/COLOR][COLOR=#000000]][/COLOR];
[COLOR=#000000]}[/COLOR] [COLOR=#0000FF]else[/COLOR] [COLOR=#000000]{[/COLOR]
[COLOR=#0000FF]if[/COLOR] [COLOR=#000000]([/COLOR]i && points[COLOR=#000000][[/COLOR]i[COLOR=#000000]][/COLOR][COLOR=#000000])[/COLOR] [COLOR=#000000]{[/COLOR]
points[COLOR=#000000][[/COLOR]i[COLOR=#000000]][/COLOR].[COLOR=#000080]x[/COLOR] += points[COLOR=#000000][[/COLOR]i[COLOR=#000000]][/COLOR].[COLOR=#000080]vx[/COLOR];
points[COLOR=#000000][[/COLOR]i[COLOR=#000000]][/COLOR].[COLOR=#000080]y[/COLOR] += points[COLOR=#000000][[/COLOR]i[COLOR=#000000]][/COLOR].[COLOR=#000080]vy[/COLOR];
[COLOR=#000000]var [/COLOR] cx:[COLOR=#0000FF]Number[/COLOR] = points[COLOR=#000000][[/COLOR]i - [COLOR=#000080]1[/COLOR][COLOR=#000000]][/COLOR].[COLOR=#000080]x[/COLOR];
[COLOR=#000000]var [/COLOR] cy:[COLOR=#0000FF]Number[/COLOR] = points[COLOR=#000000][[/COLOR]i - [COLOR=#000080]1[/COLOR][COLOR=#000000]][/COLOR].[COLOR=#000080]y[/COLOR];
[COLOR=#0000FF]this[/COLOR].[COLOR=#0000FF]curveTo[/COLOR][COLOR=#000000]([/COLOR]cx, cy, [COLOR=#000000]([/COLOR]points[COLOR=#000000][[/COLOR]i[COLOR=#000000]][/COLOR].[COLOR=#000080]x[/COLOR] + cx[COLOR=#000000])[/COLOR] / [COLOR=#000080]2[/COLOR], [COLOR=#000000]([/COLOR]points[COLOR=#000000][[/COLOR]i[COLOR=#000000]][/COLOR].[COLOR=#000080]y[/COLOR] + cy[COLOR=#000000])[/COLOR] / [COLOR=#000080]2[/COLOR][COLOR=#000000])[/COLOR];
[COLOR=#000000]}[/COLOR] [COLOR=#0000FF]else[/COLOR] [COLOR=#000000]{[/COLOR]
[COLOR=#0000FF]this[/COLOR].[COLOR=#0000FF]moveTo[/COLOR][COLOR=#000000]([/COLOR]points[COLOR=#000000][[/COLOR]i[COLOR=#000000]][/COLOR].[COLOR=#000080]x[/COLOR], points[COLOR=#000000][[/COLOR]i[COLOR=#000000]][/COLOR].[COLOR=#000080]y[/COLOR][COLOR=#000000])[/COLOR];
[COLOR=#000000]}[/COLOR]
[COLOR=#000000]}[/COLOR]
[COLOR=#000000]}[/COLOR]
prev_xmouse = [COLOR=#0000FF]this[/COLOR].[COLOR=#0000FF]_xmouse[/COLOR];
prev_ymouse = [COLOR=#0000FF]this[/COLOR].[COLOR=#0000FF]_ymouse[/COLOR];
[COLOR=#000000]}[/COLOR];
[COLOR=#000000]function [/COLOR] randSetCOLOR=#000000 [/COLOR]:[COLOR=#0000FF]Number[/COLOR] [COLOR=#000000]{[/COLOR]
[COLOR=#0000FF]return[/COLOR] [COLOR=#0000FF]arguments[/COLOR][COLOR=#000000][[/COLOR][COLOR=#0000FF]Math[/COLOR].[COLOR=#0000FF]floor[/COLOR][COLOR=#000000]([/COLOR][COLOR=#0000FF]Math[/COLOR].[COLOR=#0000FF]random[/COLOR]COLOR=#000000 [/COLOR] * [COLOR=#0000FF]arguments[/COLOR].[COLOR=#0000FF]length[/COLOR][COLOR=#000000])[/COLOR][COLOR=#000000]][/COLOR];
[COLOR=#000000]}[/COLOR]
[/LEFT]
[/FONT]
http://www.ffiles.com/view_listing.php?sid=381&cat=74
:hoser:
One more thing though, I’ve played around with this code and tried a few different things, ive noticed this code doesnt work when I have a movieClip on the stage at the same time…
Ok just realised it IS working, just beneath what ive got on the stage… any way to bring it to a higher layer / level?
aaand… just been advised to put it in a movieclip, thanks again, i’ll shut up now.
Your welcome and glad you could find the solutions for your other questions :nat: