# Elastic and Magnet Mouse

I try to reproduce this in openframworks
http://pollivier.free.fr/prod.oldies/magnetikdots/

I have this code
with is done in AS2, my friend gave it to me

`````` package toys.repulsivedots
{
import flash.display.Sprite;
import flash.events.Event;

public class MagnetikSpot extends Sprite
{
var magnet : Number = 5000;
var elektrik : Number = 0.8;
var elastik : Number = 0.4;
var forceX : Number = 0;
var forceY : Number = 0;
var forceZ : Number = 0;
var homeX : Number;
var homeY : Number;

// var homeZ:Number;
public function MagnetikSpot(x : Number, y : Number) : void {
homeX = x;
homeY = y;

}

public function step(e : Event) {
var dX : Number = mouseX + homeX - x;
var dY : Number = mouseY + homeY - y;

var d : Number = Math.sqrt(dX * dX + dY * dY);

var powerX : Number = x - dX / d * magnet / d;
var powerY : Number = y - dY / d * magnet / d;

forceX = (forceX + (homeX - x) / elektrik) * elastik;
forceY = (forceY + (homeY - y) / elektrik) * elastik;

x = powerX + forceX;
y = powerY + forceY;
//z = (powerX * forceY) / 10;
}
}
}
``````

I tried to redo it in openframworks the the behaviour is totaly different.
I had to tweak a bit to get something not even perfect

here is my code

``````void ofApp::setup() {

float magnet  = 5000;
float elektrik = 0.8;
float  elastik  = 0.4;
float   forceX  = 0;
float   forceY  = 0;

for (int i=0; i<NUM_BILLBOARDS; i++) {
pos[i].x = (ofGetHeight()/4)+i*100;
pos[i].y = ofGetHeight()/2;
home[i] = pos[i];
}
}

//--------------------------------------------------------------
void ofApp::update() {

for (int i=0; i<NUM_BILLBOARDS; i++) {
float dX  = -mouseX/15 + hom[i].x - po[i].x;
float dY  = mouseY -ofGetHeight()/2 + home[i].y - pos[i].y;
int d  = sqrt(dX * dX + dY * dY); //Pythagoras theorem

int powerX  = pos[i].x  - dX / d * magnet / d;
int powerY  = pos[i].y  - dY / d * magnet / d;
forceX = (forceX + (home[i].x - pos[i].x) / elektrik) * elastik;
forceY = (forceY + (home[i].y- pos[i].y) / elektrik) * elastik;

pos[i].x = powerX + forceX;
po[i].y = powerY + forceY;

}
}

//--------------------------------------------------------------
void ofApp::draw() {
for (int i=0; i<NUM_BILLBOARDS; i++) {
ofCircle(pos[i].x,pos[i].y, 30);
}
``````

The only thing I understand was Pythagoras theorem
can some help