Monday, 10 February 2014

Programming Pictures with Pygame

I love 8 bit pixel graphics from old arcade games like Space Invaders! I'm not sure why I loved them so much, perhaps it's because I enjoyed those games so much as a child.


It got me thinking about making my own pictures using code. Perhaps even my own space invader animation!




To make your own Python Pixel Art you will need:

  • Square paper
  • Colouring pencils
  • A Raspberry Pi or a Computer with Python installed

Instructions:

1. Taking a sheet of paper with squares, write 1 through to 9 across one row, and 1-6 down one column to make a grid.
2. Draw your design or space invader in this grid using colouring pencils.
3. On your Raspberry Pi or computer, open IDLE and create a new text editor file by clicking on File and New Window.
4. Start your code by importing the modules you will need:

import pygame, sys

5. Next setup your pygame window using:

pygame.init()

screen = pygame.display.set_mode([225, 150])

6. Next create variables for each of the colours that you wish to use. I've used red and white here, but you can use as many colours as you like:

r = pygame.Color("red") 
w = pygame.Color("white")

7. Now for the fun part, writing the code that will create your picture. Here we can use an array in Python. This is where your diagram from step 1 comes in really handy. Look at row 1 on your drawing and type the first line between square brackets [ ]. Then do row 2, then row 3 and so on:

data = [ 
 [ w, w, r, r, r, r, r, w, w ], 
 [ w, w, r, w, r, w, r, w, w ], 
 [ w, w, r, r, r, r, r, w, w ], 
 [ w, r, r, r, w, r, r, r, w ], 
 [ r, w, w, r, r, r, w, w, r ], 
 [ r, r, w, w, w, w, w, r, r ] 
 ]

8. Next we use a for loop and enumerate to display the picture how we want it. Enumerate allows us to get both the index and the data at that index for every element of the array. For instance, the first time round the outer loop, y = 0 and row = [ w, w, r, r, r, r, r, w, w ].

for y, row in enumerate(data):
  for x, colour in enumerate(row):
    rect = pygame.Rect(x*25, y*25, 25, 25)
    screen.fill(colour, rect=rect)

9. Finally we add the code that will run our pygame program and keep it displaying the image until we want to exit:

pygame.display.update()

while True:
  for event in pygame.event.get():
    if event.type == pygame.QUIT:
      sys.exit()

Challange:

Can you create two pictures and animate them?

Sunday, 9 February 2014

Competition Winners & Working at Raspberry Pi

As ever, this geek gurl has been really busy. 2013 was turly a life changing year for me, as I won an award for Geek Gurl Diaries and even wrote a book 'Adventures in Raspberry Pi'. At the end of the year I made the decision to leave teaching (which was hard and sad) to join the Raspberry Pi Foundation to educate young people globally (which is fun and yay!).


I've been at the foundation for little over a month and can say that I've never been busier! I've been speaking at events like BETT, and running workshops at Raspberry Jam events. But never fear viewers, I am continuing to make videos. Just remember, it takes time to make a final polished piece for your consumption. I'm a perfectionist, and want to you to enjoy computing as much as I do, so be patient!

In the meantime here are the winners from the video competition to win a signed copy of Adventures in Raspberry Pi:


Your prizes will be on their way to you in the next few days. All the best with your Raspberry Pi and programming projects!

Thursday, 28 November 2013

Get the Geek Gurl Diaries Badge!

I attended Mozilla festival again this year, and spent some time in the Open Badges zone creating my very own GGD badge using card, glue, and my imagination. That's the last I thought I would see of it but no! The lovely people at Mozilla made my badge for me! Check it out:




I love it! If you like making and receiving badges, why not check out Mozilla Open Badges yourself. 

Wednesday, 30 October 2013

Geek Gurl Diaries goes to House of Commons!

On Tuesday 29th October 2013, I put my on my finest frock, rallied the troops, and made my way to the House of Commons in London for the Talk Talk Digital Heroes Award Ceremony 2013.

Queen Anne Blend was my favourite, so much so I bought teabags on my way out!

First off, seeing as I was with friends and all dressed up, it seemed silly not to capitalise on the day by visiting Fortnum & Mason's Jubilee Tea Rooms in Picadilly and having Afternoon Tea. (Perhaps I've just been watching too much Downton Abbey?) 

Getting nervous waiting outside the House of Lords


After eating ALL THE CAKES we made our way to the common outside the House of Lord's to meet all the other Digital Heroes from around the UK. They had travelled from all over to my city, which made me feel very guilty indeed. We had many photographs taken of us before we made our way through the most epic security I've ever encountered. Luckily our names were on the list, so we got in!




Team GGD: +Emma B (@embre) & +Alex Bradbury  (@asbradbury) who have supported the project from it's early days and deserved a trip to the House of Commons too!

Very quickly we were whisked through various halls and chambers (which was a little sad as I really wanted to look at the old paintings and architecture, into the Churchill Rooms, where another afternoon tea, this time with Champagne, awaited us. My little party of three quickly became four, as we were joined by my local MP, Jon Cruddas (@JonCruddasMP) who kindly welcomed and entertained us as his guests. 

Lots of hand shaking goes on when you are 'Dagenham's Daughter'

Talk quickly turned to the work that I have been doing in Dagenham at my school, and the work I've been doing on Geek Gurl Diaries. In the course of two hours, the three of us gave one MP: a lecture on the importance of teaching our children computing concepts; the success of my own students; and the possibilities that their futures can hold through being exposed to computer science.   I'm not sure Jon was prepared for what he got, but I'm happy to report it resulted in him wanting to learn more, and organising a visit to my school to see my cs lessons in action. 

Receiving my award from Martha Lane Fox (Co-founder of lastminute.com) , Lloyd Embley (Editor in chief The Mirror) and Talk Dido Harding (CEO Talk Talk)

The award ceremony got into full swing when Chi Onwurah MP (Shadow Minister Business, Innovation & Skills) and Ed Vaizey MP Under Secretary of State for Culture, Communications & Creative Industries gave keynote talks expressing their congratulations to us all for our achievements and for using technology to improve our communities. Then each digital hero was presented with a framed award by the panel of judges.



It was a truly wonderful day, and I hope to continue the discussions that were started with the other digital heroes in a google+ group so that we can help support each other over the next few years. I'm also excited to reply to my MP and invite him to look at what we are doing in Dagenham, and hopefully one day, the world!

Watching this video made me cry! Thanks to Dawn Hewitson (@DawnHewitson) Stemettes (@Stemettes) and +Alan O'Donohoe (@teknoteacher) for taking part and saying such nice things.



Wednesday, 16 October 2013

Adventures In Raspberry Pi - A book for teens and novices

Interested in Raspberry Pi but not sure how to get started? Not sure what to do once it is up and running? Want to learn how to code? Then check out my new book. (Yes, I wrote a book!) Designed to be gender neutral and fun.


Adventures include:

  • Getting set up and started with hardware 
  • Using Linux (both command line and GUI) 
  • Programming in Scratch 
  • Creating graphics with turtle 
  • Programming in Python 
  • Programming Minecraft Pi 
  • Creating music with Sonic Pi 
  • Using GPIO and basic electronics 
  • A final big project Where to go to learn more
Hope you enjoy!

You can purchase from Amazon here.

Sunday, 6 October 2013

Coding Music on a Raspberry Pi using Sonic Pi

Are you the creative type? I know I am, but I've never really been the musical type. Learning a musical instrument always seemed terribly hard work. I take my hat off to anyone that can play more than a tambourine. I love music, doesn't everybody?

Imagine my excitement then when I was introduced to Sonic Pi by +Sam Aaron, an application for the Raspberry Pi that lets your program music! 



What you will need:

  • A Raspberry Pi and peripherals (mouse, keyboard, SD card, monitor, that type of thing!)
  • some headphones or a mini speaker that will plug into the sound jack port on your Pi.
  • The latest version of NOOBS.
  • Your imagination!
You will find the Sonic Pi application on the main menu of the latest version of NOOBS, under 'Programming'. When you first run the software you will need to re size the window to fill the screen so you can see all parts of the interface.

To play a note in Sonic Pi type 'play' followed by a MIDI note number:
play 60

To add timings between the notes type 'sleep' followed by the amount of time. e.g. 1 for one second, 0.5 for half a second, and so on:
sleep 0.5

To repeat or loop a a sequence use:
3.times do 
  play 60 
  sleep 0.5 
end

To add new synths use:
with_synth "fm"

Learn Sonic Pi at School!

As you may know I am a high school/secondary school computing and ICT teacher, so together with Sam who created Sonic Pi, we wrote a scheme of work that can be taught in schools. Here is a post all about it by +Raspberry Pi with a picture of me teaching it in my school:


Why not ask your teachers about it?

Friday, 23 August 2013

Vote for 'Carrie Anne' for a Talk Talk Digital Heroes Award

For the second year running, Geek Gurl Diaries has been nominated for and chosen as a regional finalist, for a Talk Talk digital heroes award. Like last year this part of the competition is subject to a public vote. I narrowly missed out last year, but who knows this could be the year!

Please click on the image below, then 'Voting Gallery', select 'London' from the map, and scroll all the way to the bottom and click 'Vote' under my name 'Carrie Anne'.
Please vote, daily and on multiple devices!

Your support means the world to me, and to be officially recognised for the work I do in my spare time outside of teaching to improve the uptake of computing by teenage girls would really make my year!