User avatar
ben_nuttall
Posts: 235
Joined: Sun Aug 19, 2012 11:19 am
Location: Cambridgeshire, UK
Contact: Website Twitter

BN Astro Pi Examples

Sun May 24, 2015 1:03 pm

I've made a few example scripts and stuck them on GitHub: https://github.com/bennuttall/astro-pi-examples/

Examples so far:

- Random Sparkles
- Conway's Game of Life
- Minecraft Colour
- Minecraft Map
- Colour Match
Former RPF staff. Author of gpiozero and creator of piwheels.

OllieT
Posts: 4
Joined: Sun May 24, 2015 1:33 pm

Re: BN Astro Pi Examples

Sun May 24, 2015 6:00 pm

To get the conway game to work had to change 'ap.set_pixel(x, y ,color)'
to 'ap.set_pixel(x, y, color[0], color[1], color[2])' otherwise a 'set_pixel() takes exactly 6 arguments' error was thrown

User avatar
Davespice
Forum Moderator
Forum Moderator
Posts: 1665
Joined: Fri Oct 14, 2011 8:06 pm
Location: The Netherlands
Contact: Twitter

Re: BN Astro Pi Examples

Sun May 24, 2015 6:23 pm

OllieT wrote:To get the conway game to work had to change 'ap.set_pixel(x, y ,color)'
to 'ap.set_pixel(x, y, color[0], color[1], color[2])' otherwise a 'set_pixel() takes exactly 6 arguments' error was thrown
Ah, you may have an older version of the API installed on your Pi.
If you run these commands it will update it to the latest version:

Code: Select all

cd ~/astro-pi-hat
git fetch origin
git reset --hard origin/master
sudo python setup.py install
sudo python3 setup.py install

User avatar
ben_nuttall
Posts: 235
Joined: Sun Aug 19, 2012 11:19 am
Location: Cambridgeshire, UK
Contact: Website Twitter

Re: BN Astro Pi Examples

Mon May 25, 2015 2:47 am

As Dave said, we changed the API before the v1.0.0 release to allow passing of the colour in either individual r, g, b values or a 3-tuple containing (r, g, b).

Sometimes you just want to have a bunch of colours declared, like black, white, blue, red, green, and pass the colour in.
Sometimes, you're incrementing and decrementing individual RGB colour values in a loop so you want to pass them in separately.

Currently the best way to update your version of the library is to clone it from git and run "sudo python3 setup.py" or "sudo python setup.py" but before long we'll have it packaged in Raspbian.

To find out what version you have, run the following from the command line:

Code: Select all

python3 -c "import astro_pi as ap; print(ap.__version__)"
python -c "import astro_pi as ap; print(ap.__version__)"
I think it was set at v0.0.0 until we released v1.0.0 and there haven't been any code changes since then.
Former RPF staff. Author of gpiozero and creator of piwheels.

Return to “Astro Pi”