# Lottery balls floating, bouncing

**URL:** <https://forum.kirupa.com/t/lottery-balls-floating-bouncing/321527>\
**Category:** flash\
**Created:** [April 21, 2011, 11:14pm UTC](https://forum.kirupa.com/t/lottery-balls-floating-bouncing/321527 "2011-04-21T23:14:30Z")\
**Posts on this page:** 1\
**Page:** 1

<div class="post-metadata">

**Author:** ![somnamblst](https://avatars.discourse-cdn.com/v4/letter/s/a4c791/32.png) [@somnamblst](https://forum.kirupa.com/u/somnamblst)\
**Post date:** [April 21, 2011, 11:14pm UTC](https://forum.kirupa.com/t/lottery-balls-floating-bouncing/321527/1 "2011-04-21T23:14:30Z")

</div>

Trying to wrap my mind around how lottery balls fly around in those air bubbles. They are pushed up and around I assume, and they bounce off each other and the round sides of the container.

I have been searching for examples but only found a Stringy example from 2005

> **[Lottery Game Help](https://www.kirupa.com/forum/showthread.php?t=200612&highlight=%22lottery+balls%22)**
>
> Got a web design/development question or just want to hang out with the most awesome people on the planet? Drop on in!

```auto
var r=circle._width/2
for (var i = 0; i<20; i++) {
 var clip = this.attachMovie("mc", "mc"+i, i);
 clip._x = circle._x+Math.random()*50-25;
 clip._y = circle._y+Math.random()*50-25;
 clip.velx =Math.random()*10-5
 clip.vely =Math.random()*10-5
 clip.onEnterFrame =move
}
function move(){
 this._x +=this.velx
 this._y +=this.vely
 this.x = this._x-circle._x
 this.y = this._y-circle._y
 this.d =Math.round(Math.sqrt(this.x*this.x+this.y*this.y))
 if(this.d>r-this._width/2){
  this.velx*=-1
  this.vely*=-1
 }
}

```
