From e38bf28abbf013d23508592e99671a209d22be65 Mon Sep 17 00:00:00 2001 From: Mylloon Date: Mon, 3 Apr 2023 02:36:54 +0200 Subject: [PATCH] add better string representation of color objects --- utils.py | 13 +++++++++++++ 1 file changed, 13 insertions(+) diff --git a/utils.py b/utils.py index 544ab2b..54f3e38 100644 --- a/utils.py +++ b/utils.py @@ -129,6 +129,9 @@ class Color3i: self.g = g self.b = b + def __str__(self): + return f"{self.__class__.__name__}({self.r}, {self.g}, {self.b})" + class Color4f: """Color RGBA as float""" @@ -138,3 +141,13 @@ class Color4f: self.g = g self.b = b self.a = a + + def __str__(self): + max_precision = 3 + + r = round(self.r, max_precision) + g = round(self.g, max_precision) + b = round(self.b, max_precision) + a = round(self.a, max_precision) + + return f"{self.__class__.__name__}({r}, {g}, {b}, {a})"