Skip to content

Instantly share code, notes, and snippets.

@nervoussystem
Created May 13, 2010 16:12
Show Gist options
  • Select an option

  • Save nervoussystem/400005 to your computer and use it in GitHub Desktop.

Select an option

Save nervoussystem/400005 to your computer and use it in GitHub Desktop.
//wrap around so it cannot get too far away
//get the vector from dla_center to current_circle
PVector center_to_circle = PVector.sub(current_circle,dla_center);
float sq_dist = sq(center_to_circle.x)+sq(center_to_circle.y);
if(sq_dist > bound_radius_sq) {
float prev_dist = sqrt(sq_dist);
//make the distance outside of the radius into the amount inside
//bound_radius-(prev_dist-bound_radius)
float new_dist = 2*bound_radius-prev_dist;
center_to_circle.mult(-new_dist/prev_dist);
current_circle.x = center_to_circle.x+dla_center.x;
current_circle.y = center_to_circle.y+dla_center.y;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment