Scene
FluxRender.core.Scene
Scene(name: str, coords: CoordinateSystem, background_color: Sequence[float] = (0.101, 0.105, 0.149), trail_fade_factor: float = 0.95)
Manages the main rendering loop, graphics layers, and object physics.
This class implements a rendering pipeline based on two distinct layers: a trail layer for fading effects and a final layer for crisp overlays. It handles alpha composition, physics updates, and the Taichi GUI window.
Advanced Usage: Custom Frame Hook
While FluxRender is designed to handle UI and rendering autonomously without requiring manual loop management, advanced users can inject custom logic to be executed every frame.
If a global or passed function named update() is defined, the Scene will
detect it and call it exactly once per frame, just before the rendering phase.
This is ideal for custom animations, complex state machines, or physical simulations.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
name
|
str
|
Title of the window. |
required |
coords
|
CoordinateSystem
|
Coordinate system |
required |
background_color
|
Sequence[float]
|
Background color in RGB format (0.0 - 1.0). Defaults to dark navy. |
(0.101, 0.105, 0.149)
|
trail_fade_factor
|
float
|
Decay factor for the trail layer (0.0 - 1.0). A value of 0.95 means the trails will fade by 5% each frame. Defaults to 0.95. |
0.95
|
Example
Basic initialization:
import FluxRender as fr
coords = fr.CoordinateSystem((-10, 10), (-10, 10), 1200, 800, keep_aspect_ratio=True)
scene = fr.Scene(
"My Simulation",
coords,
background_color=(0.208, 0.122, 0.361), # Dark purple background color in RGB format (0.0 - 1.0).
trail_fade_factor=0.98 # Trails will fade by 2% each frame, creating a longer-lasting trail effect.
)
# [Define objects and add them to the scene here]
scene.run()
Source code in FluxRender/core.py
add
Adds a renderable object to the scene.
The object must implement the render(scene) and update(scene) methods.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
*args
|
One or more objects to be added to the scene. Each object must have render(scene) and update(scene) methods. Optionally, they can have coords and scene attributes, which will be set to the current scene's coordinate system and the scene itself if not already set. |
()
|
Notes
- Order of rendering: Objects are rendered in the order they are added. The first object added will be rendered first (at the bottom layer), and the last object will be rendered last (on top). For example, if you added an Axis first and then a VectorField, the vector field will partially cover the coordinate axes.
Source code in FluxRender/core.py
run
Starts the main application loop.
Performs the following actions on each frame: - Updates the physics and renders all objects. - Combines the layers into a single image and displays it. - Calls the update() function on each frame if the user has declared it. - Handles mouse and keyboard clicks. - Gets the mouse cursor position.
Source code in FluxRender/core.py
464 465 466 467 468 469 470 471 472 473 474 475 476 477 478 479 480 481 482 483 484 485 486 487 488 489 490 491 492 493 494 495 496 497 498 499 500 501 502 503 504 505 506 507 508 509 510 511 512 513 514 515 516 517 518 519 520 521 522 523 524 525 526 527 528 529 530 531 532 533 534 535 536 537 538 539 540 541 | |