Skip to content

Commit

Permalink
added dark mode to demo and readme
Browse files Browse the repository at this point in the history
  • Loading branch information
papalotis committed Oct 17, 2024
1 parent f1f9745 commit 3a8dd20
Show file tree
Hide file tree
Showing 6 changed files with 62 additions and 15 deletions.
4 changes: 2 additions & 2 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -7,9 +7,9 @@ FaSTTUBe Formula Student Driverless Path Planning Algorithm
| With color information | Without color information |
| ---------------------- | ------------------------- |
| Autocross FSG 2019
| ![An animation demoing the path planning algorithm](media/fsg_color.gif) | ![An animation demoing the path planning algorithm without color](media/fsg_no_color.gif) |
| ![An animation demoing the path planning algorithm](media/fsg_color.gif#gh-light-mode-only) ![An animation demoing the path planning algorithm](media/fsg_color_dark_mode.gif#gh-dark-mode-only) | ![An animation demoing the path planning algorithm without color](media/fsg_no_color.gif#gh-light-mode-only) ![An animation demoing the path planning algorithm without color](media/fsg_no_color_dark_mode.gif#gh-dark-mode-only) |
| Skidpad |
| ![An animation demoing the path planning algorithm](media/skidpad_color.gif) | ![An animation demoing the path planning algorithm without color](media/skidpad_no_color.gif) |
| ![An animation demoing the path planning algorithm](media/skidpad_color.gif#gh-light-mode-only) ![An animation demoing the path planning algorithm](media/skidpad_color_dark_mode.gif#gh-dark-mode-only) | ![An animation demoing the path planning algorithm without color](media/skidpad_no_color.gif#gh-light-mode-only) ![An animation demoing the path planning algorithm without color](media/skidpad_no_color_dark_mode.gif#gh-dark-mode-only) |

> [!NOTE]
> You can find an interactive demo of the algorithm <a href="https://ft-fsd-path-planning.streamlit.app//" target="_blank">here.</a>
Expand Down
73 changes: 60 additions & 13 deletions fsd_path_planning/demo/json_demo.py
Original file line number Diff line number Diff line change
Expand Up @@ -68,6 +68,7 @@ def main(
show_runtime_histogram: bool = False,
output_path: Optional[Path] = typer.Option(None, "--output-path", "-o"),
experimental_performance_improvements: bool = False,
dark_mode: bool = False,
) -> None:
data_path = get_filename(data_path)

Expand Down Expand Up @@ -140,27 +141,70 @@ def main(
plt.hist(timer.intervals[10:])
plt.show()



# Conditionally apply dark mode settings
if dark_mode:
plt.style.use("dark_background")
cone_colors = {
'yellow': 'yo',
"yellow_sorted": "yo-",
'blue': 'bo',
"blue_sorted": "bo-",
'unknown': 'wo', # White for unknown cones in dark mode
'orange_small': 'orange',
'orange_big': 'darkorange',
'path': 'r-',
'position': 'go',
'direction': 'g-',
'title_color': 'white'
}
else:
plt.style.use('default')
cone_colors = {
'yellow': 'yo',
"yellow_sorted": "yo-",
'blue': 'bo',
"blue_sorted": "bo-",
'unknown': 'ko', # Black for unknown cones in light mode
'orange_small': 'orange',
'orange_big': 'darkorange',
'path': 'r-',
'position': 'go',
'direction': 'g-',
'title_color': 'black'
}

fig, ax = plt.subplots(figsize=(10, 10))
ax.set_aspect("equal")
# plot animation
frames = []


for i in tqdm(range(len(results)), desc="Generating animation"):
co = cone_observations[i]
(yellow_cones,) = plt.plot(*co[ConeTypes.YELLOW].T, "yo")
(blue_cones,) = plt.plot(*co[ConeTypes.BLUE].T, "bo")
(unknown_cones,) = plt.plot(*co[ConeTypes.UNKNOWN].T, "ko")
(orange_small_cones,) = plt.plot(*co[ConeTypes.ORANGE_SMALL].T, "o", c="orange")

# Use cone colors based on the mode
(yellow_cones,) = plt.plot(*co[ConeTypes.YELLOW].T, cone_colors['yellow']) # Yellow cones
(blue_cones,) = plt.plot(*co[ConeTypes.BLUE].T, cone_colors['blue']) # Blue cones
(unknown_cones,) = plt.plot(*co[ConeTypes.UNKNOWN].T, cone_colors['unknown']) # Unknown cones
(orange_small_cones,) = plt.plot(*co[ConeTypes.ORANGE_SMALL].T, "o", c=cone_colors['orange_small']) # Small orange cones
(orange_big_cones,) = plt.plot(
*co[ConeTypes.ORANGE_BIG].T, "o", c="darkorange", markersize=10
*co[ConeTypes.ORANGE_BIG].T, "o", c=cone_colors['orange_big'], markersize=10 # Big orange cones
)
(yellow_cones_sorted,) = plt.plot(*results[i][2].T, "y-")
(blue_cones_sorted,) = plt.plot(*results[i][1].T, "b-")
(path,) = plt.plot(*results[i][0][:, 1:3].T, "r-")
(position,) = plt.plot([positions[i][0]], [positions[i][1]], "go")

# Sorted cones and path
(yellow_cones_sorted,) = plt.plot(*results[i][2].T, cone_colors['yellow_sorted'])
(blue_cones_sorted,) = plt.plot(*results[i][1].T, cone_colors['blue_sorted'])
(path,) = plt.plot(*results[i][0][:, 1:3].T, cone_colors['path']) # Path color

# Position and direction
(position,) = plt.plot([positions[i][0]], [positions[i][1]], cone_colors['position']) # Position marker
(direction,) = plt.plot(
*np.array([positions[i], positions[i] + directions[i]]).T, "g-"
*np.array([positions[i], positions[i] + directions[i]]).T, cone_colors['direction'] # Direction line
)

# Title with conditional color
title = plt.text(
0.5,
1.01,
Expand All @@ -169,7 +213,10 @@ def main(
va="bottom",
transform=ax.transAxes,
fontsize="large",
color=cone_colors['title_color'] # Title color based on mode
)

# Collect the frame elements for animation
frames.append(
[
yellow_cones,
Expand All @@ -186,9 +233,9 @@ def main(
]
)

anim = matplotlib.animation.ArtistAnimation(
fig, frames, interval=1 / data_rate * 1000, blit=True, repeat_delay=1000
)
anim = matplotlib.animation.ArtistAnimation(
fig, frames, interval=1 / data_rate * 1000, blit=True, repeat_delay=1000
)

if output_path is not None:
absolute_path_str = str(output_path.absolute())
Expand Down
Binary file added media/fsg_color_dark_mode.gif
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added media/fsg_no_color_dark_mode.gif
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added media/skidpad_color_dark_mode.gif
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added media/skidpad_no_color_dark_mode.gif
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.

0 comments on commit 3a8dd20

Please sign in to comment.