# Making the mouse a trailing rainbow

**URL:** https://forum.kirupa.com/t/making-the-mouse-a-trailing-rainbow/232040
**Category:** flash
**Created:** [July 10, 2007, 7:19pm UTC](https://forum.kirupa.com/t/making-the-mouse-a-trailing-rainbow/232040 "2007-07-10T19:19:28Z")
**Posts on this page:** 1
**Page:** 1

<div class="post-metadata">

### Author: ![khaleel](https://avatars.discourse-cdn.com/v4/letter/k/c89c15/32.png) [@khaleel](https://forum.kirupa.com/u/khaleel)
#### Post date: [July 10, 2007, 7:19pm UTC](https://forum.kirupa.com/t/making-the-mouse-a-trailing-rainbow/232040/1 "2007-07-10T19:19:28Z")

</div>

We all now what the [swirling line](http://www.kirupa.com/forum/showthread.php?t=222172&highlight=swirling+line) thing can do. A mouse effect which creates a filled layer trail.

```auto
var points:Array = new Array();
var prev_xmouse:Number;
var prev_ymouse:Number;
this.onEnterFrame = function():Void {
    this.clear();
    this.lineStyle(1, 0xff0000, 0x00ff00, 0x0000ff); //
[COLOR=#000000] **var** [/COLOR] colors:[COLOR=#0066cc]Array[/COLOR] = [COLOR=#006600]**[**[/COLOR]0xff0000, 0x00ff00, 0x0000ff[COLOR=#006600]**]**[/COLOR];
//this.linestyle(gradient fill as if its a rainbox of colors)
//i want different colors coming out
    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)];
}
loop.this.movie();

```

I edited the code above.

I want it so when someone moves the mouse across the screen a color is coming out, say for three seconds its blue, then it blends to red (thats why i put alpha at 12) and obviously added the loop! So it does not stop
