Let's start with the MoonCat "k" values explained visual:
(Source: MoonCat "k" values explained)
Brooks Boyd (aka Midnight Lightning) writes:
In the original MoonCat visualization code, the second byte of the cat's ID is referred to as its
k
value, and from a technical perspective it controls the pose and pattern of the cat. If you take any cat's second byte (first two characters after the initial0x00
in their ID) and convert it to a binary number (and add zeroes to the left side until you have an 8-digit number), you can then see the composition of the different factors that make up the cat's pose, fur pattern, and facial expression.
Let's break apart the 0x00571281e7
cat id example
from the visual:
id = '0x00571281e7'
snd = id[4,2] # take 2 chars (starting at position 4)
#=> "57"
Note: "57" is a hex string (use snd.hex
to convert to number).
Let's print out the 0s and 1s, that is, the 8-digit binary number:
bits = '%08b' % snd.hex
#=> "01010111"
And let's break apart the different factors that make up the cat's pose, fur pattern, and facial expression bit-by-bit:
invert = bits[0,1] # take 1 char (starting at position 0)
#=> "0"
facing = bits[1,1] # take 1 char (starting at position 1)
#=> "1"
face = bits[2,2] # take 2 chars (starting at position 2)
#=> "01
fur = bits[4,2] # take 2 chars (starting at position 4)
#=> "01"
pose = bits[6,2] # take 2 chars (starting at position 6)
#=> "11"
Looking up the mapping from the visual by "hand" you will get:
- Inverted Colors? - 0: No
- Facing - 1: Right
- Face - 01: Frown (Look Down)
- Fur - 01: Striped
- Pose - 11: Stalking
Let's try again - re(using) the mooncats library - to automate the lookup using the pre-defined assigned names from the visual:
require 'mooncats'
meta = Mooncats::Metadata.new( '0x00571281e7' )
meta.invert? #=> false
meta.facing #=> "Right"
meta.face #=> "Frown (Look Down)"
meta.fur #=> "Striped"
meta.pose #=> "Stalking"
Yes, the facing (2), face (4), fur (4), and pose (4) attributes
make up all the possible 128 designs, that is, 2 x 4 x 4 x 4 = 128
.
"Remove" the first bit, that is, the Inverted Colors? bit and you will get the design (0 to 127):
snd = "57"
snd.hex % 128
#=> 87
Voila! Design Right·Frown (Look Down)·Striped·Stalking is #87.
Or re(using) the mooncats library machinery:
meta.design.to_i
#=> 87
Let's double check:
design = Mooncats::Metadata::Design.new( 87 )
design.facing #=> "Right"
design.face #=> "Frown (Look Down)"
design.fur #=> "Striped"
design.pose #=> "Stalking"