xnano.types
xnano.types
¶
xnano.types
The types that describe what xnano accepts: positions and sizes as an axis, anything that can
be added to a canvas, space around text, pixel encodings, the settings of a canvas and of the
screen it is opened on, and the functions that hook into events.
Classes:
-
SpacingDictionary–Space around text, edge by edge.
-
EffectController–The effects of the hook that is running, one method for each effect.
-
PlayableEffects–The sound effects of a canvas's audio, one method for each effect.
-
RenderableEffects–The visual effects of a placement or a canvas, one method for each effect.
-
HookHandle–One hook attached to a canvas or a placement.
-
SupportsPlay–Anything that can be played: an object with a
__xnano_play__method. -
SupportsRender–Anything that draws itself: an object with a
__xnano_render__method. -
GateSettings–What a screen reports to a canvas: the input gates of
new()andopen(). -
CanvasAppearanceArguments–How a canvas itself looks: its colors, text modifiers, border, padding and margin.
-
AppearanceArguments–How written content looks: the appearance keywords of
write. -
CanvasSettings–The keyword settings of
new: the input gates and the canvas's own look. -
OpenSettings–The keyword settings of
Canvas.openand of -
PlayOptions–The keyword options of
play. An option replaces the same value on a
Attributes:
-
Spacing(TypeAlias) –Space around text: one value for every edge or a
SpacingDictionary. -
EffectCustomization–Any visual or sound effect, as the customization that
fx(...)returns. -
PlayableEffect–A sound effect as
fx(...)and the methods ofcanvas.audio.fxandcontext.fxreturn it. -
PlayableEffectKind–The kinds of effect that change how a sound plays:
fxkinds that start with'audio.'. -
PlayableEffectSpecification–One sound effect as a dictionary for
effects=[...]: itskindand its keywords. -
RenderableEffect–A visual effect as
fx(...)and the methods ofplacement.fxandcontext.fxreturn it. -
RenderableEffectKind–The kinds of effect that change how a buffer looks:
fxkinds that start with'effect.'. -
RenderableEffectSpecification–One visual effect as a dictionary for
effects=[...]: itskindand its keywords. -
Hook(TypeAlias) –What a canvas or placement calls when an event counts: a function of the
-
HookGenerator(TypeAlias) –A hook that spans several events: it receives the next context at each bare
yield. -
HookKind(TypeAlias) –When a hook runs.
-
When(TypeAlias) –The condition of a hook: an expression, a function of the context, or a string.
-
Anchor(TypeAlias) –The
(x, y)pixel inside anArtthat sits at the art's(x, y). -
Axis(TypeAlias) –One number of a position or size:
x,y,widthorheight. -
CanvasLayout(TypeAlias) –How a canvas places what is written on it.
-
ColorValue(TypeAlias) –A color, an ANSI color name, a
'#rrggbb'string, or a(red, green, blue)tuple. -
Content(TypeAlias) –Anything a canvas can show or play: a
Renderableor aPlayable. -
EdgeBehavior(TypeAlias) –What content does at the edges of its area.
-
HeldMouseButtonName(TypeAlias) –The name of a mouse button in the held-input vocabulary of
Input. -
HorizontalPosition(TypeAlias) –A word that places something inside its parent along
x. -
Interpolation(TypeAlias) –How an effect eases between its start and end:
'linear', or a curve such as -
KeyName(TypeAlias) –The name of a key such as
'q','enter'or'page_up'. -
MotionDirection(TypeAlias) –The direction a sweep, slide or stretch effect moves in.
-
Percentage(TypeAlias) –A share of the space a size or position is measured against, such as
'50%'. -
PixelEncoding(TypeAlias) –'half_blocks': one column and two rows of pixels per cell.'braille': two by four. -
Playable(TypeAlias) –Anything
playandCanvas.playaccept: a -
PlaySource(TypeAlias) –Anything
playandCanvas.playaccept: a -
RangeBound(TypeAlias) –One end of a range as written: cells, a percentage string, an expression, or
None. -
Renderable(TypeAlias) –Anything
Canvas.writeaccepts: text, a -
VerticalPosition(TypeAlias) –A word that places something inside its parent along
y. -
PixelPreset(TypeAlias) –The names of the characters
Pixelknows:Pixel('diamond')draws◆. -
BorderKind(TypeAlias) –The line style of a border.
Spacing
module-attribute
¶
Spacing: TypeAlias = int | float | Percentage | str | SpacingDictionary
Space around text: one value for every edge or a SpacingDictionary.
A whole number is a count of cells. A float (0.1) or a percentage string ('10%') is
a share of the text's width for the left and right edges and of its height for the top and
bottom edges, read when the spacing is applied.
EffectCustomization
module-attribute
¶
EffectCustomization = RenderableEffect | PlayableEffect
Any visual or sound effect, as the customization that fx(...) returns.
This is not Effect, the class whose methods build a visual effect
for update.
PlayableEffect
module-attribute
¶
PlayableEffect = BitCrushAudioCustomization | DistortionAudioCustomization | LowPassAudioCustomization | HighPassAudioCustomization | DelayAudioCustomization | ReverbAudioCustomization | TremoloAudioCustomization
A sound effect as fx(...) and the methods of canvas.audio.fx and context.fx return it.
PlayableEffectKind
module-attribute
¶
PlayableEffectKind = Literal['audio.bit_crush', 'audio.distortion', 'audio.low_pass', 'audio.high_pass', 'audio.delay', 'audio.reverb', 'audio.tremolo']
The kinds of effect that change how a sound plays: fx kinds that start with 'audio.'.
PlayableEffectSpecification
module-attribute
¶
PlayableEffectSpecification = BitCrushAudioSpecification | DistortionAudioSpecification | LowPassAudioSpecification | HighPassAudioSpecification | DelayAudioSpecification | ReverbAudioSpecification | TremoloAudioSpecification
One sound effect as a dictionary for effects=[...]: its kind and its keywords.
RenderableEffect
module-attribute
¶
RenderableEffect = FadeToEffectCustomization | FadeFromEffectCustomization | PaintEffectCustomization | SaturateEffectCustomization | LightenEffectCustomization | DarkenEffectCustomization | SweepInEffectCustomization | SweepOutEffectCustomization | SlideInEffectCustomization | SlideOutEffectCustomization | HslShiftEffectCustomization | DissolveEffectCustomization | CoalesceEffectCustomization | GlitchEffectCustomization | SleepEffectCustomization | EvolveEffectCustomization | EvolveIntoEffectCustomization | EvolveFromEffectCustomization | ExpandEffectCustomization | StretchEffectCustomization | ExplodeEffectCustomization
A visual effect as fx(...) and the methods of placement.fx and context.fx return it.
RenderableEffectKind
module-attribute
¶
RenderableEffectKind = Literal['effect.fade_to', 'effect.fade_from', 'effect.paint', 'effect.saturate', 'effect.lighten', 'effect.darken', 'effect.sweep_in', 'effect.sweep_out', 'effect.slide_in', 'effect.slide_out', 'effect.hsl_shift', 'effect.dissolve', 'effect.coalesce', 'effect.glitch', 'effect.sleep', 'effect.evolve', 'effect.evolve_into', 'effect.evolve_from', 'effect.expand', 'effect.stretch', 'effect.explode']
The kinds of effect that change how a buffer looks: fx kinds that start with 'effect.'.
RenderableEffectSpecification
module-attribute
¶
RenderableEffectSpecification = FadeToEffectSpecification | FadeFromEffectSpecification | PaintEffectSpecification | SaturateEffectSpecification | LightenEffectSpecification | DarkenEffectSpecification | SweepInEffectSpecification | SweepOutEffectSpecification | SlideInEffectSpecification | SlideOutEffectSpecification | HslShiftEffectSpecification | DissolveEffectSpecification | CoalesceEffectSpecification | GlitchEffectSpecification | SleepEffectSpecification | EvolveEffectSpecification | EvolveIntoEffectSpecification | EvolveFromEffectSpecification | ExpandEffectSpecification | StretchEffectSpecification | ExplodeEffectSpecification
One visual effect as a dictionary for effects=[...]: its kind and its keywords.
Hook
module-attribute
¶
Hook: TypeAlias = Callable[[Context[DepsT, StateT]], 'object | HookGenerator[DepsT, StateT]'] | Callable[[], 'object | HookGenerator[DepsT, StateT]']
What a canvas or placement calls when an event counts: a function of the
Context, or a function with no parameters when it needs none.
HookGenerator
module-attribute
¶
A hook that spans several events: it receives the next context at each bare yield.
HookKind
module-attribute
¶
HookKind: TypeAlias = Literal['frame', 'tick', 'beat', 'key', 'mouse', 'scroll', 'drag', 'paste', 'focus', 'resize', 'state', 'custom']
When a hook runs.
'frame' before each frame, 'tick' at each simulation step, 'beat' on the canvas's
musical beat, 'key', 'mouse', 'scroll', 'drag', 'paste', 'focus' and
'resize' when that input arrives, 'state' when state the hook read changes, and
'custom' for events you push yourself. A hook without on hears every input event.
- API Reference xnano
When
module-attribute
¶
When: TypeAlias = 'str | Callable[[Context[DepsT, StateT]], bool] | _core.Expression[bool]'
The condition of a hook: an expression, a function of the context, or a string.
- An expression built from the scopes in
xnano.expressions, such asKeyboard.key == 'q', is checked by the runtime before Python is called. - A function takes the context and returns
Truewhen the hook should run. - A string such as
"keyboard.key == 'q' and not mouse.is_down"is parsed once. It uses the nameskeyboard,mouse,scroll,buffer,parent,root,timeanddeps, and the operators==,!=,<,<=,>,>=,in,and,orandnot.
A value the event did not carry, such as keyboard.key while a mouse event arrives, is
neither equal to nor different from anything, so every comparison with it is false.
- API Reference xnano
Anchor
module-attribute
¶
Axis
module-attribute
¶
Axis: TypeAlias = int | float | Percentage | HorizontalPosition | VerticalPosition | str | tuple[RangeBound, RangeBound] | NumericExpression
One number of a position or size: x, y, width or height.
12: exactly that many cells.'50%': that share of the parent.- a word that places it inside its parent:
'left','center'or'right'forx, and'top','center'or'bottom'fory. - an expression such as
(ParentWidth - Width) // 2orParentWidth * (TimeElapsed % 4 / 4): evaluated again on every frame, withTimeElapsedand the other clock references moving with the canvas's clock. - a range, a pair
(low, high): not a value but a limit on the values the axis may take. Forxandyit is how far the placement may travel, such as the track of a slider; forwidthandheightit is the smallest and largest size. Whatever is assigned afterwards is held inside the range, and the range stays until another one replaces it. Each bound is a number, a percentage string or an expression, andNoneleaves that side open.
CanvasLayout
module-attribute
¶
How a canvas places what is written on it.
'overlay' places every piece on its own, over the whole canvas. 'column' stacks the
pieces from top to bottom in the order they are written, and 'row' from left to right.
ColorValue
module-attribute
¶
ColorValue: TypeAlias = 'Color | ColorName | str | tuple[int, int, int]'
A color, an ANSI color name, a '#rrggbb' string, or a (red, green, blue) tuple.
A Tailwind name such as 'slate-400' is a TailwindColorBinding.
It is not parsed by Color.
- API Reference
-
API Reference
-
xnano
-
xnano -
xnano.appearance
appearance -
xnano.art
art -
xnano.buffers
buffers -
xnano.canvas
canvasCanvaswrite -
xnano.effects
effectsFade -
xnano.operations
operations -
xnano.pixel
pixelPixel -
xnano.placement
placementPlacementwrite -
xnano.region
regionRegionshade -
xnano.styles
stylesStyle -
xnano.terminal
terminalTerminalwrite -
xnano.widgets
widgets
-
-
xnano_core
-
xnano_core -
xnano_core._xnano_core
_xnano_core
-
-
xnano
EdgeBehavior
module-attribute
¶
What content does at the edges of its area.
'clip' lets it go past the edge, where it is not drawn. 'stop' holds it inside the
area when it moves. 'wrap' continues text on the next rows of the area.
HeldMouseButtonName
module-attribute
¶
The name of a mouse button in the held-input vocabulary of Input.
Input.is_down('mouse_left') asks whether the left button is held. The button of a mouse
event keeps the names 'left', 'right' and 'middle'.
HorizontalPosition
module-attribute
¶
A word that places something inside its parent along x.
Interpolation
module-attribute
¶
Interpolation: TypeAlias = Literal['linear', 'back_in', 'back_out', 'back_in_out', 'bounce_in', 'bounce_out', 'bounce_in_out', 'circ_in', 'circ_out', 'circ_in_out', 'cubic_in', 'cubic_out', 'cubic_in_out', 'elastic_in', 'elastic_out', 'elastic_in_out', 'expo_in', 'expo_out', 'expo_in_out', 'quad_in', 'quad_out', 'quad_in_out', 'quart_in', 'quart_out', 'quart_in_out', 'quint_in', 'quint_out', 'quint_in_out', 'sine_in', 'sine_out', 'sine_in_out', 'smooth_step', 'spring', 'reverse', 'ease_in']
How an effect eases between its start and end: 'linear', or a curve such as
'quad_in_out' or 'bounce_out'. 'ease_in' is 'quad_in'.
KeyName
module-attribute
¶
KeyName: TypeAlias = Literal['a', 'b', 'c', 'd', 'e', 'f', 'g', 'h', 'i', 'j', 'k', 'l', 'm', 'n', 'o', 'p', 'q', 'r', 's', 't', 'u', 'v', 'w', 'x', 'y', 'z', '0', '1', '2', '3', '4', '5', '6', '7', '8', '9', 'space', 'enter', 'escape', 'tab', 'backspace', 'delete', 'insert', 'home', 'end', 'page_up', 'page_down', 'up', 'down', 'left', 'right', 'f1', 'f2', 'f3', 'f4', 'f5', 'f6', 'f7', 'f8', 'f9', 'f10', 'f11', 'f12'] | str
The name of a key such as 'q', 'enter' or 'page_up'.
A key with modifiers is written as a chord joined with +, such as 'ctrl+s' or
'shift+tab'; the trailing str lets a chord and punctuation keys type-check while editors
still suggest the names listed here.
MotionDirection
module-attribute
¶
The direction a sweep, slide or stretch effect moves in.
Percentage
module-attribute
¶
Percentage: TypeAlias = Literal['5%', '10%', '15%', '20%', '25%', '30%', '35%', '40%', '45%', '50%', '55%', '60%', '65%', '70%', '75%', '80%', '85%', '90%', '95%', '100%']
A share of the space a size or position is measured against, such as '50%'.
Editors suggest the steps of 5% listed here, and every other percentage, such as '33%' or
'12.5%', works the same way; a parameter that takes a percentage also takes any str.
PixelEncoding
module-attribute
¶
'half_blocks': one column and two rows of pixels per cell. 'braille': two by four.
Playable
module-attribute
¶
Playable: TypeAlias = 'str | Note | Audio | SupportsPlay | Sequence[Playable]'
Anything play and Canvas.play accept: a
Note, an Audio, an object with __xnano_play__, a
sequence of those that plays one after another, or a str: the name of a registered
symbol, a note name such as 'C#4', or melody text such as 'C4 E4 G4:2'.
PlaySource
module-attribute
¶
PlaySource: TypeAlias = 'Playable | int | float | TerminalSound | TerminalNote | TerminalMelody'
Anything play and Canvas.play accept: a
Playable (a Note, an Audio, a symbol
name, a note name such as 'C#4', melody text, or a sequence of those), a MIDI note number
such as 60, a frequency in hertz, or a rendered sound, note or melody from xnano-audio.
RangeBound
module-attribute
¶
RangeBound: TypeAlias = Number | Percentage | str | NumericExpression | None
One end of a range as written: cells, a percentage string, an expression, or None.
Renderable
module-attribute
¶
Renderable: TypeAlias = 'str | Region | Art | Pixel | Image | Buffer | SupportsRender | Sequence[Renderable]'
Anything Canvas.write accepts: text, a
Region, an Art, a Pixel, an
Image, a core Buffer, an object with
__xnano_render__, or a sequence of those, which is stacked from top to bottom.
VerticalPosition
module-attribute
¶
A word that places something inside its parent along y.
PixelPreset
module-attribute
¶
PixelPreset: TypeAlias = Literal['block', 'half_top', 'half_bottom', 'shade_light', 'shade_medium', 'shade_dark', 'braille', 'circle', 'circle_outline', 'dot', 'diamond', 'star', 'line_horizontal', 'line_vertical', 'corner_top_left_rounded', 'corner_top_right_rounded', 'corner_bottom_left_rounded', 'corner_bottom_right_rounded', 'corner_top_left_square', 'corner_top_right_square', 'corner_bottom_left_square', 'corner_bottom_right_square', 'arrow_up', 'arrow_down', 'arrow_left', 'arrow_right', 'check', 'cross']
The names of the characters Pixel knows: Pixel('diamond') draws ◆.
BorderKind
module-attribute
¶
The line style of a border.
SpacingDictionary
¶
Bases: TypedDict
Space around text, edge by edge.
Attributes:
-
top(int | float | Percentage | str) –The space above, in cells.
-
right(int | float | Percentage | str) –The space to the right.
-
bottom(int | float | Percentage | str) –The space below.
-
left(int | float | Percentage | str) –The space to the left.
-
vertical(int | float | Percentage | str) –The space above and below, unless
toporbottomis given. -
horizontal(int | float | Percentage | str) –The space left and right, unless
leftorrightis given.
EffectController
¶
Bases: _RenderableEffectMethods, _PlayableEffectMethods
The effects of the hook that is running, one method for each effect.
Get it from context.fx. A visual effect (context.fx.fade_to(...)) starts on the
hook's buffer, and a sound effect (context.fx.reverb(...)) is added to every sound the
hook plays. The effects last while the hook does; clear() ends them sooner, and
removing the hook or its placement ends them too. Starting an effect of a kind that is
already set replaces the earlier one.
Attributes:
-
context(Context[object, object]) –The context of the hook that applies the effects.
-
active(tuple[EffectCustomization, ...]) –The effects the hook has set and not cleared or replaced.
Examples:
import xnano
with xnano.new(width=8, height=1) as canvas:
label = canvas.write('hi')
counts = []
@label.hook(on='frame')
def tint(context: xnano.Context) -> None:
if not context.fx.active:
context.fx.fade_to(foreground='red', duration_milliseconds=100)
counts.append(len(context.fx.active))
canvas.step(delta_seconds=0.05)
assert counts and set(counts) == {1}
Create the controller of a context. Use context.fx instead of calling this.
Parameters:
Methods:
-
bit_crush–Lower the resolution of the sound, for a gritty, retro tone.
-
distortion–Distort the sound by driving it into soft clipping.
-
low_pass–Keep the frequencies below
cutoffand soften those above it. -
high_pass–Keep the frequencies above
cutoffand soften those below it. -
delay–Repeat the sound as fading echoes.
-
reverb–Add the reverberation of a room.
-
tremolo–Pulse the volume up and down.
-
fade_to–Fade the colors to
foregroundandbackground. -
fade_from–Fade the colors in from
foregroundandbackground. -
paint–Paint
foregroundandbackgroundover the colors. -
saturate–Make the colors more or less saturated.
-
lighten–Lighten the colors.
-
darken–Darken the colors.
-
sweep_in–Reveal the content behind a sweep of
colorindirection. -
sweep_out–Hide the content behind a sweep of
colorindirection. -
slide_in–Slide the content in, in
direction. -
slide_out–Slide the content out, in
direction. -
hsl_shift–Shift the hue, saturation and lightness of the colors.
-
dissolve–Dissolve the content into
style, cell by cell. -
coalesce–Bring the content together out of
style, cell by cell. -
glitch–Make a share of the cells glitch for a moment.
-
sleep–Wait for
duration_millisecondswithout changing anything. -
evolve–Cycle the cells through a progression of
symbols. -
evolve_into–Turn the content into a progression of
symbols. -
evolve_from–Grow the content out of a progression of
symbols. -
expand–Expand
styleoutward from the center. -
stretch–Stretch
styleacross the area indirection. -
explode–Throw the cells outward.
-
clear–End the effects this hook has set.
Source code in xnano/_effect_controller.py
context
property
¶
The context of the hook that applies the effects.
active
property
¶
active: tuple[EffectCustomization, ...]
The effects the hook has set and not cleared or replaced.
bit_crush
¶
Lower the resolution of the sound, for a gritty, retro tone.
Other Parameters:
-
bits(int) –Quantization resolution in bits (
1to16). -
downsample(int) –Sample-hold factor (
1to256).
Returns:
-
BitCrushAudioCustomization–The effect. Assigning one of its fields changes the sounds played after that.
Source code in xnano/_effect_controller.py
distortion
¶
Distort the sound by driving it into soft clipping.
Other Parameters:
-
drive(float) –Input gain before soft-clipping (
0.1to100.0).
Returns:
-
DistortionAudioCustomization–The effect. Assigning one of its fields changes the sounds played after that.
Source code in xnano/_effect_controller.py
low_pass
¶
Keep the frequencies below cutoff and soften those above it.
Other Parameters:
-
cutoff(float) –Corner frequency in hertz (
20.0to20000.0). -
resonance(float) –Filter resonance Q (
0.1to20.0).
Returns:
-
LowPassAudioCustomization–The effect. Assigning one of its fields changes the sounds played after that.
Source code in xnano/_effect_controller.py
high_pass
¶
Keep the frequencies above cutoff and soften those below it.
Other Parameters:
-
cutoff(float) –Corner frequency in hertz (
20.0to20000.0). -
resonance(float) –Filter resonance Q (
0.1to20.0).
Returns:
-
HighPassAudioCustomization–The effect. Assigning one of its fields changes the sounds played after that.
Source code in xnano/_effect_controller.py
delay
¶
Repeat the sound as fading echoes.
Other Parameters:
-
time_milliseconds(float) –Delay time between echoes in milliseconds (
1.0to2000.0). -
feedback(float) –Echo feedback ratio (
0.0to0.95). -
mix(float) –Wet/dry mix ratio (
0.0to1.0).
Returns:
-
DelayAudioCustomization–The effect. Assigning one of its fields changes the sounds played after that.
Source code in xnano/_effect_controller.py
reverb
¶
Add the reverberation of a room.
Other Parameters:
-
room(float) –Room size (
0.0to1.0). -
damping(float) –High-frequency damping (
0.0to1.0). -
mix(float) –Wet/dry mix ratio (
0.0to1.0).
Returns:
-
ReverbAudioCustomization–The effect. Assigning one of its fields changes the sounds played after that.
Source code in xnano/_effect_controller.py
tremolo
¶
Pulse the volume up and down.
Other Parameters:
-
rate_hertz(float) –Modulation rate in hertz (
0.1to40.0). -
depth(float) –Modulation depth (
0.0to1.0).
Returns:
-
TremoloAudioCustomization–The effect. Assigning one of its fields changes the sounds played after that.
Source code in xnano/_effect_controller.py
fade_to
¶
Fade the colors to foreground and background.
Other Parameters:
-
foreground(ColorValue | Expression[ColorValue] | None) –Target foreground color, or
None. -
background(ColorValue | Expression[ColorValue] | None) –Target background color, or
None. -
duration_milliseconds(int | Expression[int | float] | None) –Duration of the fade in milliseconds.
-
interpolation(Interpolation | Expression[str] | None) –The easing curve, such as
'linear'or'quad_in_out'. -
key(str | Expression[str] | None) –Optional effect key for replacement or cancellation.
Returns:
-
FadeToEffectCustomization–The running effect. Assigning one of its fields starts it again with the new
-
FadeToEffectCustomization–values, and
cancel()stops it.
Source code in xnano/_effect_controller.py
fade_from
¶
Fade the colors in from foreground and background.
Other Parameters:
-
foreground(ColorValue | Expression[ColorValue] | None) –Starting foreground color, or
None. -
background(ColorValue | Expression[ColorValue] | None) –Starting background color, or
None. -
duration_milliseconds(int | Expression[int | float] | None) –Duration of the fade in milliseconds.
-
interpolation(Interpolation | Expression[str] | None) –The easing curve, such as
'linear'or'quad_in_out'. -
key(str | Expression[str] | None) –Optional effect key for replacement or cancellation.
Returns:
-
FadeFromEffectCustomization–The running effect. Assigning one of its fields starts it again with the new
-
FadeFromEffectCustomization–values, and
cancel()stops it.
Source code in xnano/_effect_controller.py
paint
¶
Paint foreground and background over the colors.
Other Parameters:
-
foreground(ColorValue | Expression[ColorValue] | None) –Foreground color to paint, or
None. -
background(ColorValue | Expression[ColorValue] | None) –Background color to paint, or
None. -
duration_milliseconds(int | Expression[int | float] | None) –Duration in milliseconds.
-
interpolation(Interpolation | Expression[str] | None) –The easing curve, such as
'linear'or'quad_in_out'. -
key(str | Expression[str] | None) –Optional effect key for replacement or cancellation.
Returns:
-
PaintEffectCustomization–The running effect. Assigning one of its fields starts it again with the new
-
PaintEffectCustomization–values, and
cancel()stops it.
Source code in xnano/_effect_controller.py
saturate
¶
Make the colors more or less saturated.
Other Parameters:
-
foreground(float | Expression[int | float] | None) –Foreground saturation change, or
None. -
background(float | Expression[int | float] | None) –Background saturation change, or
None. -
duration_milliseconds(int | Expression[int | float] | None) –Duration in milliseconds.
-
interpolation(Interpolation | Expression[str] | None) –The easing curve, such as
'linear'or'quad_in_out'. -
key(str | Expression[str] | None) –Optional effect key for replacement or cancellation.
Returns:
-
SaturateEffectCustomization–The running effect. Assigning one of its fields starts it again with the new
-
SaturateEffectCustomization–values, and
cancel()stops it.
Source code in xnano/_effect_controller.py
lighten
¶
Lighten the colors.
Other Parameters:
-
foreground(float | Expression[int | float] | None) –Foreground lightness increase, or
None. -
background(float | Expression[int | float] | None) –Background lightness increase, or
None. -
duration_milliseconds(int | Expression[int | float] | None) –Duration in milliseconds.
-
interpolation(Interpolation | Expression[str] | None) –The easing curve, such as
'linear'or'quad_in_out'. -
key(str | Expression[str] | None) –Optional effect key for replacement or cancellation.
Returns:
-
LightenEffectCustomization–The running effect. Assigning one of its fields starts it again with the new
-
LightenEffectCustomization–values, and
cancel()stops it.
Source code in xnano/_effect_controller.py
darken
¶
Darken the colors.
Other Parameters:
-
foreground(float | Expression[int | float] | None) –Foreground darkness increase, or
None. -
background(float | Expression[int | float] | None) –Background darkness increase, or
None. -
duration_milliseconds(int | Expression[int | float] | None) –Duration in milliseconds.
-
interpolation(Interpolation | Expression[str] | None) –The easing curve, such as
'linear'or'quad_in_out'. -
key(str | Expression[str] | None) –Optional effect key for replacement or cancellation.
Returns:
-
DarkenEffectCustomization–The running effect. Assigning one of its fields starts it again with the new
-
DarkenEffectCustomization–values, and
cancel()stops it.
Source code in xnano/_effect_controller.py
sweep_in
¶
Reveal the content behind a sweep of color in direction.
Other Parameters:
-
direction(MotionDirection | Expression[str] | None) –Sweep direction (such as
'left_to_right'). -
gradient_length(int | Expression[int | float] | None) –Length of the sweep gradient in cells.
-
randomness(int | Expression[int | float] | None) –Random offset across rows or columns.
-
color(ColorValue | Expression[ColorValue] | None) –Starting sweep color.
-
duration_milliseconds(int | Expression[int | float] | None) –Duration in milliseconds.
-
interpolation(Interpolation | Expression[str] | None) –The easing curve, such as
'linear'or'quad_in_out'. -
key(str | Expression[str] | None) –Optional effect key for replacement or cancellation.
Returns:
-
SweepInEffectCustomization–The running effect. Assigning one of its fields starts it again with the new
-
SweepInEffectCustomization–values, and
cancel()stops it.
Source code in xnano/_effect_controller.py
sweep_out
¶
Hide the content behind a sweep of color in direction.
Other Parameters:
-
direction(MotionDirection | Expression[str] | None) –Sweep direction (such as
'left_to_right'). -
gradient_length(int | Expression[int | float] | None) –Length of the sweep gradient in cells.
-
randomness(int | Expression[int | float] | None) –Random offset across rows or columns.
-
color(ColorValue | Expression[ColorValue] | None) –Ending sweep color.
-
duration_milliseconds(int | Expression[int | float] | None) –Duration in milliseconds.
-
interpolation(Interpolation | Expression[str] | None) –The easing curve, such as
'linear'or'quad_in_out'. -
key(str | Expression[str] | None) –Optional effect key for replacement or cancellation.
Returns:
-
SweepOutEffectCustomization–The running effect. Assigning one of its fields starts it again with the new
-
SweepOutEffectCustomization–values, and
cancel()stops it.
Source code in xnano/_effect_controller.py
slide_in
¶
Slide the content in, in direction.
Other Parameters:
-
direction(MotionDirection | Expression[str] | None) –Slide direction (such as
'left_to_right'). -
gradient_length(int | Expression[int | float] | None) –Length of the gradient trail in cells.
-
randomness(int | Expression[int | float] | None) –Random offset across rows or columns.
-
color(ColorValue | Expression[ColorValue] | None) –Color behind the sliding cells.
-
duration_milliseconds(int | Expression[int | float] | None) –Duration in milliseconds.
-
interpolation(Interpolation | Expression[str] | None) –The easing curve, such as
'linear'or'quad_in_out'. -
key(str | Expression[str] | None) –Optional effect key for replacement or cancellation.
Returns:
-
SlideInEffectCustomization–The running effect. Assigning one of its fields starts it again with the new
-
SlideInEffectCustomization–values, and
cancel()stops it.
Source code in xnano/_effect_controller.py
slide_out
¶
Slide the content out, in direction.
Other Parameters:
-
direction(MotionDirection | Expression[str] | None) –Slide direction (such as
'left_to_right'). -
gradient_length(int | Expression[int | float] | None) –Length of the gradient trail in cells.
-
randomness(int | Expression[int | float] | None) –Random offset across rows or columns.
-
color(ColorValue | Expression[ColorValue] | None) –Color left behind the sliding cells.
-
duration_milliseconds(int | Expression[int | float] | None) –Duration in milliseconds.
-
interpolation(Interpolation | Expression[str] | None) –The easing curve, such as
'linear'or'quad_in_out'. -
key(str | Expression[str] | None) –Optional effect key for replacement or cancellation.
Returns:
-
SlideOutEffectCustomization–The running effect. Assigning one of its fields starts it again with the new
-
SlideOutEffectCustomization–values, and
cancel()stops it.
Source code in xnano/_effect_controller.py
hsl_shift
¶
Shift the hue, saturation and lightness of the colors.
Other Parameters:
-
foreground(HslShiftTuple | None) –(hue, saturation, lightness)shift for foreground colors. -
background(HslShiftTuple | None) –(hue, saturation, lightness)shift for background colors. -
duration_milliseconds(int | Expression[int | float] | None) –Duration in milliseconds.
-
interpolation(Interpolation | Expression[str] | None) –The easing curve, such as
'linear'or'quad_in_out'. -
key(str | Expression[str] | None) –Optional effect key for replacement or cancellation.
Returns:
-
HslShiftEffectCustomization–The running effect. Assigning one of its fields starts it again with the new
-
HslShiftEffectCustomization–values, and
cancel()stops it.
Source code in xnano/_effect_controller.py
dissolve
¶
Dissolve the content into style, cell by cell.
Other Parameters:
-
style(Style | DynamicStyle | None) –Style dissolved into.
-
duration_milliseconds(int | Expression[int | float] | None) –Duration in milliseconds.
-
interpolation(Interpolation | Expression[str] | None) –The easing curve, such as
'linear'or'quad_in_out'. -
key(str | Expression[str] | None) –Optional effect key for replacement or cancellation.
Returns:
-
DissolveEffectCustomization–The running effect. Assigning one of its fields starts it again with the new
-
DissolveEffectCustomization–values, and
cancel()stops it.
Source code in xnano/_effect_controller.py
coalesce
¶
Bring the content together out of style, cell by cell.
Other Parameters:
-
style(Style | DynamicStyle | None) –Style coalesced from.
-
duration_milliseconds(int | Expression[int | float] | None) –Duration in milliseconds.
-
interpolation(Interpolation | Expression[str] | None) –The easing curve, such as
'linear'or'quad_in_out'. -
key(str | Expression[str] | None) –Optional effect key for replacement or cancellation.
Returns:
-
CoalesceEffectCustomization–The running effect. Assigning one of its fields starts it again with the new
-
CoalesceEffectCustomization–values, and
cancel()stops it.
Source code in xnano/_effect_controller.py
glitch
¶
Make a share of the cells glitch for a moment.
Other Parameters:
-
ratio(float | Expression[int | float] | None) –Fraction of cells affected by the glitch.
-
duration_milliseconds(int | Expression[int | float] | None) –Duration in milliseconds.
-
start_delay_milliseconds(tuple[int, int]) –(minimum, maximum)delay before a cell glitches. -
action_milliseconds(tuple[int, int]) –(minimum, maximum)duration of each cell glitch. -
key(str | Expression[str] | None) –Optional effect key for replacement or cancellation.
Returns:
-
GlitchEffectCustomization–The running effect. Assigning one of its fields starts it again with the new
-
GlitchEffectCustomization–values, and
cancel()stops it.
Source code in xnano/_effect_controller.py
sleep
¶
Wait for duration_milliseconds without changing anything.
Other Parameters:
-
duration_milliseconds(int | Expression[int | float]) –Pause duration in milliseconds.
-
interpolation(Interpolation | Expression[str] | None) –The easing curve, such as
'linear'or'quad_in_out'. -
key(str | Expression[str] | None) –Optional effect key for replacement or cancellation.
Returns:
-
SleepEffectCustomization–The running effect. Assigning one of its fields starts it again with the new
-
SleepEffectCustomization–values, and
cancel()stops it.
Source code in xnano/_effect_controller.py
evolve
¶
Cycle the cells through a progression of symbols.
Other Parameters:
-
symbols(EvolveSymbolSet | Expression[str] | None) –The symbols stepped through, such as
'circles','squares'or'shaded'. -
style(Style | DynamicStyle | None) –Optional style applied to the evolving symbols.
-
duration_milliseconds(int | Expression[int | float] | None) –Duration in milliseconds.
-
interpolation(Interpolation | Expression[str] | None) –The easing curve, such as
'linear'or'quad_in_out'. -
key(str | Expression[str] | None) –Optional effect key for replacement or cancellation.
Returns:
-
EvolveEffectCustomization–The running effect. Assigning one of its fields starts it again with the new
-
EvolveEffectCustomization–values, and
cancel()stops it.
Source code in xnano/_effect_controller.py
evolve_into
¶
Turn the content into a progression of symbols.
Other Parameters:
-
symbols(EvolveSymbolSet | Expression[str] | None) –The symbols stepped through, such as
'circles','squares'or'shaded'. -
style(Style | DynamicStyle | None) –Optional style applied to the evolving symbols.
-
duration_milliseconds(int | Expression[int | float] | None) –Duration in milliseconds.
-
interpolation(Interpolation | Expression[str] | None) –The easing curve, such as
'linear'or'quad_in_out'. -
key(str | Expression[str] | None) –Optional effect key for replacement or cancellation.
Returns:
-
EvolveIntoEffectCustomization–The running effect. Assigning one of its fields starts it again with the new
-
EvolveIntoEffectCustomization–values, and
cancel()stops it.
Source code in xnano/_effect_controller.py
evolve_from
¶
Grow the content out of a progression of symbols.
Other Parameters:
-
symbols(EvolveSymbolSet | Expression[str] | None) –The symbols stepped through, such as
'circles','squares'or'shaded'. -
style(Style | DynamicStyle | None) –Optional style applied to the evolving symbols.
-
duration_milliseconds(int | Expression[int | float] | None) –Duration in milliseconds.
-
interpolation(Interpolation | Expression[str] | None) –The easing curve, such as
'linear'or'quad_in_out'. -
key(str | Expression[str] | None) –Optional effect key for replacement or cancellation.
Returns:
-
EvolveFromEffectCustomization–The running effect. Assigning one of its fields starts it again with the new
-
EvolveFromEffectCustomization–values, and
cancel()stops it.
Source code in xnano/_effect_controller.py
expand
¶
Expand style outward from the center.
Other Parameters:
-
direction(Literal['horizontal', 'vertical'] | Expression[str] | None) –'horizontal'or'vertical'. -
style(Style | DynamicStyle | None) –Style expanded outward from the center.
-
duration_milliseconds(int | Expression[int | float] | None) –Duration in milliseconds.
-
interpolation(Interpolation | Expression[str] | None) –The easing curve, such as
'linear'or'quad_in_out'. -
key(str | Expression[str] | None) –Optional effect key for replacement or cancellation.
Returns:
-
ExpandEffectCustomization–The running effect. Assigning one of its fields starts it again with the new
-
ExpandEffectCustomization–values, and
cancel()stops it.
Source code in xnano/_effect_controller.py
stretch
¶
Stretch style across the area in direction.
Other Parameters:
-
direction(MotionDirection | Expression[str] | None) –'left_to_right','right_to_left','up_to_down'or'down_to_up'. -
style(Style | DynamicStyle | None) –Style stretched across the area.
-
duration_milliseconds(int | Expression[int | float] | None) –Duration in milliseconds.
-
interpolation(Interpolation | Expression[str] | None) –The easing curve, such as
'linear'or'quad_in_out'. -
key(str | Expression[str] | None) –Optional effect key for replacement or cancellation.
Returns:
-
StretchEffectCustomization–The running effect. Assigning one of its fields starts it again with the new
-
StretchEffectCustomization–values, and
cancel()stops it.
Source code in xnano/_effect_controller.py
explode
¶
Throw the cells outward.
Other Parameters:
-
force(float | Expression[int | float] | None) –Outward force throwing the cells.
-
randomness(float | Expression[int | float] | None) –Variation in force from cell to cell.
-
duration_milliseconds(int | Expression[int | float] | None) –Duration in milliseconds.
-
interpolation(Interpolation | Expression[str] | None) –The easing curve, such as
'linear'or'quad_in_out'. -
key(str | Expression[str] | None) –Optional effect key for replacement or cancellation.
Returns:
-
ExplodeEffectCustomization–The running effect. Assigning one of its fields starts it again with the new
-
ExplodeEffectCustomization–values, and
cancel()stops it.
Source code in xnano/_effect_controller.py
clear
¶
End the effects this hook has set.
Visual effects stop on the buffer, and the hook's sound effects are not applied to what it plays. Does nothing when the hook has set none.
Source code in xnano/_effect_controller.py
PlayableEffects
¶
PlayableEffects(device: AudioDevice)
Bases: _PlayableEffectMethods
The sound effects of a canvas's audio, one method for each effect.
Get it from AudioDevice.fx. Each method adds its effect to
every sound the canvas plays from then on, after the sound's own effects. A sound that is
already playing keeps the effects it started with. Adding an effect of a kind that is
already there replaces the earlier one, and clear() removes them all.
Attributes:
-
active(tuple[PlayableEffect, ...]) –The effects added here and not cleared or replaced.
Examples:
import xnano
with xnano.new(width=8, height=1) as canvas:
echo = canvas.audio.fx.delay(time_milliseconds=120.0, feedback=0.4)
assert canvas.audio.fx.active == (echo,)
canvas.play('C4')
canvas.audio.fx.clear()
assert canvas.audio.fx.active == ()
Create the sound effects of a canvas's audio. Use canvas.audio.fx instead.
Parameters:
-
device(AudioDevice) –The audio the effects are added to.
Methods:
-
bit_crush–Lower the resolution of the sound, for a gritty, retro tone.
-
distortion–Distort the sound by driving it into soft clipping.
-
low_pass–Keep the frequencies below
cutoffand soften those above it. -
high_pass–Keep the frequencies above
cutoffand soften those below it. -
delay–Repeat the sound as fading echoes.
-
reverb–Add the reverberation of a room.
-
tremolo–Pulse the volume up and down.
-
clear–Remove every effect added here, for the sounds played after this.
Source code in xnano/_effect_controller.py
active
property
¶
active: tuple[PlayableEffect, ...]
The effects added here and not cleared or replaced.
bit_crush
¶
Lower the resolution of the sound, for a gritty, retro tone.
Other Parameters:
-
bits(int) –Quantization resolution in bits (
1to16). -
downsample(int) –Sample-hold factor (
1to256).
Returns:
-
BitCrushAudioCustomization–The effect. Assigning one of its fields changes the sounds played after that.
Source code in xnano/_effect_controller.py
distortion
¶
Distort the sound by driving it into soft clipping.
Other Parameters:
-
drive(float) –Input gain before soft-clipping (
0.1to100.0).
Returns:
-
DistortionAudioCustomization–The effect. Assigning one of its fields changes the sounds played after that.
Source code in xnano/_effect_controller.py
low_pass
¶
Keep the frequencies below cutoff and soften those above it.
Other Parameters:
-
cutoff(float) –Corner frequency in hertz (
20.0to20000.0). -
resonance(float) –Filter resonance Q (
0.1to20.0).
Returns:
-
LowPassAudioCustomization–The effect. Assigning one of its fields changes the sounds played after that.
Source code in xnano/_effect_controller.py
high_pass
¶
Keep the frequencies above cutoff and soften those below it.
Other Parameters:
-
cutoff(float) –Corner frequency in hertz (
20.0to20000.0). -
resonance(float) –Filter resonance Q (
0.1to20.0).
Returns:
-
HighPassAudioCustomization–The effect. Assigning one of its fields changes the sounds played after that.
Source code in xnano/_effect_controller.py
delay
¶
Repeat the sound as fading echoes.
Other Parameters:
-
time_milliseconds(float) –Delay time between echoes in milliseconds (
1.0to2000.0). -
feedback(float) –Echo feedback ratio (
0.0to0.95). -
mix(float) –Wet/dry mix ratio (
0.0to1.0).
Returns:
-
DelayAudioCustomization–The effect. Assigning one of its fields changes the sounds played after that.
Source code in xnano/_effect_controller.py
reverb
¶
Add the reverberation of a room.
Other Parameters:
-
room(float) –Room size (
0.0to1.0). -
damping(float) –High-frequency damping (
0.0to1.0). -
mix(float) –Wet/dry mix ratio (
0.0to1.0).
Returns:
-
ReverbAudioCustomization–The effect. Assigning one of its fields changes the sounds played after that.
Source code in xnano/_effect_controller.py
tremolo
¶
Pulse the volume up and down.
Other Parameters:
-
rate_hertz(float) –Modulation rate in hertz (
0.1to40.0). -
depth(float) –Modulation depth (
0.0to1.0).
Returns:
-
TremoloAudioCustomization–The effect. Assigning one of its fields changes the sounds played after that.
Source code in xnano/_effect_controller.py
RenderableEffects
¶
Bases: _RenderableEffectMethods
The visual effects of a placement or a canvas, one method for each effect.
Get it from Placement.fx or
Canvas.fx. Each method starts its effect on that placement or
canvas at once and returns it while it runs. Starting an effect of a kind that is already
running replaces the earlier one, clear() stops them all, and removing the placement
stops its effects too.
Attributes:
-
active(tuple[RenderableEffect, ...]) –The effects started here and not cleared or replaced.
Examples:
import xnano
with xnano.new(width=8, height=1) as canvas:
label = canvas.write('hi')
fade = label.fx.fade_to(foreground='red', duration_milliseconds=100)
assert label.fx.active == (fade,)
label.fx.clear()
assert label.fx.active == ()
Create the effects of a placement or canvas. Use placement.fx instead.
Parameters:
-
target(Canvas[object, object] | Placement[object, object]) –The placement or canvas the effects run on.
Methods:
-
fade_to–Fade the colors to
foregroundandbackground. -
fade_from–Fade the colors in from
foregroundandbackground. -
paint–Paint
foregroundandbackgroundover the colors. -
saturate–Make the colors more or less saturated.
-
lighten–Lighten the colors.
-
darken–Darken the colors.
-
sweep_in–Reveal the content behind a sweep of
colorindirection. -
sweep_out–Hide the content behind a sweep of
colorindirection. -
slide_in–Slide the content in, in
direction. -
slide_out–Slide the content out, in
direction. -
hsl_shift–Shift the hue, saturation and lightness of the colors.
-
dissolve–Dissolve the content into
style, cell by cell. -
coalesce–Bring the content together out of
style, cell by cell. -
glitch–Make a share of the cells glitch for a moment.
-
sleep–Wait for
duration_millisecondswithout changing anything. -
evolve–Cycle the cells through a progression of
symbols. -
evolve_into–Turn the content into a progression of
symbols. -
evolve_from–Grow the content out of a progression of
symbols. -
expand–Expand
styleoutward from the center. -
stretch–Stretch
styleacross the area indirection. -
explode–Throw the cells outward.
-
clear–Stop every effect started here. Does nothing when none was started.
Source code in xnano/_effect_controller.py
active
property
¶
active: tuple[RenderableEffect, ...]
The effects started here and not cleared or replaced.
fade_to
¶
Fade the colors to foreground and background.
Other Parameters:
-
foreground(ColorValue | Expression[ColorValue] | None) –Target foreground color, or
None. -
background(ColorValue | Expression[ColorValue] | None) –Target background color, or
None. -
duration_milliseconds(int | Expression[int | float] | None) –Duration of the fade in milliseconds.
-
interpolation(Interpolation | Expression[str] | None) –The easing curve, such as
'linear'or'quad_in_out'. -
key(str | Expression[str] | None) –Optional effect key for replacement or cancellation.
Returns:
-
FadeToEffectCustomization–The running effect. Assigning one of its fields starts it again with the new
-
FadeToEffectCustomization–values, and
cancel()stops it.
Source code in xnano/_effect_controller.py
fade_from
¶
Fade the colors in from foreground and background.
Other Parameters:
-
foreground(ColorValue | Expression[ColorValue] | None) –Starting foreground color, or
None. -
background(ColorValue | Expression[ColorValue] | None) –Starting background color, or
None. -
duration_milliseconds(int | Expression[int | float] | None) –Duration of the fade in milliseconds.
-
interpolation(Interpolation | Expression[str] | None) –The easing curve, such as
'linear'or'quad_in_out'. -
key(str | Expression[str] | None) –Optional effect key for replacement or cancellation.
Returns:
-
FadeFromEffectCustomization–The running effect. Assigning one of its fields starts it again with the new
-
FadeFromEffectCustomization–values, and
cancel()stops it.
Source code in xnano/_effect_controller.py
paint
¶
Paint foreground and background over the colors.
Other Parameters:
-
foreground(ColorValue | Expression[ColorValue] | None) –Foreground color to paint, or
None. -
background(ColorValue | Expression[ColorValue] | None) –Background color to paint, or
None. -
duration_milliseconds(int | Expression[int | float] | None) –Duration in milliseconds.
-
interpolation(Interpolation | Expression[str] | None) –The easing curve, such as
'linear'or'quad_in_out'. -
key(str | Expression[str] | None) –Optional effect key for replacement or cancellation.
Returns:
-
PaintEffectCustomization–The running effect. Assigning one of its fields starts it again with the new
-
PaintEffectCustomization–values, and
cancel()stops it.
Source code in xnano/_effect_controller.py
saturate
¶
Make the colors more or less saturated.
Other Parameters:
-
foreground(float | Expression[int | float] | None) –Foreground saturation change, or
None. -
background(float | Expression[int | float] | None) –Background saturation change, or
None. -
duration_milliseconds(int | Expression[int | float] | None) –Duration in milliseconds.
-
interpolation(Interpolation | Expression[str] | None) –The easing curve, such as
'linear'or'quad_in_out'. -
key(str | Expression[str] | None) –Optional effect key for replacement or cancellation.
Returns:
-
SaturateEffectCustomization–The running effect. Assigning one of its fields starts it again with the new
-
SaturateEffectCustomization–values, and
cancel()stops it.
Source code in xnano/_effect_controller.py
lighten
¶
Lighten the colors.
Other Parameters:
-
foreground(float | Expression[int | float] | None) –Foreground lightness increase, or
None. -
background(float | Expression[int | float] | None) –Background lightness increase, or
None. -
duration_milliseconds(int | Expression[int | float] | None) –Duration in milliseconds.
-
interpolation(Interpolation | Expression[str] | None) –The easing curve, such as
'linear'or'quad_in_out'. -
key(str | Expression[str] | None) –Optional effect key for replacement or cancellation.
Returns:
-
LightenEffectCustomization–The running effect. Assigning one of its fields starts it again with the new
-
LightenEffectCustomization–values, and
cancel()stops it.
Source code in xnano/_effect_controller.py
darken
¶
Darken the colors.
Other Parameters:
-
foreground(float | Expression[int | float] | None) –Foreground darkness increase, or
None. -
background(float | Expression[int | float] | None) –Background darkness increase, or
None. -
duration_milliseconds(int | Expression[int | float] | None) –Duration in milliseconds.
-
interpolation(Interpolation | Expression[str] | None) –The easing curve, such as
'linear'or'quad_in_out'. -
key(str | Expression[str] | None) –Optional effect key for replacement or cancellation.
Returns:
-
DarkenEffectCustomization–The running effect. Assigning one of its fields starts it again with the new
-
DarkenEffectCustomization–values, and
cancel()stops it.
Source code in xnano/_effect_controller.py
sweep_in
¶
Reveal the content behind a sweep of color in direction.
Other Parameters:
-
direction(MotionDirection | Expression[str] | None) –Sweep direction (such as
'left_to_right'). -
gradient_length(int | Expression[int | float] | None) –Length of the sweep gradient in cells.
-
randomness(int | Expression[int | float] | None) –Random offset across rows or columns.
-
color(ColorValue | Expression[ColorValue] | None) –Starting sweep color.
-
duration_milliseconds(int | Expression[int | float] | None) –Duration in milliseconds.
-
interpolation(Interpolation | Expression[str] | None) –The easing curve, such as
'linear'or'quad_in_out'. -
key(str | Expression[str] | None) –Optional effect key for replacement or cancellation.
Returns:
-
SweepInEffectCustomization–The running effect. Assigning one of its fields starts it again with the new
-
SweepInEffectCustomization–values, and
cancel()stops it.
Source code in xnano/_effect_controller.py
sweep_out
¶
Hide the content behind a sweep of color in direction.
Other Parameters:
-
direction(MotionDirection | Expression[str] | None) –Sweep direction (such as
'left_to_right'). -
gradient_length(int | Expression[int | float] | None) –Length of the sweep gradient in cells.
-
randomness(int | Expression[int | float] | None) –Random offset across rows or columns.
-
color(ColorValue | Expression[ColorValue] | None) –Ending sweep color.
-
duration_milliseconds(int | Expression[int | float] | None) –Duration in milliseconds.
-
interpolation(Interpolation | Expression[str] | None) –The easing curve, such as
'linear'or'quad_in_out'. -
key(str | Expression[str] | None) –Optional effect key for replacement or cancellation.
Returns:
-
SweepOutEffectCustomization–The running effect. Assigning one of its fields starts it again with the new
-
SweepOutEffectCustomization–values, and
cancel()stops it.
Source code in xnano/_effect_controller.py
slide_in
¶
Slide the content in, in direction.
Other Parameters:
-
direction(MotionDirection | Expression[str] | None) –Slide direction (such as
'left_to_right'). -
gradient_length(int | Expression[int | float] | None) –Length of the gradient trail in cells.
-
randomness(int | Expression[int | float] | None) –Random offset across rows or columns.
-
color(ColorValue | Expression[ColorValue] | None) –Color behind the sliding cells.
-
duration_milliseconds(int | Expression[int | float] | None) –Duration in milliseconds.
-
interpolation(Interpolation | Expression[str] | None) –The easing curve, such as
'linear'or'quad_in_out'. -
key(str | Expression[str] | None) –Optional effect key for replacement or cancellation.
Returns:
-
SlideInEffectCustomization–The running effect. Assigning one of its fields starts it again with the new
-
SlideInEffectCustomization–values, and
cancel()stops it.
Source code in xnano/_effect_controller.py
slide_out
¶
Slide the content out, in direction.
Other Parameters:
-
direction(MotionDirection | Expression[str] | None) –Slide direction (such as
'left_to_right'). -
gradient_length(int | Expression[int | float] | None) –Length of the gradient trail in cells.
-
randomness(int | Expression[int | float] | None) –Random offset across rows or columns.
-
color(ColorValue | Expression[ColorValue] | None) –Color left behind the sliding cells.
-
duration_milliseconds(int | Expression[int | float] | None) –Duration in milliseconds.
-
interpolation(Interpolation | Expression[str] | None) –The easing curve, such as
'linear'or'quad_in_out'. -
key(str | Expression[str] | None) –Optional effect key for replacement or cancellation.
Returns:
-
SlideOutEffectCustomization–The running effect. Assigning one of its fields starts it again with the new
-
SlideOutEffectCustomization–values, and
cancel()stops it.
Source code in xnano/_effect_controller.py
hsl_shift
¶
Shift the hue, saturation and lightness of the colors.
Other Parameters:
-
foreground(HslShiftTuple | None) –(hue, saturation, lightness)shift for foreground colors. -
background(HslShiftTuple | None) –(hue, saturation, lightness)shift for background colors. -
duration_milliseconds(int | Expression[int | float] | None) –Duration in milliseconds.
-
interpolation(Interpolation | Expression[str] | None) –The easing curve, such as
'linear'or'quad_in_out'. -
key(str | Expression[str] | None) –Optional effect key for replacement or cancellation.
Returns:
-
HslShiftEffectCustomization–The running effect. Assigning one of its fields starts it again with the new
-
HslShiftEffectCustomization–values, and
cancel()stops it.
Source code in xnano/_effect_controller.py
dissolve
¶
Dissolve the content into style, cell by cell.
Other Parameters:
-
style(Style | DynamicStyle | None) –Style dissolved into.
-
duration_milliseconds(int | Expression[int | float] | None) –Duration in milliseconds.
-
interpolation(Interpolation | Expression[str] | None) –The easing curve, such as
'linear'or'quad_in_out'. -
key(str | Expression[str] | None) –Optional effect key for replacement or cancellation.
Returns:
-
DissolveEffectCustomization–The running effect. Assigning one of its fields starts it again with the new
-
DissolveEffectCustomization–values, and
cancel()stops it.
Source code in xnano/_effect_controller.py
coalesce
¶
Bring the content together out of style, cell by cell.
Other Parameters:
-
style(Style | DynamicStyle | None) –Style coalesced from.
-
duration_milliseconds(int | Expression[int | float] | None) –Duration in milliseconds.
-
interpolation(Interpolation | Expression[str] | None) –The easing curve, such as
'linear'or'quad_in_out'. -
key(str | Expression[str] | None) –Optional effect key for replacement or cancellation.
Returns:
-
CoalesceEffectCustomization–The running effect. Assigning one of its fields starts it again with the new
-
CoalesceEffectCustomization–values, and
cancel()stops it.
Source code in xnano/_effect_controller.py
glitch
¶
Make a share of the cells glitch for a moment.
Other Parameters:
-
ratio(float | Expression[int | float] | None) –Fraction of cells affected by the glitch.
-
duration_milliseconds(int | Expression[int | float] | None) –Duration in milliseconds.
-
start_delay_milliseconds(tuple[int, int]) –(minimum, maximum)delay before a cell glitches. -
action_milliseconds(tuple[int, int]) –(minimum, maximum)duration of each cell glitch. -
key(str | Expression[str] | None) –Optional effect key for replacement or cancellation.
Returns:
-
GlitchEffectCustomization–The running effect. Assigning one of its fields starts it again with the new
-
GlitchEffectCustomization–values, and
cancel()stops it.
Source code in xnano/_effect_controller.py
sleep
¶
Wait for duration_milliseconds without changing anything.
Other Parameters:
-
duration_milliseconds(int | Expression[int | float]) –Pause duration in milliseconds.
-
interpolation(Interpolation | Expression[str] | None) –The easing curve, such as
'linear'or'quad_in_out'. -
key(str | Expression[str] | None) –Optional effect key for replacement or cancellation.
Returns:
-
SleepEffectCustomization–The running effect. Assigning one of its fields starts it again with the new
-
SleepEffectCustomization–values, and
cancel()stops it.
Source code in xnano/_effect_controller.py
evolve
¶
Cycle the cells through a progression of symbols.
Other Parameters:
-
symbols(EvolveSymbolSet | Expression[str] | None) –The symbols stepped through, such as
'circles','squares'or'shaded'. -
style(Style | DynamicStyle | None) –Optional style applied to the evolving symbols.
-
duration_milliseconds(int | Expression[int | float] | None) –Duration in milliseconds.
-
interpolation(Interpolation | Expression[str] | None) –The easing curve, such as
'linear'or'quad_in_out'. -
key(str | Expression[str] | None) –Optional effect key for replacement or cancellation.
Returns:
-
EvolveEffectCustomization–The running effect. Assigning one of its fields starts it again with the new
-
EvolveEffectCustomization–values, and
cancel()stops it.
Source code in xnano/_effect_controller.py
evolve_into
¶
Turn the content into a progression of symbols.
Other Parameters:
-
symbols(EvolveSymbolSet | Expression[str] | None) –The symbols stepped through, such as
'circles','squares'or'shaded'. -
style(Style | DynamicStyle | None) –Optional style applied to the evolving symbols.
-
duration_milliseconds(int | Expression[int | float] | None) –Duration in milliseconds.
-
interpolation(Interpolation | Expression[str] | None) –The easing curve, such as
'linear'or'quad_in_out'. -
key(str | Expression[str] | None) –Optional effect key for replacement or cancellation.
Returns:
-
EvolveIntoEffectCustomization–The running effect. Assigning one of its fields starts it again with the new
-
EvolveIntoEffectCustomization–values, and
cancel()stops it.
Source code in xnano/_effect_controller.py
evolve_from
¶
Grow the content out of a progression of symbols.
Other Parameters:
-
symbols(EvolveSymbolSet | Expression[str] | None) –The symbols stepped through, such as
'circles','squares'or'shaded'. -
style(Style | DynamicStyle | None) –Optional style applied to the evolving symbols.
-
duration_milliseconds(int | Expression[int | float] | None) –Duration in milliseconds.
-
interpolation(Interpolation | Expression[str] | None) –The easing curve, such as
'linear'or'quad_in_out'. -
key(str | Expression[str] | None) –Optional effect key for replacement or cancellation.
Returns:
-
EvolveFromEffectCustomization–The running effect. Assigning one of its fields starts it again with the new
-
EvolveFromEffectCustomization–values, and
cancel()stops it.
Source code in xnano/_effect_controller.py
expand
¶
Expand style outward from the center.
Other Parameters:
-
direction(Literal['horizontal', 'vertical'] | Expression[str] | None) –'horizontal'or'vertical'. -
style(Style | DynamicStyle | None) –Style expanded outward from the center.
-
duration_milliseconds(int | Expression[int | float] | None) –Duration in milliseconds.
-
interpolation(Interpolation | Expression[str] | None) –The easing curve, such as
'linear'or'quad_in_out'. -
key(str | Expression[str] | None) –Optional effect key for replacement or cancellation.
Returns:
-
ExpandEffectCustomization–The running effect. Assigning one of its fields starts it again with the new
-
ExpandEffectCustomization–values, and
cancel()stops it.
Source code in xnano/_effect_controller.py
stretch
¶
Stretch style across the area in direction.
Other Parameters:
-
direction(MotionDirection | Expression[str] | None) –'left_to_right','right_to_left','up_to_down'or'down_to_up'. -
style(Style | DynamicStyle | None) –Style stretched across the area.
-
duration_milliseconds(int | Expression[int | float] | None) –Duration in milliseconds.
-
interpolation(Interpolation | Expression[str] | None) –The easing curve, such as
'linear'or'quad_in_out'. -
key(str | Expression[str] | None) –Optional effect key for replacement or cancellation.
Returns:
-
StretchEffectCustomization–The running effect. Assigning one of its fields starts it again with the new
-
StretchEffectCustomization–values, and
cancel()stops it.
Source code in xnano/_effect_controller.py
explode
¶
Throw the cells outward.
Other Parameters:
-
force(float | Expression[int | float] | None) –Outward force throwing the cells.
-
randomness(float | Expression[int | float] | None) –Variation in force from cell to cell.
-
duration_milliseconds(int | Expression[int | float] | None) –Duration in milliseconds.
-
interpolation(Interpolation | Expression[str] | None) –The easing curve, such as
'linear'or'quad_in_out'. -
key(str | Expression[str] | None) –Optional effect key for replacement or cancellation.
Returns:
-
ExplodeEffectCustomization–The running effect. Assigning one of its fields starts it again with the new
-
ExplodeEffectCustomization–values, and
cancel()stops it.
Source code in xnano/_effect_controller.py
clear
¶
Stop every effect started here. Does nothing when none was started.
HookHandle
¶
HookHandle(owner: _Hooked[DepsT, StateT], function: Callable[[Context[DepsT, StateT]], object], *, on: HookKind | None, when: CompiledWhen, every: float | None, after: float | None, keys: tuple[str, ...])
Bases: Generic[DepsT, StateT]
One hook attached to a canvas or a placement.
remove stops the hook, cancels its timer and closes its generator.
Attributes:
-
function(Callable[[Context[DepsT, StateT]], object]) –The function that is called when an event counts.
-
on(HookKind | None) –When the hook runs, or
Nonefor a hook that hears every input event. -
is_removed(bool) –Whether
removewas called.
Attach a function to a canvas or placement. Use hook instead of calling this.
Parameters:
-
owner(_Hooked[DepsT, StateT]) –The canvas or placement the hook listens on.
-
function(Callable[[Context[DepsT, StateT]], object]) –The function to call with a
Context. -
on(HookKind | None) –When the hook runs.
-
when(CompiledWhen) –The compiled condition.
-
every(float | None) –Seconds (
'tick') or beats ('beat') between runs. -
after(float | None) –Seconds or beats before the one run.
-
keys(tuple[str, ...]) –The normalized keys of an
on='key'hook.
Methods:
-
remove–Stop this hook. Removing it twice does nothing.
Source code in xnano/_hooks.py
function
instance-attribute
¶
The function called with a context when an event counts.
on
instance-attribute
¶
on: HookKind | None = on
When the hook runs, or None for a hook that hears every input event.
remove
¶
Stop this hook. Removing it twice does nothing.
Source code in xnano/_hooks.py
SupportsPlay
¶
Bases: Protocol[DepsT_contra, StateT_contra]
Anything that can be played: an object with a __xnano_play__ method.
The method receives the Context and returns what to play.
No base class is needed; a dataclass or a plain class qualifies. The context may be
annotated with the dependency and state types the component reads, such as
Context[Services].
Methods:
-
__xnano_play__–Return what to play.
SupportsRender
¶
Bases: Protocol[DepsT_contra, StateT_contra]
Anything that draws itself: an object with a __xnano_render__ method.
The method receives the Context and returns what to draw, which
is any Renderable. No base class is needed; a dataclass or a
plain class qualifies. The context may be annotated with the dependency and state types
the component reads, such as Context[Services]. The method runs again, on the next
frame, only when it read something that changes (the time, the size, state or an input).
Methods:
-
__xnano_render__–Return what to draw.
GateSettings
¶
Bases: TypedDict
What a screen reports to a canvas: the input gates of new() and open().
A canvas stores the gates it is given and applies them when it is opened on a screen;
a canvas without a screen has no device to report anything, and events pushed with
Canvas.push reach hooks whatever the gates say. A gate that
is left out takes its default. mouse, scroll and paste are turned on when the
canvas is opened if a hook registered before that needs them; a gate given as False
stays off, and a hook that needs it raises a
TerminalError that says which gate to turn on.
Attributes:
-
mouse(bool | Literal['motion']) –Truereports button presses, releases and drags;'motion'reports every movement as well. Unset by default: turned on when a hook registered before the canvas is opened needs it. The wheel is thescrollgate. -
scroll(bool) –Whether the mouse wheel is reported. Unset by default: turned on when a hook registered before the canvas is opened needs it.
-
keyboard(bool | Literal['disambiguated', 'release_events']) –Truefor ordinary key presses,'disambiguated'to tell keys such asescapeandalt+keyapart,'release_events'to also report repeats and releases, andFalseto ignore keys.Trueby default. -
paste(bool) –Whether pasted text arrives as one paste event instead of as key presses. Unset by default, which means on.
-
focus(bool) –Whether the window gaining and losing focus is reported. On by default.
-
interrupt(bool) –Whether
Ctrl-Cends the loop.Falsedelivers it as a key press. On by default. -
capture(bool) –Whether text printed while the screen is in use is held back and printed when the canvas closes. On by default.
-
clear(bool) –Whether what was drawn is erased when the canvas closes. On by default.
-
alternate_screen(bool) –Whether a full-window canvas draws on the alternate screen, so the shell's history comes back untouched. On by default.
CanvasAppearanceArguments
¶
Bases: TypedDict
How a canvas itself looks: its colors, text modifiers, border, padding and margin.
These style the canvas, not what is written into it, so new() and open() accept
them only without content. title is not one of them: on new() and open() it is
the window title.
Attributes:
-
style(Style | None) –A ready-made style that the colors and modifiers are applied over.
-
foreground(ColorValue | None) –The color of the cells no content covers.
-
background(ColorValue | None) –The color behind the cells no content covers.
-
bold(bool) –Whether the canvas's own cells are bold.
-
dim(bool) –Whether they are dimmed.
-
italic(bool) –Whether they are italic.
-
underline(bool) –Whether they are underlined.
-
blink(bool) –Whether they blink.
-
reverse(bool) –Whether foreground and background are swapped.
-
hidden(bool) –Whether they are hidden.
-
crossed_out(bool) –Whether they are struck through.
-
border(BorderKind | bool | None) –The kind of border around the canvas,
Truefor'plain',Falsefor none. -
border_style(Style | None) –The style of the border.
-
padding(Spacing | None) –Space between the border and what is written into the canvas.
-
margin(Spacing | None) –Space outside the border.
style
instance-attribute
¶
style: Style | None
A ready-made style that the colors and modifiers are applied over.
border
instance-attribute
¶
border: BorderKind | bool | None
The kind of border; True is 'plain' and False is none.
AppearanceArguments
¶
Bases: CanvasAppearanceArguments
How written content looks: the appearance keywords of write.
Attributes:
style
instance-attribute
¶
style: Style | None
A ready-made style that the colors and modifiers are applied over.
border
instance-attribute
¶
border: BorderKind | bool | None
The kind of border; True is 'plain' and False is none.
CanvasSettings
¶
Bases: GateSettings, CanvasAppearanceArguments
The keyword settings of new: the input gates and the canvas's own look.
Every key is described where it is declared, in
GateSettings and
CanvasAppearanceArguments.
Attributes:
-
mouse(bool | Literal['motion']) –See
GateSettings; the same forscroll,keyboard,paste,focus,interrupt,capture,clearandalternate_screen. -
background(ColorValue | None) –See
CanvasAppearanceArguments; the same for the other appearance keys. -
layout(CanvasLayout) –How the canvas places what is written on it; see
CanvasLayout.'overlay'when left out. -
edges(EdgeBehavior) –What content written on the canvas does at the edges of its area, unless it is given its own; see
EdgeBehavior.'clip'when left out.
style
instance-attribute
¶
style: Style | None
A ready-made style that the colors and modifiers are applied over.
border
instance-attribute
¶
border: BorderKind | bool | None
The kind of border; True is 'plain' and False is none.
mouse
instance-attribute
¶
True for presses, releases and drags; 'motion' for every movement too.
keyboard
instance-attribute
¶
Which key events are reported, or False for none.
OpenSettings
¶
Bases: CanvasSettings
The keyword settings of Canvas.open and of
open given a canvas.
Everything new() takes except realtime (a screen always runs in real time) and the
content. deps and state are accepted only by a canvas created without them.
Attributes:
-
fps(float) –The most frames drawn per second.
-
bpm(float) –Beats per minute for beat hooks, notes and melodies.
-
effects(Sequence[RenderableEffectSpecification]) –Effects to apply to the canvas, as dictionaries with a
kindkey. -
deps(object) –The dependencies hooks and components read as
context.deps. -
state(object) –A dataclass instance the canvas keeps and validates.
effects
instance-attribute
¶
effects: Sequence[RenderableEffectSpecification]
Effects to apply, as dictionaries with a kind key.
style
instance-attribute
¶
style: Style | None
A ready-made style that the colors and modifiers are applied over.
border
instance-attribute
¶
border: BorderKind | bool | None
The kind of border; True is 'plain' and False is none.
mouse
instance-attribute
¶
True for presses, releases and drags; 'motion' for every movement too.
keyboard
instance-attribute
¶
Which key events are reported, or False for none.
capture
instance-attribute
¶
capture: bool
Whether printed text is held back while the screen is in use.
PlayOptions
¶
Bases: TypedDict
The keyword options of play. An option replaces the same value on a
Note.
Attributes:
-
instrument(InstrumentName) –A built-in instrument, from
instrument_names. -
velocity(float) –How hard a note is played, from 0.0 to 1.0.
-
effects(Sequence[PlayableEffectSpecification]) –Sound effects as dictionaries with a
kindkey. -
volume(float) –Playback gain from 0.0 to 1.0.
-
pan(float) –Stereo position from -1.0 (left) to 1.0 (right).
-
at_beat(int) –Start when the musical clock reaches this beat.
-
beats(float) –How long a note name, a number or a
Noteis held, in beats.
effects
instance-attribute
¶
effects: Sequence[PlayableEffectSpecification]
Sound effects as dictionaries with a kind key.