Skip to content

Commit

Permalink
compute colors only once
Browse files Browse the repository at this point in the history
  • Loading branch information
vpoulailleau committed Jan 15, 2024
1 parent 295d0af commit 8fa626c
Show file tree
Hide file tree
Showing 2 changed files with 8 additions and 9 deletions.
6 changes: 6 additions & 0 deletions space_collector/viewer/constants.py
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
import colorsys

SCREEN_HEIGHT = 1000
SCREEN_WIDTH = 1777
SCREEN_TITLE = "Space collector"
Expand All @@ -9,6 +11,10 @@
2: 65,
3: 130,
}
TEAM_COLORS = {
team: tuple(int(c * 255) for c in colorsys.hsv_to_rgb(hue / 360, 1, 1))
for team, hue in TEAM_HUES.items()
}

MAP_MARGIN = 100
MAP_MIN_X = SCORE_WIDTH + MAP_MARGIN
Expand Down
11 changes: 2 additions & 9 deletions space_collector/viewer/planet.py
Original file line number Diff line number Diff line change
@@ -1,11 +1,10 @@
import logging
import random
import colorsys

import arcade

from space_collector.viewer.animation import AnimatedValue, Animation
from space_collector.viewer.constants import TEAM_HUES
from space_collector.viewer.constants import TEAM_HUES, TEAM_COLORS
from space_collector.viewer.utils import (
hue_changed_texture,
map_coord_to_window_coord,
Expand Down Expand Up @@ -37,17 +36,11 @@ def animate(self) -> None:

def draw(self) -> None:
self.animate()
color_rgb = colorsys.hsv_to_rgb(TEAM_HUES[self.team] / 360, 1, 1)
arcade.draw_circle_outline(
self.sprite.position[0],
self.sprite.position[1],
self.size.value // 2 + 2,
(
int(color_rgb[0] * 255),
int(color_rgb[1] * 255),
int(color_rgb[2] * 255),
150,
),
(*TEAM_COLORS[self.team], 150),
4,
)
self.sprite.draw()
Expand Down

0 comments on commit 8fa626c

Please sign in to comment.