Skip to main content

Posts

All the symmetrical watch faces (and code to generate them)

If you ever look at pictures of clocks and watches in advertising they are set to roughly 10:10 which is meant to be the most attractive (smiling!) position for the hands . They are actually set to 10:09.14 if the hands are truly symmetrical. CC BY 2.0 image by Shinji I wanted to know what all the possible symmetrical watch faces are and so I wrote some code using Processing. Here's the output (there's one watch face missing, 00:00 or 12:00, because it's very boring): The key to writing this is to figure out the relationship between the hour and minute hands when the watch face is symmetrical. In an hour the minute hand moves through 360° and the hour hand moves through 30° (12 hours are shown on the watch face and 360/12 = 30). The core loop inside the program is this:   for (int h = 0; h <= 12; h++) {     float m = (360-30*float(h))*2/13;     int s = round(60*(m-floor(m)));     int col = h%6;     int row = floor(h/6);     draw_clock((r+f)*(2*col+1), (r+f)*(row*2+1),
Recent posts

The difference between parentheses and curly braces in GNU Make

One of the problems/perks of having written a book about GNU Make is that people ping me with questions. This morning someone said to me: " Especially curly braces vs parentheses is something that always confuses me ". As always the first port of call with GNU Make questions should be the FSF's manual . It says the following: " To substitute a variable’s value, write a dollar sign followed by the name of the variable in parentheses or braces: either $(foo)  or ${foo}  is a valid reference to the variable foo . " And that seems to work well: $ cat Makefile foo := hello.world $(info $(foo)) $(info ${foo}) $(info $(foo:world=everyone)) $(info ${foo:world=everyone}) $(info $(foo:hello.%=good morning.%)) $(info ${foo:hello.%=good morning.%}) $ make hello.world hello.world hello.everyone hello.everyone good morning.world good morning.world make: *** No targets.  Stop. You can see that simple variable references work, as do substitutions (where I changed world to ever

The search for the "perfect" Advent Calendar (involves Python and Processing)

I grew up with Advent Calendars , and they are very common in the UK. Shops across the country sell calendars with typically 24 doors on them, one for each day from December 1 to December 24. Behind each door is a small gift (usually chocolate or something similarly sweet and edible). The numbers on the doors of the calendar are usually arranged somewhat haphazardly. Part of the fun each day is finding the next door to open. It's the search for the chocolate that makes the calendars enjoyable. Here's an example layout from an Advent Calendar that I bought in Paul in London: This is an example of a very common 6x4 (and sometimes 4x6) layout for calendars. In this blog I'm going to develop code to find "pleasing" Advent Calendar layouts in the 6x4 shape. But first, here's a little animation of the Paul calendar in action. What makes it "pleasing" is that the numbers don't cluster together (mostly).   So, that calendar isn't

Turning a cheap 'police light' into an IoT device

If you've read my blog in the past you'll know I like to make ambient devices: mixtures of electronics and physical objects that blend into a home and provide a useful service. I have, for example, a model bus that shows the live times of buses near my home, and a Totoro that shows the weather forecast , and an old candle mug turned into a breathing nightlight using sea glass gathered on a beach. The Totoro uses an ESP8266 in the form of a NodeMCU for a useful combination of WiFi connectivity, HTTP and GPIO for controlling physical devices like the LEDs in its eyes. One of the challenges with working with these devices is updating the software on the NodeMCU when new functionality is implemented. Every code change has to be uploaded via a USB cable. For a new project I decided to make use of Cloudflare's Workers product to provide a simple API that tells an ambient device what to do. By creating an API that just controls the physical aspects of the device (in thi

More deep dives into source code in TV and film

After my initial videos were somewhat popular, I've made a few more exploring Westworld (new and old), Knight Rider and more .

A publishing experiment about source code in cinema and TV

I was persuaded by buddy Mr H to make a YouTube channel out of my Source Code in TV and Film Tumblr. The Tumblr shows the source code that flashes by on computer screens in films and TV programmes and look at its heritage. This is sometimes surprising, funny, or relevant, and often ridiculous. For the first experimental episode I looked at what I believe is an Easter Egg in the original Iron Man film: I would be interested to hear people's thoughts on this format. The second episode is a forensic examination of the opening sequence of the Doctor Who episode The Bells of Saint John :

A Totoro to forecast the weather

Regular readers may know that I like ambient  devices: devices that fit into the environment unobtrusively and provide information at a glance. One such device is my bus monitor that shows times of buses at the stop near my house. Recently I decided to solve the problem of answering the question "Do I need an umbrella?" when I leave the house. For this I chose to use an ESP8266 in the form of a NodeMCU running Lua and display the coming weather by illuminating the eyes on a small Totoro figure. This was my first NodeMCU/ESP8266 project and there's definitely a bit of a learning curve. I ended up using luatool to upload my Lua code to the device, and esptool to flash the firmware using a custom firmware build from this wonderful website  with the following modules present:  cjson , file , gpio , http , net , node , tmr , uart , wifi , and ws2812 . ./esptool.py --port /dev/cu.SLAB_USBtoUART write_flash -fm qio 0x00000 nodemcu-master-10-modules-2017-04-08-