Archive for the Category »Labs «

Realism with Randomness and Math

One thing I like about game development is the occasional challenge that comes along that requires you to clean out the cob webs in the ol’ noggin and reach back for a few knowledge nuggets that you somehow managed to hold on to from your high school trigonometry class. Take for instance this little problem in recreating Mancala. While it would be simple to neatly order the stones in each of the bowls it would hardly lend itself to any bit of realism. What we need is randomness to create the effect they were tossed in the bowl. So, how can we do that? Observe.


// Random radius.
var new_r:int = (_bowlShp.width/2) - s.width;
new_r = Math.random() * new_r;

// Random angle.
var new_ang:int = Math.random() * (Math.PI * 2);

// Find the new x and y positions.
var new_x:int = Math.cos(new_ang) * new_r;
var new_y:int = Math.sin(new_ang) * new_r;

// Move the stone.
s.x = new_x;
s.y = new_y;

// Random rotation.
s.rotation = Math.random()*360;

Lines 2 and 3 take the radius of the bowl and subtracts the width of the stone. It then finds a random number between 0 and this shortened radius. Line 6 chooses a random angle. Lines 9 and 10 is where the fun comes in. Using our random values and a bit of right triangle trig, new x and y coordinates are chosen for the stone. We finish it off by moving the stone to the new location and giving it a little spin.

Essentially you can think of this whole process as first placing the stone in the center of the bowl, move it out a random distance from the center without falling outside of the bowl, and swing it around from the center at a random angle.

Mancala game stones in bowls

Category: Labs  3 Comments

Where are the Apostles?: An Experiment with Google Maps

I’ve been working on this experiment off and on, but I’m probably at the point where I could share it. This little test satisfies two of my curiosities:

  1. Where are the remains of Christ’s apostles?
  2. How does the Google Maps API work?

Well, here are the answers. I was quite impressed with the level of detail these maps present at an international scale enabling you to locate sites with pinpoint accuracy (check out Peter’s for example). Click on each individual marker for further information.

You can tell I have a few gaps missing, so if you’re up to the challenge send me on some coordinates. I find Wikipedia to be the most resourceful.

Category: Labs  One Comment