Random walk with Actionscript

January 7th, 2007 . by polyGeek

It’s amazing to me how something so simple can be so subtlety beautiful. Below is a demonstration of a random walk, or drunkards walk as it is sometimes called. Simply put, each step is a random distance and angle from the previous step.

Download FLA

The code needed to create this is rather simple. It uses nothing more complex than the drawingAPI and an onEnterFrame. Note: there are no checks to make sure that the last step stays on the visible stage. If you want to play around with this you could do things like randomly change the color, use curveTo instead of lineTo, have multiple walkers of varying colors walking around simultaneously, etc. Use your imagination.

A bit of code that you might find useful are the first two lines of code from the drawVector function. This code finds the point to draw to when it only knows the starting point, distance and angle. This bit could come in handy in a number of instances.

Share and Enjoy: These icons link to social bookmarking sites where readers can share and discover new web pages.
  • del.icio.us
  • Reddit
  • Slashdot
  • StumbleUpon
  • Technorati
  • Digg
  • Facebook

Leave a Reply

Name

Mail (never published)

Website

- Why ask? This confirms you are a human user!

   




© Copyright 2008 polyGeek.com / Dan Florio, All Rights Reserved Except Where Explicitly Stated
Web Developement Blogs - Blog Catalog Blog Directory
M2 Websites