Lord Greyscale
Posting a pretty picture of some greyscale in which the fractal nature of it is clearly visible. Black rectangles represent zeros and white rectangles represent ones.
Read it as an array of columns going from left to right. In each column exactly one bit changes relative to the previous, making it an ideal scheme for a head to determine its position.
An $n$-bit greyscale sequence has $2^n$ members, and the last member always differs from the first in just 1 bit position. This makes greyscale ideal for determining position around a cylinder.
Here's the code:
#!/usr/bin/env python3 def __greyscale_fwd(nbits, preset_bits): if nbits == 1: yield 0 + preset_bits yield 1 + preset_bits else: for x in __greyscale_fwd(nbits-1, preset_bits): yield x for x in __greyscale_rev(nbits-1, preset_bits | (1 << (nbits-1))): yield x def __greyscale_rev(nbits, preset_bits): if nbits == 1: yield 1 + preset_bits yield 0 + preset_bits else: for x in __greyscale_fwd(nbits-1, preset_bits | (1 << (nbits-1))): yield x for x in __greyscale_rev(nbits-1, preset_bits): yield x def greyscale(nbits): return __greyscale_fwd(nbits, 0) if __name__ == '__main__': for x in greyscale(32): print('{0:032b}'.format(x))
(NB: I modified the __main__ routine slightly to get the picture above)
Comments
Post a Comment