[Flash 8] Interactive Voronoi Diagram Script..Help(from a flash new_bee)

Hi
I working on the following script(which I got on the net) to generate interactive voronoi diagrams. At the moment additional points on the clip are done by clicking with the mouse, but I would like to amend the part which adds new dots (blue highlighted)so that I can:

option 1: type in the x and y location values of the dots instead

option 2(prefered): link this input of dots to a dynamically generated x and y values from Max/MSP tracking system.(through flashsever).

Pliz help!

killion

script:

MovieClip.prototype.drawLine = function(x1, y1, x2, y2) {
this.moveTo(x1, y1);
this.lineTo(x2, y2);
};
Movieclip.prototype.drawFillCircle = function(x, y, r, c) {
var rx = r+x, ry = r+y, xr = x-r, yr = y-r;
var r07 = r0.7071, r04 = r0.4142;
this.moveTo(rx, y);
this.beginFill©;
this.curveTo(rx, r04+y, r07+x, r07+y);
this.curveTo(r04+x, ry, x, ry);
this.curveTo(x-r04, ry, x-r07, r07+y);
this.curveTo(xr, r04+y, xr, y);
this.curveTo(xr, y-r04, x-r07, y-r07);
this.curveTo(x-r04, yr, x, yr);
this.curveTo(r04+x, yr, r07+x, y-r07);
this.curveTo(rx, y-r04, rx, y);
this.endFill();
};
function init() {
dots = [];
PI = Math.PI;
PI2 = 2PI;
maxSpeed = 5;
dotNum = 0;
distance = [];
sx = [];
sy = [];
ex = [];
ey = [];
appW = Stage.width-1;
appH = Stage.height-1;
gOff = _root.createEmptyMovieClip(“imageOff”, 0);
initDots();
_root.onEnterFrame = run;
_root.onMouseUp = addDotAtMouse;
}
function addDotAtMouse() {
addDot(_xmouse, _ymouse);
}
function run() {
movedot();
setVoronoi();
gOff.clear();
drawVoronoi(0x808080);
}
function initDots() {
var i;
for (i=0; i<3; i++) {
addDot(Math.random()appW, Math.random()appH);
}
}
function addDot(x, y) {
dots[dotNum] = new Object();
dots[dotNum].x = x;
dots[dotNum].y = y;
dots[dotNum].angle = Math.random()PI2;
dots[dotNum].v = Math.random()maxSpeed;
dots[dotNum].m = _root.createEmptyMovieClip(“dot” add dotNum, 10+dotNum);
dots[dotNum].m.drawFillCircle(0, 0, 3, 0x000000);
storage = dotNum+4;
dotNum++;
}
function movedot() {
var i, t;
var a, s, x, y, cx, cy, vx, vy;
for (i=0; i<dotNum; i++) {
x = dots
.x;
y = dots
.y;
a = dots
.angle;
s = dots
.v;
vx = Math.cos(a)s;
vy = Math.sin(a)s;
x += vx;
y += vy;
if (x<3 || x>=appW-3 || y<3 || y>=appH-3) {
if (x<3) {
x = 3;
vx = -1;
}
if (x>appW-4) {
x = appW-4;
vx = -1;
}
if (y<3) {
y = 3;
vy = -1;
}
if (y>appH-4) {
y = appH-4;
vy = -1;
}
dots
.angle = Math.atan2(vy, vx);
}
dots
.m._x = dots
.x=x;
dots
.m._y = dots
.y=y;
if (Math.random()<.1) {
dots
.angle += Math.random()-.5;
}
if (Math.random()<.1) {
dots
.v += Math.random()-.5;
dots*.v = Math.max(0, Math.min(maxSpeed, Math.abs(dots*.v)));
}
}
}
function setVoronoi() {
var i, j, k, m, n;
var a, b, a0, b0, a1, b1, x, y, x0, y0, x1, y1;
for (i=0; i<dotNum; i++) {
x0 = dots*.x;
y0 = dots*.y;
n = istorage+i+1;
for (j=i+1; j<dotNum; j++) {
x1 = dots[j].x;
y1 = dots[j].y;
if (x1 == x0) {
a = 0;
} else if (y1 == y0) {
a = 10000;
} else {
a = -1/((y1-y0)/(x1-x0));
}
b = (y0+y1)/2-a
(x0+x1)/2;
if (a>-1 && a<=1) {
sx[n] = 0;
sy[n] = asx[n]+b;
ex[n] = appW-1;
ey[n] = a
ex[n]+b;
} else {
sy[n] = 0;
sx[n] = (sy[n]-b)/a;
ey[n] = appH-1;
ex[n] = (ey[n]-b)/a;
}
n++;
}
sx[n] = 0;
sy[n] = 0;
ex[n] = appW;
ey[n] = 0;
n++;
sx[n] = .1;
sy[n] = 0;
ex[n] = 0;
ey[n] = appH;
n++;
sx[n] = appW;
sy[n] = 0;
ex[n] = appW-.1;
ey[n] = appH;
n++;
sx[n] = 0;
sy[n] = appH;
ex[n] = appW;
ey[n] = appH;
}
for (i=0; i<dotNum; i++) {
x0 = dots*.x;
y0 = dots*.y;
for (j=0; j<dotNum+4; j++) {
if (j != i) {
if (j>i) {
n = istorage+j;
} else {
n = j
storage+i;
}
if (sx[n]>-Number.MAX_VALUE) {
a0 = (ey[n]-sy[n])/(ex[n]-sx[n]);
b0 = sy[n]-a0sx[n];
for (k=i+1; k<dotNum+4; k++) {
if (k != j) {
m = i
storage+k;
if (sx[m]>-Number.MAX_VALUE) {
a1 = (ey[m]-sy[m])/(ex[m]-sx[m]);
b1 = sy[m]-a1sx[m];
x = -(b1-b0)/(a1-a0);
y = a0
x+b0;
if ((a0x0+b0-y0)(a0sx[m]+b0-sy[m])<0) {
sx[m] = x;
sy[m] = y;
}
if ((a0
x0+b0-y0)(a0ex[m]+b0-ey[m])<0) {
if (sx[m] == x) {
sx[m] = -Number.MAX_VALUE;
} else {
ex[m] = x;
ey[m] = y;
}
}
}
}
}
}
}
}
}
}
function drawVoronoi© {
var i, j, n;
gOff.lineStyle(0, c);
for (i=0; i<dotNum; i++) {
n = i*storage+i+1;
for (j=i+1; j<dotNum+4; j++) {
if (sx[n]>-Number.MAX_VALUE) {
gOff.drawLine(sx[n], sy[n], ex[n], ey[n]);
}
n++;
}
}
}
function angleDifference(t, s) {
var a;
a = t-s;
if (a>PI) {
return (a-PI2);
}
if (a<-PI) {
return (a+PI2);
}