# Flash 8 dynamic drawing api

**URL:** <https://forum.kirupa.com/t/flash-8-dynamic-drawing-api/186379>\
**Category:** Uncategorized\
**Created:** [April 20, 2006, 9:51pm UTC](https://forum.kirupa.com/t/flash-8-dynamic-drawing-api/186379 "2006-04-20T21:51:41Z")\
**Posts on this page:** 9\
**Page:** 1

<div class="post-metadata">

**Author:** ![willgoldstone7](https://yyz1.discourse-cdn.com/flex011/user_avatar/forum.kirupa.com/willgoldstone7/32/2251_2.png) [@willgoldstone7](https://forum.kirupa.com/u/willgoldstone7)\
**Post date:** [April 20, 2006, 9:51pm UTC](https://forum.kirupa.com/t/flash-8-dynamic-drawing-api/186379/1 "2006-04-20T21:51:41Z")

</div>

hi, i’m looking to recreate something like the line that follows the mouse on this page:

[http://www.agualuca.com/agua.html](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

---

<div class="post-metadata">

**Author:** ![joran420](https://yyz1.discourse-cdn.com/flex011/user_avatar/forum.kirupa.com/joran420/32/2329_2.png) [@joran420](https://forum.kirupa.com/u/joran420)\
**Post date:** [April 20, 2006, 10:19pm UTC](https://forum.kirupa.com/t/flash-8-dynamic-drawing-api/186379/2 "2006-04-20T22:19:25Z")

</div>

> [@willgoldstone7](#):
>
> hi, i’m looking to recreate something like the line that follows the mouse on this page:
> 
> [http://www.agualuca.com/agua.html](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

---

<div class="post-metadata">

**Author:** ![willgoldstone7](https://yyz1.discourse-cdn.com/flex011/user_avatar/forum.kirupa.com/willgoldstone7/32/2251_2.png) [@willgoldstone7](https://forum.kirupa.com/u/willgoldstone7)\
**Post date:** [April 21, 2006, 7:34am UTC](https://forum.kirupa.com/t/flash-8-dynamic-drawing-api/186379/3 "2006-04-21T07:34:16Z")

</div>

> [@joran420](#):
>
> thats a pretty sweet drawing effect

i had wondered what you thought of it!

---

<div class="post-metadata">

**Author:** ![TheCanadian](https://avatars.discourse-cdn.com/v4/letter/t/67e7ee/32.png) [@TheCanadian](https://forum.kirupa.com/u/TheCanadian)\
**Post date:** [April 21, 2006, 9:35am UTC](https://forum.kirupa.com/t/flash-8-dynamic-drawing-api/186379/4 "2006-04-21T09:35:34Z")

</div>

```auto
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](http://www.ffiles.com/view_listing.php?sid=381&cat=74)  
:hoser:

---

<div class="post-metadata">

**Author:** ![willgoldstone7](https://yyz1.discourse-cdn.com/flex011/user_avatar/forum.kirupa.com/willgoldstone7/32/2251_2.png) [@willgoldstone7](https://forum.kirupa.com/u/willgoldstone7)\
**Post date:** [April 21, 2006, 10:16am UTC](https://forum.kirupa.com/t/flash-8-dynamic-drawing-api/186379/5 "2006-04-21T10:16:52Z")

</div>

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](http://www.ffiles.com/view_listing.php?sid=381&cat=74)  
> :hoser:

---

<div class="post-metadata">

**Author:** ![willgoldstone7](https://yyz1.discourse-cdn.com/flex011/user_avatar/forum.kirupa.com/willgoldstone7/32/2251_2.png) [@willgoldstone7](https://forum.kirupa.com/u/willgoldstone7)\
**Post date:** [April 21, 2006, 10:34am UTC](https://forum.kirupa.com/t/flash-8-dynamic-drawing-api/186379/6 "2006-04-21T10:34:32Z")

</div>

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…

> [@willgoldstone7](#):
>
> You my good fellow, rock.
> 
> thanks!

---

<div class="post-metadata">

**Author:** ![willgoldstone7](https://yyz1.discourse-cdn.com/flex011/user_avatar/forum.kirupa.com/willgoldstone7/32/2251_2.png) [@willgoldstone7](https://forum.kirupa.com/u/willgoldstone7)\
**Post date:** [April 21, 2006, 10:56am UTC](https://forum.kirupa.com/t/flash-8-dynamic-drawing-api/186379/7 "2006-04-21T10:56:17Z")

</div>

Ok just realised it IS working, just beneath what ive got on the stage… any way to bring it to a higher layer / level?

> [@willgoldstone7](#):
>
> 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…

---

<div class="post-metadata">

**Author:** ![willgoldstone7](https://yyz1.discourse-cdn.com/flex011/user_avatar/forum.kirupa.com/willgoldstone7/32/2251_2.png) [@willgoldstone7](https://forum.kirupa.com/u/willgoldstone7)\
**Post date:** [April 21, 2006, 1:02pm UTC](https://forum.kirupa.com/t/flash-8-dynamic-drawing-api/186379/8 "2006-04-21T13:02:28Z")

</div>

aaand… just been advised to put it in a movieclip, thanks again, i’ll shut up now.

> [@willgoldstone7](#):
>
> Ok just realised it IS working, just beneath what ive got on the stage… any way to bring it to a higher layer / level?

---

<div class="post-metadata">

**Author:** ![TheCanadian](https://avatars.discourse-cdn.com/v4/letter/t/67e7ee/32.png) [@TheCanadian](https://forum.kirupa.com/u/TheCanadian)\
**Post date:** [April 21, 2006, 7:47pm UTC](https://forum.kirupa.com/t/flash-8-dynamic-drawing-api/186379/9 "2006-04-21T19:47:35Z")

</div>

Your welcome and glad you could find the solutions for your other questions :nat:
