From 099ef4f252c826d65cd8ca720ced3cea87272a0f Mon Sep 17 00:00:00 2001 From: jay817 Date: Fri, 31 Jan 2025 03:06:48 +0000 Subject: [PATCH] Update color/README.md --- color/README.md | 10 ++++++++++ 1 file changed, 10 insertions(+) diff --git a/color/README.md b/color/README.md index ad7810a..b711957 100644 --- a/color/README.md +++ b/color/README.md @@ -2,4 +2,14 @@ for i,x in enumerate('rgybmcRGYBMC'):globals()[x]=lambda s,i=i:f'\x1b[{31+i//6*60+i%6}m{s}\x1b[0m' print(r('hello'), R('hello')) + + +def color(text, code=None): + if code: code = int(__import__('hashlib').sha1(code.encode()).hexdigest(), 16) + else: code = int(__import__('random').random() * 214) + return f'\x1b[38;5;{code % 214 + 17}m{text}\x1b[0m' + +print(color('hello')) +print(color('world')) +print(color('fixed', 'fixed')) ``` \ No newline at end of file