Saturday, 3 October 2015


I got a very kind email from David Schaeffer yesterday with some bug fixes for the shader code I wrote for converting RGB to the HCY colour space.

My original implementation was

  float3 RGBtoHCY(in float3 RGB)
    float3 HCV = RGBtoHCV(RGB);
    float Y = dot(RGB, HCYwts);
    if (HCV.y != 0)
      float Z = dot(HUEtoRGB(HCV.x), HCYwts);
      if (Y > Z)
        Y = 1 - Y;
        Z = 1 - Z;
      HCV.y *= Z / Y;
    return float3(HCV.x, HCV.y, Y);

As he points out:
It seems to me that you have an error in your RGB to HCY code, though.  I was having some pixels always saturate to white, and after looking at Kuzma Shapran's original code I don't think the value of Y should actually be changed, only using the adjusted value of Y to calculate HCV.y.  Additionally I think the check for 0 in the original code was meant to prevent divide by 0 errors, so should be using Y instead of HCV.y.
I'll have to bow to David's superior knowledge on HCY usage as I've never actually used it in anger. So here's his improved version:

  float3 RGBtoHCY(in float3 RGB)
    float3 HCV = RGBtoHCV(RGB);
    float Y = dot(RGB, HCYwts);
    float Z = dot(HUEtoRGB(HCV.x), HCYwts);
    if (Y < Z)
      HCV.y *= Z / (Epsilon + Y);
      HCV.y *= (1 - Z) / (Epsilon + 1 - Y);
    return float3(HCV.x, HCV.y, Y);

I've updated the snippets page accordingly.

Thursday, 1 October 2015

When I was at primary school, they used to run a book club where you could buy books with your pocket money. One of the purchases I made was Denis Gifford's "Monsters of the Movies" for the princely sum of 45p.

The book fascinated me and probably inspired my love of horror films. However, re-reading the book recently there are a few wrinkles I hadn't noticed.

The book was published in 1977 and had 46 entries:

The Alligator People in
The Alligator People (1959)
Certificate X
The Ape Man in
The Ape Man (1942)
Certificate X (now PG)
Barnabas Collins in
House of Dark Shadows (1970)
Certificate X (now 18)
The Beast in
Beauty and the Beast (1946)
Certificate A (now PG)
The Blood Beast Terror in
The Blood Beast Terror (1967)
Certificate X (now 12)
The Bride of Frankenstein in
The Bride of Frankenstein (1935)
Certificate A (now PG)
Carmilla in
The Vampire Lovers (1969)
Certificate X (now 15)
The Cat in
The Cat and the Canary (1939)
Certificate A (now PG)
Count Yorga in
Count Yorga, Vampire (1970)
Certificate X
Countess Dracula in
Countess Dracula (1971)
Certificate X (now 18)
The Creature in
The Creature from the Black Lagoon (1954)
Certificate A (now PG)
The Creeper in
The Brute Man (1946)
Certificate A
The Demon in
The Curse of the Demon (1958)
Certificate X (now PG)
Dr Caligari in
The Cabinet of Dr Caligari (1919)
Certificate A (now U)
Dr Jekyll and Mr Hyde in
Dr Jekyll and Mr Hyde (1931)
Certificate A (now 12A)
Dr Moreau in
The Island of Lost Souls (1932)
Certificate - (now PG)
Dr Phibes in
The Abominable Dr Phibes (1971)
Certificate X (now 15)
Dr X in
Doctor X (1932)
Certificate A
Dracula in
Dracula (1931)
Certificate A (now PG)
The Electric Man in
Man-Made Monster (1941)
Certificate A
The Fly in
The Fly (1958)
Certificate X (now PG)
Frankenstein's Monster in
Frankenstein (1931)
Certificate A (now PG)
Fu Manchu in
The Mask of Fu Manchu (1932)
Certificate A
The Ghoul in
The Ghoul (1933)
Certificate A (now PG)
The Golem in
The Golem (1920)
Certificate - (now PG)
The Gorgon in
The Gorgon (1964)
Certificate X (now 12)
The Hunchback of Notre Dame in
The Hunchback of Notre Dame (1923)
Certificate A (now PG)
The Invisible Man in
The Invisible Man (1933)
Certificate A (now PG)
King Kong in
King Kong (1933)
Certificate A (now PG)
The Mad Monster in
The Mad Monster (1941)
Certificate -
The Manster in
The Split (1962)
Certificate X
The Mummy in
The Mummy's Hand (1941)
Certificate A (now PG)
The Munsters in
Munster, Go Home! (1966)
Certificate U (now U)
Nosferatu in
Nosferatu (1922)
Certificate A (now PG)
Orlac in
The Hands of Orlac (1935)
Certificate A
The Phantom of the Opera in
The Phantom of the Opera (1925)
Certificate U (now PG)
The Raven in
The Raven (1935)
Certificate A (now 15)
The Reptile in
The Reptile (1966)
Certificate X (now 15)
Teenage Werewolf in
I Was a Teenage Werewolf (1957)
Certificate X (now 15)
The Walking Dead in
The Walking Dead (1936)
Certificate A
The Werewolf of London in
Werewolf of London (1934)
Certificate A (now PG)
White Zombie in
White Zombie (1932)
Certificate A (now PG)
The Wild Woman in
The Jungle Captive (1944)
Certificate H
The Wolf Man in
The Wolf Man (1941)
Certificate A (now PG)
Zaroff in
The Most Dangerous Game (1932)
Certificate A (now 12)
The Zombie in
The Plague of the Zombies (1966)
Certificate X (now 12A)

Here are my thoughts:

  • The latest films listed were released in 1971, so perhaps Mr Gifford wrote the book a few years before it was finally published.
  • The fact that's there 46 entries, as opposed to some nice "round" number like 50 is probably due to the limitations of the cheap printing: there are 48 leaves between the soft covers.
  • Some of the films are a bit suspect for a book obviously aimed at children: "The Vampire Lovers" and "The Abominable Dr Phibes" being prime examples.
  • "The Island of Lost Souls" was rejected by the BBFC and only given an X certificate in 1958.
  • "The Golem" was never release in the UK.
  • "The Mad Monster" was initially rejected by the BBFC and only given an X certificate in 1952.
  • "Countess Dracula" is currently listed as a 18 certificate, but this is presumably because it hasn't been re-submitted. It's the equivalent of a PG in the USA.
  • All the zombies listed are "voodoo zombies"; "Night of the Living Dead" (1968) isn't listed.
  • Some of the films aren't even monster films and a few are actually comedies.
  • I've managed to see just over half of the films on the list.
  • The most obscure is surely "The Split" which I'm dying to see.
If I were going to "round up" the list to 50 by adding four more, which monsters would I choose? Funnily enough, they're all 1950s films (which seems to be under-represented in the original list):
  1. "The Thing from Another World" (1951)
  2. "The Beast from 20,000 Fathoms" (1953) not because it's a good film, but because of fond memories staying up late to watch it on TV during the school holidays.
  3. "Godzilla" (1954) - how did this not get on the list?
  4. "The Blob" (1958)
Two films that just missed the cut were "Forbidden Planet" (1956) and "The Day of the Triffids" (1962).

Tuesday, 29 September 2015


Was it George Bernard Shaw who said that England and America are two countries divided by a common language?

Some words have very different meanings on either side of the pond. So while an Englishman puts his trunks in the boot of his car before driving off on holiday, an American would put his boots in the trunk.

Similarly, an Englishman puts his pants on before his shorts.

But my all-time favourite [or should that be favorite?] only really works when spoken aloud:
In England, we pay our bills with a cheque. In America, they pay their checks with a bill.

Sunday, 27 September 2015

Dominoes, Triangles, Squares and Tetris

My maternal grandfather was a coal miner from the North West of England. Unsurprisingly, for a working class man of that era, he played dominoes. Dominoes is often thought of as a children's game; but that's very unfair. Indeed there are championships played throughout the world. By subtle play, an experienced player can discern which tiles are in their opponents' hands. For a double-six deck, this is supposedly easy; for a double-nine deck, it is somewhat more difficult.

Dominoes are a favourite of mathematicians. Consider the number of tiles in a deck. If we arrange the tiles into rows where the value of the greater "side" is zero, one, two, three, four, five and six in turn, we get:

01 11
02 12 22
03 13 23 33
04 14 24 34 44
05 15 25 35 45 55
06 16 26 36 46 56 66

This obviously forms a triangle: the number of tiles in a complete double-n deck is a triangular number:

tiles in a double-n deck, D(n) = T(n+1) = (n + 1) × (n + 2) ÷ 2

For a double-six deck, D(6) = 28. For a double-nine deck, D(9) = 55.

In terms of construction, dominoes are two squares bolted together with a common edge:

There's no real choice about how we join the two squares, but when we go to three squares, there are two arrangements (ignoring rotations):

These are known as trominoes, not to be confused with triominoes.

When we get to four squares, we get the tetrominoes, The one-sided variants (allowing reflection) also being known as the Tetris pieces:

If we take the seven Tetris pieces and add the two trominoes and the single domino, we get ten pieces made up of a total of 36 squares (7×4 + 2×3 + 1×2):

Thirty-six is interesting: it is the first number after one that is both a square and a triangular number. Therefore, we can arrange the ten pieces above into both a square:

And into a triangle:

You can also arrange them into 2-by-18, 3-by-12 and 4-by-9 rectangles: