Social media generated art in Python #ThisIsMyClassroom #Programming #STEAM

Social media generated art in Python #ThisIsMyClassroom #Programming #STEAM

For the third blog post on this topic I wanted to use Python to generate different pieces of art without relying entirely on the random function. I decided to use the tweepy library, mainly because I had already used it to post content to Twitter but had never investigated how it could be used to read information back from Twitter.

It didn’t take long to find out how to read the latest 10 tweets from my own timeline using Python. Then I split the individual words into a list and sorted them into alphabetical order (for no real reason at the moment, but frequency analysis will follow!). Then I used the write method from the Turtle graphics library to place each word at a random location on the screen. This was my first attempt:

Screen Shot 2016-04-03 at 23.50.08

A bit tricky to read the words I thought. And I’d accidentally forgotten to penup before moving the turtle. However this accidental vector spider web became part of the artwork (because when I removed it, it looked quite boring).

A little while later I was able to change the font size at random (I changed the font to palatino after experimenting with a few others) and changing the pencolor in the same way as previous Python art programs changed the text colour too.

Screen Shot 2016-04-03 at 23.53.35

I had a lot of text to display, even just from 10 tweets, so I thought of ways to reduce the amount. I wrote a little Python subroutine that removed hashtags, mentions and URLs (as well as any other non ASCII text) and that was enough!

The video below shows the program in action. I decided to make a video this time because you can make out the individual words much more clearly at the beginning of the drawing than at the end!

As before the code is now on github (with my tweepy details removed for security). I’ve left in a commented out section of code that allows you to run a search for a keyword, hashtag or phrase instead of taking the latest timeline so you can experiment.

Any comments or improvements would be much appreciated!



I had a lot of fun experimenting with the subroutines and Python Turtle methods yesterday but wanted to push it a little further and find out if I could make use of a new Python library to help create automated art.

Somehow I’ve never built a program that utilises and analyses audio before, so challenged myself to find out more about libraries such as PyAudio and Wave this afternoon. My daughter was practising piano in the other room so it gave me a push to integrate live audio into my solution, rather than rely on pre-recorded wav files.

I learned about numpy a little this afternoon too. I hadn’t realised it had functions to extract the frequency from an audio block (FFT). The more I explore Python, the more I fall in love with it as a language!

Once I’d successfully extracted numeric frequencies from the 5 second wave file into a list I looped through them and attempted to place shapes on the Python Turtle screen to correlate with the current frequency. I decided on a simple X axis plot to begin with but then, as I realised the range between min and max frequencies usually exceeded 8000 I introduced a scale factor so they could be seen on the screen together and adjusted the Y axis so that each frequency appeared bottom to top in the order of analysis.

Screen Shot 2016-03-31 at 18.18.40

Quite nice, but there’s a lot of white space where the unused frequency range lies. Instead of removing this range from the visualisation (which, in retrospect, might have been a good idea) I decided to attempt to create ghosts of the circles fading out as they get further from the original position. This led me into colorsys and all sorts of bother, reminding me (eventually) not to mess with anything that returns a Tuple until I convert it back to a List first. Anyway, I removed that part of the code and put my arty effects on the back burner. You can see one example of the mess below. Ugh.

Screen Shot 2016-03-31 at 18.19.00

I decided to alter the colour of the background this time too. I think I’d like to use some audio analysis to decide on the colour range in a future version so that low audio frequencies create darker images and high frequencies create bright, bubblegum pop images.

Screen Shot 2016-03-31 at 18.06.42

The last thing I added to the program was the option to use pre-recorded audio WAV files instead of always recording 5 seconds of audio. This was very easy to add as I’d modularised the code as I went, so all that was needed was a few lines extra in the main program:

Screen Shot 2016-03-31 at 19.08.33

Trying out the program with a few WAV files from or playing a YouTube video in the background resulted in the following images:

uptown funk
uptown funk

Python files can be found at Github – Feel free to fork the code, leave comments below or just enjoy the images it generates!

Computer Generated Art #thisismyclassroom #programming #steam

Computer Generated Art #thisismyclassroom #programming #steam

Screen Shot 2016-03-31 at 02.22.22

I wanted to create a task that allowed students to create a computer program in Python that would automatically create its own artwork but be customisable so that each student could experiment and personalise their own program to their tastes.

Screen Shot 2016-03-31 at 02.15.10

It’s a rough Python 3 program using the Turtle library and an array of Turtles but so far it has produced some really nice work. In the images shown below the program uses a user-defined function that draws a randomly sized square. I thought this would be easy for the students to understand and hack into something new!

Screen Shot 2016-03-31 at 02.15.24

Of course art can be created as a response to an external stimulus so a possible extension of this program would be to get input from the user (colours, mood, age) or calculate a range of colours from an input sensor or device (temperature, time, image).

Screen Shot 2016-03-31 at 02.15.38

The code is below! Any suggestions or improvements would be appreciated!

import turtle
import random
wn = turtle.Screen()
w = wn.window_width()
h = wn.window_height()

t1 = turtle.Turtle()
t2 = turtle.Turtle()
t3 = turtle.Turtle()
t4 = turtle.Turtle()
t5 = turtle.Turtle()
t6 = turtle.Turtle()

turtles = [t1, t2, t3, t4, t5, t6]

def square(item, size):
for x in range(4):
item.left(random.randrange(-180, 180))

for iteration in range(3):
for item in turtles:
for move in range(2500):
for item in turtles:


Screen Shot 2016-03-31 at 02.51.34

Screen Shot 2016-03-31 at 02.54.57

Using CodeBug tethered via USB on a MacBook

It has been a few weeks since our CodeBugs arrived here in Milan and after playing around with some of the sample programs and thinking about their features I have decided to use these with next session’s Year 10 students as an introduction to the iGCSE Computer Science course in September.

While they worked really well with the Raspberry Pi I struggled to get the CodeBugs working with IDLE on the MacBook. Installing packages via Terminal updated the Python 2.7 install that comes with the OS and – for me anyway – Homebrew complicated what should have been a very easy process. In Visual Studio if you wanted to use a module library you simply added it to the project and IDLE does not have this function.

I found PyCharm today – an IDE for Python that allows me to add the codebug_tether module (and any others I need) with the minimum of fuss. Now my CodeBug can be programmed while connected via USB to my MacBook! As an added bonus I learned more about Virtual Environments.


To make it easier for my students to get going with their CodeBugs in September I created a 20-step guide linked here. It’s CC0 so please feel free to use and adapt as required. If you find any mistakes or it just doesn’t work for you in the same way please let me know.

Clean slate classroom: What would you do?


I’m thinking about classroom design this evening.

My current classroom is suitable for any subject area – as long as there are less than 12 students. I’m considering how to make it stand out as a Computer Science and STEM classroom while still retaining practicality and space to move!

I’ve thought about my movement in the current classroom, what irritates me about current organisation that -if changed- will have a positive impact on my classes, my desire to amalgamate the classroom and STEM club (currently two floors apart) and how the room should be primarily a place for students to learn, but also a place that promotes the subject to visitors.

The current STEM room has desktop monitors that I have moved into the classroom in the past (two floors apart remember?). These dominate the layout and take up a lot of space when not being used so I am interested in trialling some HDMIPi screens which can be stored away when not in use.

I also want it to be a fun environment where students can interact or change some of the elements. Ideas for this include an interactive electronics wall where elements can be added or removed to change how it works, multi coloured dry erase vinyl stickers that can be placed on walls and desks, and easy access computing kits that are in magnetic containers stuck to a themed wall. I want to maximise what students can do in lessons while minimising the daily prep required to get the room ready and then reset.

Not included in the sketches are alternative seating or the location of the tall benches.

Nothing is to scale. Comments and suggestions would be lovely!


Investigating Arduino #Gemma – Adapting Blink code to control 2 LEDs #STEAM

After a reader suggestion (thanks Kathleen!) I’ve also included the adapted blink code below and on my GitHub:

Getting started with Arduino #Gemma #STEAM

Getting started with Arduino #Gemma #STEAM


Tonight I found time to finally open the Arduino Gemma that arrived just before the October break.

It comes with no instructions, but Adafruit have plenty of guides on their website. However depending on where you start, you may waste a bit of time. More on that below.

The first guide I read told me nothing about how to use the Gemma, just what it was, and offered no links to follow up guides. Thanks.

The second guide I found recommended the website as a way to program the Gemma to do what I wanted. I figured that this would be a good place to start and that I could learn from other users on the site. It started quite promisingly, with a Getting Started Guide that took me through the process of installing the Chrome extension, Arduino drivers and then… well then it wouldn’t let me get any further because… the Adafruit Gemma programmers aren’t yet supported for the codebender app! There was no explanation behind the error message (what exactly ARE programmers in the context of Arduinos?) and I imagine that other beginning Arduino users like myself would have been bemused by the lack of user assistance.

Back to the adafruit website where I find some information about drivers. They confirm I have the Arduino Gemma because it’s teal not black. This is useful information and it means that my time on the Adafruit website has been wasted. I’m also still bemused at why codebender only offered Adafruit Gemma as an option earlier.

Right. Off to the Arduino website to see if they can be any more help. I now ignore all Adafruit guides in my Google search results.

I install the Arduino IDE and connect the mini USB cable to my Gemma. Red and green LEDs flicker and then there is a steady green LED.

Screen Shot 2015-11-01 at 19.20.36

I find and copy the Blink code into the Arduino IDE, following the instructions in the comments (good work, see above). However the IDE is obviously now different and “Upload using Programmer” is now in the Sketch menu. By the time I’d found the correct menu the 10 seconds of red LED blinking had passed and I had to press the reset button a few times on the Gemma to get it blinking again. Second time around the code transferred successfully.

I looked for a way to run the code, but then realised that the steady blinking red LED was the code running!

I’m off to investigate some more code now but thought I should summarise with my steps to getting the first program running on my Arduino Gemma:

  1. Download the Arduino IDE
  2. Connect the Arduino Gemma to Macbook via mini USB cable, make sure LEDs are lit
  3. (Windows users have to download drivers)

  4. Copy the Blink code into the code window on the Arduino IDE, replacing ALL text that is there
  5. Select Arduino Gemma from the Tools > Board menu
  6. Select Arduino Gemma from the Tools > Programmer
  7. Press the small button on the Gemma between the red and green LEDs. The red LED will glow dimly then begin to pulse. This means it is ready to receive data
  8. In the Arduino IDE select Sketch > Upload Using Programmer while the red LED is pulsing (you have 10 seconds to comply)
  9. Check the Arduino IDE output message. If there is an error message I suggest you repeat steps 6 and 7.

Screen Shot 2015-11-01 at 19.35.03

At this point – perhaps after a short wait – the red LED on the Gemma board should begin to blink slowly. This is confirmation of the program running!

Full STEAM ahead!

Full STEAM ahead!

It’s late. I’ll not apologise for that title.


After rediscovering the missing Raspberry Pi SD cards (lets put their reappearance down to pixies) I was back on track to start the STEAM club in my High School today. My colleague had already successfully started his club with younger students a few weeks before and the Kano kits, Lego Mindstorms and drones were going down a storm.


Our space is a reclaimed dormitory in the top floor of the school. It currently has five desks, four Kano kits and lots of my imported Raspberry Pi goodies. The students spent today setting up their Kanos and exploring the gamified Kano OS. I did wonder if the High School students would consider the system a bit young for them, but I had no reason to worry, they loved it and spent a long time extending the python Snake Game and then coding different objects in Minecraft.

Screen Shot 2015-10-15 at 22.29.22

In the coming weeks we will begin to use TinkerCad to learn about 3D modelling and design with the intention of creating prototypes on the wonderful Ultimaker 2 3D printer and (if possible) importing some of their models into Minecraft. We are also going to visit the new Makerspace at Museo Scienza to gain inspiration for customising our own workspace. I’d like to explore WeMake too…

We would love to link with other school Makerspaces or STEAM / STEM clubs around the world. Please post your details in the comments and we’ll be in touch!