File size: 2,087 Bytes
d19858a
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
"""
Visualization state and configuration.

Contains:
- VisualizationState: Enum for tracking visualization state
- VisualizationConfig: Configuration dataclass for visualization options
"""

from dataclasses import dataclass
from enum import Enum


class VisualizationState(Enum):
    """
    πŸ“š CONCEPT: Finite State Machine
    
    A visualization can only be in ONE of these states at a time.
    This prevents impossible states like "playing AND paused".
    
    BEFORE OOP (with strings):
        state = "idle"
        if state == "plying":  # Typo! Hard to catch bug
            ...
    
    AFTER OOP (with Enum):
        state = VisualizationState.IDLE
        if state == VisualizationState.PLYING:  # Python error! Typo caught
            ...
    """
    IDLE = "idle"              # No steps loaded
    READY = "ready"            # Steps loaded, ready to start
    PLAYING = "playing"        # Auto-playing animation
    PAUSED = "paused"          # Paused mid-animation
    STEPPING = "stepping"      # Manual step-by-step mode
    COMPLETE = "complete"      # Reached the end


@dataclass
class VisualizationConfig:
    """
    Configuration options for the visualizer.
    
    πŸ“š CONCEPT: Configuration Object
    
    Instead of passing many parameters to functions, we bundle
    related settings into a configuration object.
    
    BEFORE:
        def start_visualization(speed, auto_play, loop, show_stats, ...):
    
    AFTER:
        def start_visualization(config: VisualizationConfig):
    
    Benefits:
    - Easy to add new options without changing function signatures
    - Can have sensible defaults
    - Can save/load configurations
    """
    animation_speed_ms: int = 1000      # Milliseconds per step
    auto_play: bool = False              # Start playing immediately
    loop: bool = False                   # Restart when finished
    show_statistics: bool = True         # Show step count, comparisons, etc.
    show_legend: bool = True             # Show color legend
    image_size: int = 60                 # Size of image thumbnails