diff options
author | Daniel Baumann <daniel.baumann@progress-linux.org> | 2024-04-27 16:29:01 +0000 |
---|---|---|
committer | Daniel Baumann <daniel.baumann@progress-linux.org> | 2024-04-27 16:29:01 +0000 |
commit | 35a96bde514a8897f6f0fcc41c5833bf63df2e2a (patch) | |
tree | 657d15a03cc46bd099fc2c6546a7a4ad43815d9f /share/extensions/text_randomcase.py | |
parent | Initial commit. (diff) | |
download | inkscape-upstream.tar.xz inkscape-upstream.zip |
Adding upstream version 1.0.2.upstream/1.0.2upstream
Signed-off-by: Daniel Baumann <daniel.baumann@progress-linux.org>
Diffstat (limited to 'share/extensions/text_randomcase.py')
-rwxr-xr-x | share/extensions/text_randomcase.py | 29 |
1 files changed, 29 insertions, 0 deletions
diff --git a/share/extensions/text_randomcase.py b/share/extensions/text_randomcase.py new file mode 100755 index 0000000..208cade --- /dev/null +++ b/share/extensions/text_randomcase.py @@ -0,0 +1,29 @@ +#!/usr/bin/env python +"""Randomise the case of the letters.""" + +import random +import inkex + +class RandomCase(inkex.TextExtension): + """Randomise the case of the text (with bias)""" + previous_case = 1 + + def map_char(self, char): + # bias the randomness towards inversion of the previous case: + # We use this weird way to get from a random set because + # python2 and python3 have different ways of seeding + if self.previous_case > 0: + case = [-2, -1, 1][int(random.random() * 3)] + else: + case = [-1, 1, 2][int(random.random() * 3)] + + if char.isalpha(): + self.previous_case = case + if case > 0: + return char.upper() + elif case < 0: + return char.lower() + return char + +if __name__ == '__main__': + RandomCase().run() |