Loginskip to content

Archive for October 29th, 2006

NXT Life

Sunday, October 29th, 2006

Based on a comment in the nxtasy forums about a version of the Life simulator written in NBC that was unusably slow, I decided to try my hand at writing a speedier version.

The original code is written by forum user bk227865. He kindly shared a copy of his code with me and I started ripping it apart and building it up again. Originally, the program kept an array of bytes with 6400 entries which was used to mark whether a pixel on the screen was a live cell or a dead cell. A faster way to implement Life is to just keep an array of live cell indices. This will generally be a relatively small array which can be used to paint the screen very quickly.

After a generation has been drawn on the screen then a new array is built containing all the live cell indices from the previous generation plus all their neighbors which may become live in the next generation. This next generation array is then processed to count how many live neighbors each cell indice has. I can think of a way to optimize this further to make it even faster at calculating the next generation of live cells, but I’ll leave that as an exercise for the reader for now. :-)

In my version of NXT Life with a glider and a blinker on the screen, like in bk227865’s original code, each generation takes a little less than 0.8 seconds to draw. When the glider intersects the blinker and additional live cells appear in subsequent generations the time it takes to calculate the next generation increases.

The program uses a macro called MakeCellLive to draw the first generation state. If you want to try other Life shapes you can modify this section of the program.

You can get a copy of Life on the NBC Samples page. It’s the first item on the page. I also posted it to the nxtasy forums.

New Products from HiTechnic

Sunday, October 29th, 2006

HiTechnic has posted information about four new product offerings! Here’s a summary from their site:

NXT Prototype Board (shown)

The HiTechnic Prototype board gives you an easy-to-use platform to build your own sensors or interface to other devices. The Prototype board comes with a complete and operating NXT I2C interface to give you a head start on your design.

NXT Color Sensor

The NXT Color Sensor operates by using three different color light emitting diodes (LED) to illuminate the target surface and measures the intensity of each color reflected by the surface. Using the relative intensity of each color reflection, the color sensor calculates a Color Number that is returned to the NXT program.

NXT Acceleration Sensor

The NXT Acceleration Sensor contains a three axis accelerometer that measures acceleration in three axes, x, y and z. Acceleration is measured in the range of –2g to +2g with scaling of approximately 200 counts per g.

NXT Extended Connector Cable Set

The Extended Connector Cable Set contains four cables in total, two cables shorter than the standard Mindstorms cables and two cables longer than the standard Mindstorms cables. Cables has standard NXT style RJ12 plugs on each end.

[via TheNXTStep]