Region
FluxRender.regions
CircularRegion
CircularRegion(center: Sequence[float], radius: float, world_fixed: bool = False, visible: bool = False, color_active: Sequence[float] = (1, 1, 1, 0.3), color_inactive: Sequence[float] = (0, 0.1, 0.2, 0.3))
Bases: SpatialRegion
A static, circular spatial boundary used for spatial queries and interactions.
The CircularRegion defines a precise area within the simulation. It is primarily utilized as a localized spawning zone for ParticleSystems (acting as an emitter) or as a targeted sampling area for DataProbes.
Its most powerful feature is its dual-coordinate nature: it can either be rigidly anchored to the UI screen space (pixels) or embedded directly into the mathematical world space, scaling and panning seamlessly with the camera.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
center
|
Sequence[float]
|
The (x, y) coordinates of the region's center.
Units depend strictly on the |
required |
radius
|
float
|
The radius of the circle. Units depend strictly on the |
required |
world_fixed
|
bool
|
The coordinate system toggle.
|
False
|
visible
|
bool
|
Whether to render region on screen (useful for debugging). |
False
|
color_active
|
Sequence[float]
|
RGBA color sequence when Region.active is True. |
(1, 1, 1, 0.3)
|
color_inactive
|
Sequence[float]
|
RGBA color sequence when Region.active is False. |
(0, 0.1, 0.2, 0.3)
|
Notes
- units: The
world_fixedflag is crucial for determining how thecenterandradiusparameters are interpreted. Whenworld_fixedis False, they are in screen pixels; when True, they are in world units. - rendering: If
visibleis set to True, it is essential to add the CircularRegion instance to the scene usingscene.add(your_region)for it to be rendered. However, even ifvisibleis False, the CircularRegion can still function as an emitter or probe target without being added to the scene.
Example
Creating a screen-fixed UI Particle emitter:
import FluxRender as fr
# [Initialize scene and math engine here]
# A fixed 50px radius circle in the bottom-left corner of the screen UI
ui_emitter = fr.CircularRegion(center=(100.0, 100.0), radius=50.0, world_fixed=False)
particle_system = fr.ParticleSystem(
vec_function = lambda x, y: (0.0, 1.0), # Example vector function that emits particles upwards
emitter=ui_emitter
)
scene.add(particle_system) # You don't need to add the CircularRegion itself to the scene for it to function as an emitter, but you do need to add it if you want it to be visible.
Creating a visible, world-fixed Particle emitter:
import FluxRender as fr
# [Initialize scene and math engine here]
# A visible circular region centered at (1, 1) with a radius of 0.25 world unit
world_emitter = fr.CircularRegion(center=(1.0, 1.0), radius=0.25, world_fixed=True, visible=True)
particle_system = fr.ParticleSystem(
vec_function = lambda x, y: (y, -x), # Example vector function that emits particles in a circular pattern
emitter=world_emitter
)
scene.add(particle_system, world_emitter) # We want the CircularRegion to be visible, so we need to add it to the scene.
Source code in FluxRender/regions.py
contains
Checks whether a given spatial point falls within the circular region.
The point should be in the same coordinate space as the region (screen or world) based on the world_fixed flag.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
point
|
tuple
|
A tuple representing the (x, y) coordinates of the point to check. The coordinate space of the point must match the region's coordinate space as determined by the |
required |
Returns:
| Name | Type | Description |
|---|---|---|
contains |
bool
|
True if the point is within the circular region, False otherwise. |
Source code in FluxRender/regions.py
get_center
Returns the current center coordinates of the circular region in math coordinates, regardless of the world_fixed setting.
Returns:
| Name | Type | Description |
|---|---|---|
center |
Tuple[float, float]
|
The (x, y) coordinates of the region's center in math coordinates. |
Source code in FluxRender/regions.py
random_point_screen
Generates a single random point uniformly distributed within the circular region.
The generated point is returned in screen coordinates, regardless of the region's world_fixed setting.
Returns:
| Name | Type | Description |
|---|---|---|
point |
Tuple[float, float]
|
The (x, y) coordinates of the generated point in screen coordinates. |
Source code in FluxRender/regions.py
random_points_screen
Generates a specified number of random points uniformly distributed within the circular region.
The generated points are returned in screen coordinates, regardless of the region's world_fixed setting.
Args:
count (int): The number of random points to generate.
Returns:
| Name | Type | Description |
|---|---|---|
points |
Tuple of two numpy arrays
|
(x_coordinates, y_coordinates) of the generated points in screen coordinates. |
Source code in FluxRender/regions.py
CursorRegion
CursorRegion(radius: float = 50.0, visible: bool = False, color_active=(1, 1, 1, 0.3), color_inactive=(0, 0.1, 0.2, 0.3), always_active: bool = False)
Bases: SpatialRegion
A dynamic spatial region permanently attached to the user's mouse cursor.
The CursorRegion serves as the primary interactive bridge between the user and the mathematical simulation. By translating raw screen-space mouse coordinates into actionable world-space queries in real-time, it allows users to directly "paint" particles onto the screen (as an emitter) or dynamically sample local vector properties simply by hovering over them (as a DataProbe carrier).
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
radius
|
float
|
The interaction radius around the cursor, defined in screen pixels. |
50.0
|
visible
|
bool
|
Whether to render a visual halo around the mouse cursor. |
False
|
color_active
|
Sequence[float]
|
RGBA color of the halo when the region is actively triggered (e.g., mouse button held down). |
(1, 1, 1, 0.3)
|
color_inactive
|
Sequence[float]
|
RGBA color of the halo when the cursor is merely hovering. |
(0, 0.1, 0.2, 0.3)
|
always_active
|
bool
|
Behavioral toggle.
|
False
|
Notes
- Scene Addition Required: Unlike CircularRegion, a CursorRegion instance always needs to be added to the scene using
scene.add(your_region).
Example
Setting up an interactive, visible cursor emitter:
import FluxRender as fr
# [Initialize scene and coordinate system here]
# Creates a 30px visible halo around the mouse. Particles will only spawn when the user clicks and drags the mouse across the field.
interactive_cursor = fr.CursorRegion(
radius=30.0,
visible=True,
)
particle_system = fr.ParticleSystem(
vec_function = lambda x, y: (y, -x), # Example vector function that emits particles in a circular pattern
emitter=interactive_cursor
)
scene.add(particle_system, interactive_cursor)
Setting up a constantly active cursor probe:
import FluxRender as fr
# [Initialize scene and coordinate system here]
math_engine = fr.VectorMathEngine(scene, primary_vector_function=lambda x, y: (y, -x))
# A CursorRegion that continuously probes the vector field under the mouse cursor, even without clicks.
probing_cursor = fr.CursorRegion(
radius=20.0,
visible=False,
always_active=True
)
probe = fr.DataProbe(
target_region=probing_cursor,
math_engine=math_engine,
measured_property=fr.Property.VELOCITY
)
probe.add_listener(lambda value: print(f"Current velocity at cursor: {value}", end="\r"))
scene.add(probe, probing_cursor)
Source code in FluxRender/regions.py
contains
Checks whether a given spatial point falls within the cursor region. The point should be in the screen coordinate space (pixels).
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
point
|
tuple
|
A tuple representing the (x, y) coordinates of the point to check in screen space. |
required |
Returns:
| Name | Type | Description |
|---|---|---|
contains |
bool
|
True if the point is within the cursor region, False otherwise. |
Source code in FluxRender/regions.py
get_center
Returns the current center coordinates of the cursor region in math coordinates.
Returns:
| Name | Type | Description |
|---|---|---|
center |
Tuple[float, float]
|
The (x, y) coordinates of the region's center in math coordinates. |
Source code in FluxRender/regions.py
random_point_screen
Generates a single random point uniformly distributed within the cursor region. The generated point is returned in screen coordinates.
Returns:
| Name | Type | Description |
|---|---|---|
point |
Tuple[float, float]
|
The (x, y) coordinates of the generated point in screen coordinates. |
Source code in FluxRender/regions.py
random_points_screen
Generates a specified number of random points uniformly distributed within the cursor region. The generated points are returned in screen coordinates. Args: count (int): The number of random points to generate.
Returns:
| Name | Type | Description |
|---|---|---|
points |
Tuple of two numpy arrays
|
(x_coordinates, y_coordinates) of the generated points in screen coordinates. |