# Help with function

**URL:** <https://forum.kirupa.com/t/help-with-function/215055>\
**Category:** Uncategorized\
**Created:** [February 3, 2007, 3:23pm UTC](https://forum.kirupa.com/t/help-with-function/215055 "2007-02-03T15:23:31Z")\
**Posts on this page:** 1\
**Page:** 1

<div class="post-metadata">

**Author:** ![andrewburgess](https://avatars.discourse-cdn.com/v4/letter/a/94ad74/32.png) [@andrewburgess](https://forum.kirupa.com/u/andrewburgess)\
**Post date:** [February 3, 2007, 3:23pm UTC](https://forum.kirupa.com/t/help-with-function/215055/1 "2007-02-03T15:23:31Z")

</div>

Hi,

I dont know so much about actionscript. There is this function called splat which you can view there [http://img.stamen.com/drawing/lines\_splat.html](http://img.stamen.com/drawing/lines_splat.html). The challenge is i need to use this function and constrict it to an area within the stage.

This is the function, the actions on the first frame:

[SIZE=“2”][FONT=“Courier New”][COLOR=“Navy”]function splat(obj, x1, y1, x2, y2, x3, y3, d) {  
var \_loc3 = obj;  
shadow = 1;  
\_loc3.lineStyle(d, \_root.colora, 100);  
\_loc3.moveTo(x1, y1);  
\_loc3.curveTo(x3, y3, x2, y2);  
dd = Math.sqrt(Math.pow(x2-x1, 2)+Math.pow(y2-y1, 2));  
var i = 0;  
while (i\<Math.floor(5_Math.pow(Math.random(), 4))) {  
var \_loc1 = dd_4\*(Math.pow(Math.random(), 2)-5.000000E-001);  
var \_loc2 = dd_4_(Math.pow(Math.random(), 2)-5.000000E-001);  
var x5 = Math.random()-5.000000E-001;  
var y5 = Math.random()-5.000000E-001;  
\_loc3.lineStyle(d\*(5.000000E-001+Math.random()), \_root.colora, 100);  
\_loc3.moveTo(x1+\_loc1, y1+\_loc2);  
\_loc3.lineTo(x1+\_loc1+x5, y1+\_loc2+y5);  
++i;  
}  
// end while  
}  
// End of the function  
var new\_size\_influence;  
var mid\_point\_push;  
var max\_line\_width;  
new\_size\_influence = Math.floor(Math.random()\*20)/10-5.000000E-001;  
mid\_point\_push = Math.floor(Math.random()\*8)/4-1;  
new\_size\_influence = 5.000000E-001;  
mid\_point\_push = 7.500000E-001;  
max\_line\_width = Math.random()\*50+50;  
[/COLOR][/FONT][/SIZE]

There is a movieclip which contains this script:

[SIZE=“2”][FONT=“Courier New”][COLOR=“Navy”]setProperty("", \_x, 0);  
setProperty("", \_y, 0);  
var start\_x;  
var start\_y;  
var mid\_x;  
var mid\_y;  
var end\_x;  
var end\_y;  
var parity;  
var size;  
start\_x = mid\_x = end\_x = Stage.width / 2;  
start\_y = mid\_y = end\_y = Stage.height / 2;  
parity = false;  
size = 0;[/COLOR][/FONT][/SIZE]

This movieclip has these actionscript attached to it:

[SIZE=“2”][FONT=“Courier New”][COLOR=“Navy”]onClipEvent (load) {  
\_root.colora = random(100000000);  
}  
onClipEvent (mouseMove)  
{  
mid\_x = (end\_x - start\_x) \* (1 + \_parent.mid\_point\_push) + start\_x;  
mid\_y = (end\_y - start\_y) \* (1 + \_parent.mid\_point\_push) + start\_y;  
start\_x = end\_x;  
start\_y = end\_y;  
end\_x = \_xmouse;  
end\_y = \_ymouse;  
distance = Math.sqrt(Math.pow(end\_x - start\_x, 2) + Math.pow(end\_y - start\_y, 2));  
new\_size = \_parent.max\_line\_width / distance;  
size = \_parent.new\_size\_influence \* new\_size + (1 - \_parent.new\_size\_influence) \* size;  
\_parent.splat(this, start\_x, start\_y, end\_x, end\_y, mid\_x, mid\_y, size);  
}  
onClipEvent (mouseDown)  
{  
\_root.colora = “255255255”;  
}  
onClipEvent (mouseUp)  
{  
\_root.colora = random(100000000);  
}[/COLOR][/FONT][/SIZE]
