From a2ad297301d66a777bd2a0a3d5837f7a81e89e84 Mon Sep 17 00:00:00 2001 From: pushfoo <36696816+pushfoo@users.noreply.github.com> Date: Fri, 2 Dec 2022 15:33:57 -0500 Subject: [PATCH 1/7] Add TRANSPARENT_BLACK color constant --- arcade/color/__init__.py | 1 + 1 file changed, 1 insertion(+) diff --git a/arcade/color/__init__.py b/arcade/color/__init__.py index 0cb6ca296..feb3b74e4 100644 --- a/arcade/color/__init__.py +++ b/arcade/color/__init__.py @@ -923,6 +923,7 @@ TROLLEY_GREY = (128, 128, 128, 255) TROPICAL_RAIN_FOREST = (0, 117, 94, 255) TRUE_BLUE = (0, 115, 207, 255) +TRANSPARENT_BLACK = (0, 0, 0, 0) TUFTS_BLUE = (65, 125, 193, 255) TULIP = (255, 135, 141, 255) TUMBLEWEED = (222, 170, 136, 255) From fb1365c48bb8c138e651195785b7dee421e6e774 Mon Sep 17 00:00:00 2001 From: pushfoo <36696816+pushfoo@users.noreply.github.com> Date: Fri, 2 Dec 2022 15:41:39 -0500 Subject: [PATCH 2/7] Improve clarity by using named constant for default window background --- arcade/application.py | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/arcade/application.py b/arcade/application.py index 061eb7ee9..eb8142d11 100644 --- a/arcade/application.py +++ b/arcade/application.py @@ -17,6 +17,7 @@ from arcade import get_display_size from arcade import set_viewport from arcade import set_window +from arcade.color import TRANSPARENT_BLACK from arcade.context import ArcadeContext from arcade.arcade_types import Color from arcade import SectionManager @@ -176,7 +177,7 @@ def __init__( self._ctx: ArcadeContext = ArcadeContext(self, gc_mode=gc_mode, gl_api=gl_api) set_viewport(0, self.width, 0, self.height) - self._background_color: Color = (0, 0, 0, 0) + self._background_color: Color = TRANSPARENT_BLACK # See if we should center the window if center_window: From 98e06cfd8fe12445c6b29378a062186fec8de612 Mon Sep 17 00:00:00 2001 From: pushfoo <36696816+pushfoo@users.noreply.github.com> Date: Fri, 2 Dec 2022 15:42:40 -0500 Subject: [PATCH 3/7] Improve clarity by using named color constant for clearing in arcade.gui.Surface --- arcade/gui/surface.py | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/arcade/gui/surface.py b/arcade/gui/surface.py index 309494102..2a39f60d7 100644 --- a/arcade/gui/surface.py +++ b/arcade/gui/surface.py @@ -3,6 +3,7 @@ import arcade from arcade import Texture +from arcade.color import TRANSPARENT_BLACK from arcade.gl import Framebuffer from arcade.gl import geometry from arcade.gui.nine_patch import NinePatchTexture @@ -102,7 +103,7 @@ def width(self) -> int: def height(self) -> int: return self._size[1] - def clear(self, color: arcade.Color = (0, 0, 0, 0)): + def clear(self, color: arcade.Color = TRANSPARENT_BLACK): """Clear the surface""" self.fbo.clear(color=color) From 83627dd45994f87e23bd3d3d780154ed269244a6 Mon Sep 17 00:00:00 2001 From: pushfoo <36696816+pushfoo@users.noreply.github.com> Date: Fri, 2 Dec 2022 15:44:02 -0500 Subject: [PATCH 4/7] Improve clarity in arcade.texture.Texture by using named color constant --- arcade/texture.py | 9 +++++---- 1 file changed, 5 insertions(+), 4 deletions(-) diff --git a/arcade/texture.py b/arcade/texture.py index 13a8d23a5..bcc2953db 100644 --- a/arcade/texture.py +++ b/arcade/texture.py @@ -17,6 +17,7 @@ calculate_hit_box_points_simple, calculate_hit_box_points_detailed, ) +from arcade.color import TRANSPARENT_BLACK from arcade.resources import resolve_resource_path from arcade.cache.hit_box import HitBoxCache from arcade.cache.image import WeakImageCache @@ -206,7 +207,7 @@ def create_empty(cls, name: str, size: Tuple[int, int]) -> "Texture": """ return Texture( name, - image=PIL.Image.new("RGBA", size, (0, 0, 0, 0)), + image=PIL.Image.new("RGBA", size, TRANSPARENT_BLACK), hit_box_algorithm=None, ) @@ -707,7 +708,7 @@ def make_circle_texture(diameter: int, color: Color, name: Optional[str] = None) "circle_texture", diameter, color[0], color[1], color[2] ) - bg_color = (0, 0, 0, 0) # fully transparent + bg_color = TRANSPARENT_BLACK # fully transparent img = PIL.Image.new("RGBA", (diameter, diameter), bg_color) draw = PIL.ImageDraw.Draw(img) draw.ellipse((0, 0, diameter - 1, diameter - 1), fill=color) @@ -745,7 +746,7 @@ def make_soft_circle_texture( outer_alpha, ) # name must be unique for caching - bg_color = (0, 0, 0, 0) # fully transparent + bg_color = TRANSPARENT_BLACK img = PIL.Image.new("RGBA", (diameter, diameter), bg_color) draw = PIL.ImageDraw.Draw(img) max_radius = int(diameter // 2) @@ -789,7 +790,7 @@ def make_soft_square_texture( "gradientsquare", size, color, center_alpha, outer_alpha ) - bg_color = (0, 0, 0, 0) # fully transparent + bg_color = TRANSPARENT_BLACK img = PIL.Image.new("RGBA", (size, size), bg_color) draw = PIL.ImageDraw.Draw(img) half_size = int(size // 2) From 0d06c6be07f5e6a3231c3b2237371b2869d5c1a4 Mon Sep 17 00:00:00 2001 From: pushfoo <36696816+pushfoo@users.noreply.github.com> Date: Fri, 2 Dec 2022 15:44:54 -0500 Subject: [PATCH 5/7] Improve clarity in arcade.gui.widgets by using named color constant --- arcade/gui/widgets/__init__.py | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/arcade/gui/widgets/__init__.py b/arcade/gui/widgets/__init__.py index b6e8b2f78..99791caca 100644 --- a/arcade/gui/widgets/__init__.py +++ b/arcade/gui/widgets/__init__.py @@ -16,6 +16,7 @@ import arcade from arcade import Sprite, get_window, Texture +from arcade.color import TRANSPARENT_BLACK from arcade.gui.events import ( UIEvent, UIMouseMovementEvent, @@ -829,7 +830,7 @@ def on_update(self, dt): def do_render(self, surface: Surface): self.prepare_render(surface) - surface.clear(color=(0, 0, 0, 0)) + surface.clear(color=TRANSPARENT_BLACK) surface.draw_sprite(0, 0, self.width, self.height, self._sprite) @@ -887,7 +888,7 @@ def __init__( y=0, width=100, height=100, - color=(0, 0, 0, 0), + color=TRANSPARENT_BLACK, size_hint=None, size_hint_min=None, size_hint_max=None, From 806c03defe8380aca5df88de25f43da8beda9dc2 Mon Sep 17 00:00:00 2001 From: pushfoo <36696816+pushfoo@users.noreply.github.com> Date: Fri, 2 Dec 2022 16:07:45 -0500 Subject: [PATCH 6/7] Use named color constant in bloom defender examples --- arcade/examples/bloom_defender.py | 2 +- arcade/experimental/bloom_multilayer_defender.py | 4 ++-- 2 files changed, 3 insertions(+), 3 deletions(-) diff --git a/arcade/examples/bloom_defender.py b/arcade/examples/bloom_defender.py index 9577ae7e2..c4c2cc04e 100644 --- a/arcade/examples/bloom_defender.py +++ b/arcade/examples/bloom_defender.py @@ -240,7 +240,7 @@ def on_draw(self): # Draw to the 'bloom' layer self.bloom_screen.use() - self.bloom_screen.clear((0, 0, 0, 0)) + self.bloom_screen.clear(arcade.color.TRANSPARENT_BLACK) arcade.set_viewport(self.view_left, SCREEN_WIDTH + self.view_left, diff --git a/arcade/experimental/bloom_multilayer_defender.py b/arcade/experimental/bloom_multilayer_defender.py index e24d8c255..475f311b2 100644 --- a/arcade/experimental/bloom_multilayer_defender.py +++ b/arcade/experimental/bloom_multilayer_defender.py @@ -250,7 +250,7 @@ def on_draw(self): # Draw to the 'slight bloom' layer self.slight_bloom_screen.use() - self.slight_bloom_screen.clear((0, 0, 0, 0)) + self.slight_bloom_screen.clear(arcade.color.TRANSPARENT_BLACK) arcade.set_viewport(self.view_left, SCREEN_WIDTH + self.view_left, @@ -262,7 +262,7 @@ def on_draw(self): # # Draw to the 'intense bloom' layer self.intense_bloom_screen.use() - self.intense_bloom_screen.clear((0, 0, 0, 0)) + self.intense_bloom_screen.clear(arcade.color.TRANSPARENT_BLACK) arcade.set_viewport(self.view_left, SCREEN_WIDTH + self.view_left, From 1f8f68147df7347bf9c742c97a92bcaf5e7f846b Mon Sep 17 00:00:00 2001 From: pushfoo <36696816+pushfoo@users.noreply.github.com> Date: Fri, 2 Dec 2022 16:14:39 -0500 Subject: [PATCH 7/7] Update expected dict size in color constant test --- tests/unit/test_color.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/tests/unit/test_color.py b/tests/unit/test_color.py index 0a3b3960b..27860dc26 100644 --- a/tests/unit/test_color.py +++ b/tests/unit/test_color.py @@ -2,4 +2,4 @@ def test_colors(): from arcade import color names = color.__dict__.keys() - assert 1012 == len(names) + assert 1013 == len(names)