# Manipulating ofNoise to change path of object

I was playing and mixed ofNoise and the ofBall example on the of tutorials page . I wanted to manipulate the balls in such a way that they stay away(80 pixels something) from the centre of the screen . I was able to do it by calculating the distance b/w the centre and the ball and then change the direction of the ball.

``````if(ofDist(x, y, ofGetWidth()/2, ofGetHeight()/2) <80){

x *= -1;
y *= -1;
}
``````

The direction change in the balls is too abrupt in this case and it feels like there is a black ball in the middle that is forcing the small balls outward . How can i achieve the direction change in such a way that it feels like the ball is smoothly deflected . Something like “ofNoise is to ofRandom” :

``````if(ofDist(x, y, ofGetWidth()/2, ofGetHeight()/2) <80){

// smoothly deflect the ball
// ok to have a slightly inward smooth trajectory like a curve
}
``````

Here is the screenshot without the change in direction :

With the ofDist condition change in direction:

I don’t know why i am not able to upload a zip file containing the video , every time i try to upload the zip file,
it gives me an error that the “image size is too big 3072kb” but both the files are less than 2000kb??

Edit : I forgot to mention that the particles already changing directions with ofNoise mapped to the x and y co-ordinate
of the cirlces.

Thanks !

Hi,
what you should do is to operate on the velocity of the ball, rather than its position. In other words, you want to apply a radial force that activates when the ball is at less than the desired distance.
Check “The Nature of Code” by Daniel Shiffman: it’s based on Processing, but the concepts are very easy to translate into openFrameworks.
Best,
Alessandro

Whenever i read that book , i always get confused b/w c++ and processing and start posting stupid Questions like this ->

Even though i know the answers,i get confused ……I wish someone wrote the same book for open frameworks , this book is really amazing .
Thanks, I will go back to this book again……….