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.
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 |
preexisting_colors |
ColorPair | None
|
The preexisting colors parsed from the input. |
Source code in terminaltexteffects/engine/animation.py
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 334 335 336 337 338 339 340 341 342 343 344 345 346 347 348 349 350 351 352 353 354 355 356 357 358 359 360 361 362 363 364 365 366 367 368 369 370 371 372 373 374 375 376 377 378 379 380 381 382 383 384 385 386 387 388 389 390 391 392 393 394 395 396 397 398 399 400 401 402 403 404 405 406 407 408 409 410 411 412 413 414 415 416 417 418 419 420 421 422 423 424 425 426 427 428 429 430 431 432 433 434 435 436 437 438 439 440 441 442 443 444 445 446 447 448 |
|
SyncMetric
Bases: Enum
Enum for specifying the type of sync to use for a Scene.
Attributes:
Name | Type | Description |
---|---|---|
DISTANCE |
int
|
Sync to a Waypoint based on distance from the Waypoint |
STEP |
int
|
Sync to a Waypoint based on the number of steps taken towards the Waypoint |
Source code in terminaltexteffects/engine/animation.py
__eq__(other)
Check if two Scene objects are equal based on their scene_id.
__hash__()
__init__(scene_id, *, is_looping=False, sync=None, ease=None, no_color=False, use_xterm_colors=False)
Initialize 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()
Activate the Scene by returning the first frame CharacterVisual
.
Called by the Animation
object when the Scene is activated.
Raises:
Type | Description |
---|---|
ActivateEmptySceneError
|
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, *, colors=None, bold=False, dim=False, italic=False, underline=False, blink=False, reverse=False, hidden=False, strike=False)
Add 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 |
colors
|
ColorPair | None
|
the colors to use. 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
|
Raises:
Type | Description |
---|---|
FrameDurationError
|
if the frame duration is less than 1 |
Source code in terminaltexteffects/engine/animation.py
apply_gradient_to_symbols(symbols, duration, *, fg_gradient=None, bg_gradient=None)
Apply a gradient effect to a sequence of symbols and add each symbol as a frame to the Scene.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
symbols
|
Sequence[str]
|
The sequence of symbols to apply the gradient to. |
required |
duration
|
int
|
The duration to show each frame. |
required |
fg_gradient
|
Gradient | None
|
The foreground gradient to apply. Defaults to None. |
None
|
bg_gradient
|
Gradient | None
|
The background gradient to apply. Defaults to None. |
None
|
Returns:
Type | Description |
---|---|
None
|
None |
Raises:
Type | Description |
---|---|
ApplyGradientToSymbolsNoGradientsError
|
if both fg_gradient and bg_gradient are None |
ApplyGradientToSymbolsEmptyGradientsError
|
if both fg_gradient and bg_gradient are empty |
Source code in terminaltexteffects/engine/animation.py
333 334 335 336 337 338 339 340 341 342 343 344 345 346 347 348 349 350 351 352 353 354 355 356 357 358 359 360 361 362 363 364 365 366 367 368 369 370 371 372 373 374 375 376 377 378 379 380 381 382 383 384 385 386 387 388 389 390 391 392 393 394 395 396 397 398 399 400 401 402 403 404 405 406 407 408 409 410 411 412 413 414 415 416 417 418 419 420 421 422 423 424 425 426 427 428 429 |
|
get_next_visual()
Get the next CharacterVisual in the Scene.
Retrieve the current frame from frames
, then increment the ticks_elapsed
attribute of the Frame.
If the ticks_elapsed
equals the duration of the current frame, reset ticks_elapsed
to 0
and move the
current frame from frames
to played_frames
. If the Scene
is set to loop
and
all frames have been played, refill frames
with the frames from played_frames
and clear
played_frames
. Return 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()
Reset the Scene.