The Top 5 Hidden Features of Python

Python aims to be an elegant and expressive language; this post includes its top 5 hidden features:

  1. List slicing
  2. For…else syntax
  3. Yield statement
  4. Multiple assignments
  5. Argument unpacking

The term hidden is loosely used to indicate features which are generally unique to Python, or not very well known. I covered the most interesting Easter eggs which are really hidden in Python in this post. Continue reading

Game Barcode: A Study of Colours in Games

This tutorial shows how to download videos from YouTube and to process their frames with Python; I have used this technique to create game barcode, an image created by sorting the colours in each frame of a particular video. You can see some of most intriguing here:

This tutorial is divided in four parts:

Continue reading

Interactive Graphs in the Browser

Having worked both as a teacher and an artist, I know how important data visualisation is. This tutorial will teach you to create interactive network graphs with Python and JavaScript. You can have a go by dragging the nodes of the graph below…

You can find a high resolution version of the melancoil tree (2000x2000px, first 1000 numbers) here: PNG, SVG, HTML. Continue reading

Recreational Maths in Python

This post is for all the developers and mathematicians out there that are curious to explore and visualize the bizarre properties of numbers. Although Maths plays an important role in today’s technology, many people likes to abuse it for recreational purposes. Part of the appeal of Recreational Maths lies in the challenge to discover something new. Despite what many believe, finding mathematical patterns is very easy; it’s discovering something useful that is incredibly challenging. If you’re up for such a challenge, this tutorial will teach you how to use Python to calculate some of the most infamous numerical sequences.

Continue reading

The incredibly challenging task of sorting colours

Let’s start with something trivial: sorting numbers. Regardless of the algorithm you’ll use, real numbers are naturally ordered. Mathematically speaking, they have a total order, in the sense that you can always decide if a number is greater than another one. There is no ambiguity in this, meaning you can actually sort them, and (excluding duplicates) this sort is unique. There are other fields which are not that lucky: colour, for instance, are very unlucky. Supposing you’re representing colours with their RGB values, there is no standard way to order triples in a line, since they are naturally not organised in a line fashion. The problem is even more complicated since colours have a meaning in the real world. How can we sort colours so that they look as continuous as possible? Which parameters affects the sorting order? Is azure closer to blue (similar hue) or to cyan (similar luminosity)? I can stop you all here and say that there is no solution to this problem. You can sort colours, but the overall result depends on what you are trying to achieve. This post will explore how colours can be sorted, and how this can lead to very different results.

Continue reading

How to DeepDream on Twitter: @DeepDreamThis

This post will guide you to create your own deepdream on Twitter: and yes, it’s as easy as tweeting a picture to @DeepDreamThis. Deep dreams have flooded the Internet. I mean, literally flooded the Internet. Behind this bizarre filter lies one of the most advanced neural network developed by Google Research. There are several services online dedicated to the creation of deep dreams, but most of them have unreasonable waiting times (hours or days) and lack customisation options.

TL;DR:

The fastest way to generate your deep dreams on Twitter is simply twitting a picture to @DeepDreamThis: in a matter of seconds or minutes it’ll reply to you!

Continue reading

How to retrieve all the images from a website

Few weeks ago I posted on Twitter few rather bizarre screenshots. A composition of all the submissions for #ScreenshotSaturday, loosely ordered by colour. In this series of posts I’ll briefly explain how I did that using Python.

You can download the original pictures (16Mb, 71Mb, 40Mb, 13Mb) here.

Continue reading