generate-alt-random: 50% chance of overwriting the last sixel

This commit is contained in:
Daniel Eklöf 2021-03-09 11:36:26 +01:00
parent 4a86cd7475
commit a3f2e2220a
No known key found for this signature in database
GPG key ID: 5BBD4992C116573F

View file

@ -165,9 +165,21 @@ def main():
# The sixel 'alphabet'
sixels = '?@ABCDEFGHIJKLMNOPQRSTUVWXYZ[\\]^_`abcdefghijklmnopqrstuvwxyz{|}~'
last_pos = None
last_size = None
for _ in range(100):
# Offset image
out.write(' ' * (random.randrange(cols // 2)))
if last_pos is not None and random.randrange(2):
# Overwrite last sixel. I.e. use same position and
# size as last sixel
pass
else:
# Random origin in upper left quadrant
last_pos = random.randrange(lines // 2) + 1, random.randrange(cols // 2) + 1
last_size = random.randrange(height // 2), random.randrange(width // 2)
out.write(f'\033[{last_pos[0]};{last_pos[1]}H')
six_height, six_width = last_size
# Begin sixel
out.write('\033Pq')
@ -179,10 +191,6 @@ def main():
# (except 'hue' which is 0..360)
out.write(f'#{idx};2;{random.randrange(101)};{random.randrange(101)};{random.randrange(101)}')
# Randomize image width/height
six_height = random.randrange(height // 2)
six_width = random.randrange(width // 2)
# Sixel size. Without this, sixels will be
# auto-resized on cell-boundaries.
out.write(f'"1;1;{six_width};{six_height}')