Scene
Module: terminaltexteffects.engine.animation
A Scene is a collection of Frames that can be played in sequence. Scenes can be looped and synced to movement.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
scene_id |
str
|
the ID of the Scene |
required |
is_looping |
bool
|
Whether the Scene should loop. Defaults to False. |
False
|
sync |
SyncMetric | None
|
The type of sync to use for the Scene. Defaults to None. |
None
|
ease |
EasingFunction | None
|
The easing function to use for the Scene. Defaults to None. |
None
|
no_color |
bool
|
Whether to ignore colors. Defaults to False. |
False
|
use_xterm_colors |
bool
|
Whether to convert all colors to XTerm-256 colors. Defaults to False. |
False
|
Methods:
Name | Description |
---|---|
add_frame |
Adds a Frame to the Scene. |
activate |
Activates the Scene. |
get_next_visual |
Gets the next CharacterVisual in the Scene. |
apply_gradient_to_symbols |
Applies a gradient effect to a sequence of symbols. |
reset_scene |
Resets the Scene. |
Attributes:
Name | Type | Description |
---|---|---|
scene_id |
str
|
the ID of the Scene |
is_looping |
bool
|
Whether the Scene should loop |
sync |
SyncMetric | None
|
The type of sync to use for the Scene |
ease |
EasingFunction | None
|
The easing function to use for the Scene |
no_color |
bool
|
Whether to ignore colors |
use_xterm_colors |
bool
|
Whether to convert all colors to XTerm-256 colors |
frames |
list[Frame]
|
The list of Frames in the Scene |
played_frames |
list[Frame]
|
The list of Frames that have been played |
frame_index_map |
dict[int, Frame]
|
A mapping of frame index to Frame |
easing_total_steps |
int
|
The total number of steps in the easing function |
easing_current_step |
int
|
The current step in the easing function |
Source code in terminaltexteffects/engine/animation.py
116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 286 287 288 289 290 291 292 293 294 295 296 297 298 299 300 301 302 303 304 305 306 307 308 309 310 311 312 313 314 315 316 317 318 319 320 321 322 323 324 325 326 327 328 329 330 331 332 333 |
|
__init__(scene_id, is_looping=False, sync=None, ease=None, no_color=False, use_xterm_colors=False)
Initializes a Scene.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
scene_id |
str
|
the ID of the Scene |
required |
is_looping |
bool
|
Whether the Scene should loop. Defaults to False. |
False
|
sync |
SyncMetric | None
|
The type of sync to use for the Scene. Defaults to None. |
None
|
ease |
EasingFunction | None
|
The easing function to use for the Scene. Defaults to None. |
None
|
no_color |
bool
|
Whether to colors should be ignored. Defaults to False. |
False
|
use_xterm_colors |
bool
|
Whether to convert all colors to XTerm-256 colors. Defaults to False. |
False
|
Source code in terminaltexteffects/engine/animation.py
activate()
Activates the Scene by returning the first frame CharacterVisual. Called by the Animation object when the Scene is activated.
Raises:
Type | Description |
---|---|
ValueError
|
if the Scene has no frames |
Returns:
Name | Type | Description |
---|---|---|
CharacterVisual |
CharacterVisual
|
the next CharacterVisual in the Scene |
Source code in terminaltexteffects/engine/animation.py
add_frame(symbol, duration, *, color=None, bold=False, dim=False, italic=False, underline=False, blink=False, reverse=False, hidden=False, strike=False)
Adds a Frame to the Scene with the given symbol, duration, color, and graphical modes.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
symbol |
str
|
the symbol to show |
required |
duration |
int
|
the number of frames to use the Frame |
required |
color |
Color
|
the color to show. Defaults to None. |
None
|
bold |
bool
|
bold mode. Defaults to False. |
False
|
dim |
bool
|
dim mode. Defaults to False. |
False
|
italic |
bool
|
italic mode. Defaults to False. |
False
|
underline |
bool
|
underline mode. Defaults to False. |
False
|
blink |
bool
|
blink mode. Defaults to False. |
False
|
reverse |
bool
|
reverse mode. Defaults to False. |
False
|
hidden |
bool
|
hidden mode. Defaults to False. |
False
|
strike |
bool
|
strike mode. Defaults to False. |
False
|
Source code in terminaltexteffects/engine/animation.py
apply_gradient_to_symbols(gradient, symbols, duration)
Applies a gradient effect to a sequence of symbols and adds each symbol as a frame to the Scene.
This method works by iterating over the symbols and calculating a progress ratio for each symbol. This ratio is calculated by dividing the index of the current symbol (plus one) by the total number of symbols. The gradient index is then calculated by multiplying the symbol progress by the length of the gradient's spectrum. This index is used to select a color from the gradient's spectrum.
The method then iterates over the colors in the gradient's spectrum from the last index to the gradient index (or 1 if gradient index is 0). For each color, it calls the add_frame method, passing the symbol, duration, and color. This adds a frame to the Scene with the symbol displayed in the color from the gradient.
Finally, the last index is updated to the current gradient index, and the process repeats for the next symbol. This results in each symbol being displayed in a sequence of colors from the gradient, creating a gradient effect across the symbols.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
gradient |
Gradient
|
The gradient to apply. |
required |
symbols |
list[str]
|
The list of symbols to apply the gradient to. |
required |
duration |
int
|
The duration to show each frame. |
required |
Returns:
Type | Description |
---|---|
None
|
None |
Source code in terminaltexteffects/engine/animation.py
get_next_visual()
This method is used to get the next CharacterVisual in the Scene. It first retrieves the current frame from the frames list. It then increments the ticks_elapsed attribute of the Frame. If the ticks_elapsed equals the duration of the current frame, it resets ticks_elapsed to 0 and moves the current frame from the frames list to the played_frames list. If the Scene is set to loop and all frames have been played, it refills the frames list with the frames from played_frames and clears played_frames. Finally, it returns the CharacterVisual of the current frame.
Returns:
Name | Type | Description |
---|---|---|
CharacterVisual |
CharacterVisual
|
The visual of the current frame in the Scene. |
Source code in terminaltexteffects/engine/animation.py
reset_scene()
Resets the Scene.