Parameters

Scene parameters for the interactive player and exports.

Contents:

  • k.Int: Integer scene parameter in the range [lo, hi]: k.Int(3, 12, default=5).
  • k.Float: Real-valued scene parameter in the range [lo, hi]: k.Float(0.5, 2, default=1).
  • k.Bool: Boolean scene parameter: k.Bool(default=True).
  • k.Choice: Scene parameter with fixed options: k.Choice([k.BLUE, k.RED]) (the default is the first option, or default=).
  • k.Str: Text scene parameter: k.Str(default="...").

Back to the reference index.

k.Int (class)

k.Int(lo: int, hi: int, default: int | None = None)

Integer scene parameter in the range [lo, hi]: k.Int(3, 12, default=5). Parameters reach the scene function as signals: in video they take the default (or --param name=value on the CLI) and in interactive output they become controls. Reading a parameter with .now freezes it at build time (lint W1301).

Parameters:

Name Type Default Description
lo int required
hi int required
default int | None None Integer scene parameter in the range [lo, hi]: k.Int(3, 12, default=5).

Example:

@k.scene(params={"n": k.Int(1, 10, default=3)})
def count(s: k.Scene, n: k.Signal[int]):
    label = k.Text(lambda: f"n = {n():.0f}", size=0.9).place(at="center")
    s.play(k.write(label))

See also: k.Float, k.scene.

Members:

  • validate: Check a value given on the command line (--param) against the range.

k.Int.validate (method)

int.validate(v: object) -> object

Check a value given on the command line (--param) against the range.

Parameters:

Name Type Default Description
v object required

k.Float (class)

k.Float(lo: float, hi: float, default: float | None = None)

Real-valued scene parameter in the range [lo, hi]: k.Float(0.5, 2, default=1). Parameters reach the scene function as signals: in video they take the default (or --param name=value on the CLI) and in interactive output they become controls. Reading a parameter with .now freezes it at build time (lint W1301).

Parameters:

Name Type Default Description
lo float required
hi float required
default float | None None Real-valued scene parameter in the range [lo, hi]: k.Float(0.5, 2, default=1).

Example:

@k.scene(params={"r": k.Float(0.5, 3, default=1.5)})
def radius(s: k.Scene, r: k.Signal[float]):
    c = k.Circle(r=r).place(at="center")
    s.play(k.draw(c))

See also: k.Int, k.scene.

Members:

  • validate: Check a value given on the command line (--param) against the range.

k.Float.validate (method)

float.validate(v: object) -> object

Check a value given on the command line (--param) against the range.

Parameters:

Name Type Default Description
v object required

k.Bool (class)

k.Bool(default: bool = False)

Boolean scene parameter: k.Bool(default=True). Parameters reach the scene function as signals: in video they take the default (or --param name=value on the CLI) and in interactive output they become controls. Reading a parameter with .now freezes it at build time (lint W1301).

Parameters:

Name Type Default Description
default bool False Boolean scene parameter: k.Bool(default=True).

Example:

@k.scene(params={"grid": k.Bool(default=True)})
def with_grid(s: k.Scene, grid: k.Signal[bool]):
    ax = k.Axes(x=(0, 5, 1), y=(0, 3, 1)).place(at="center")
    tag = k.Text("grid on", visible=grid).place(above=ax, gap=0.3)
    s.play(k.draw(ax), k.fade_in(tag))

See also: k.Choice, k.scene.

Members:

  • validate: Accept booleans and true/false/yes/no/on/off/1/0 from the command line.

k.Bool.validate (method)

bool.validate(v: object) -> object

Accept booleans and true/false/yes/no/on/off/1/0 from the command line.

Parameters:

Name Type Default Description
v object required

k.Choice (class)

k.Choice(options: Sequence[Any], default: Any = None)

Scene parameter with fixed options: k.Choice([k.BLUE, k.RED]) (the default is the first option, or default=). Parameters reach the scene function as signals: in video they take the default (or --param name=value on the CLI) and in interactive output they become controls. Reading a parameter with .now freezes it at build time (lint W1301).

Parameters:

Name Type Default Description
options Sequence[Any] required
default Any None Scene parameter with fixed options: k.Choice([k.BLUE, k.RED]) (the default is the first option, or default=).

Example:

@k.scene(params={"color": k.Choice([k.BLUE, k.RED], default=k.RED)})
def choice(s: k.Scene, color: k.Signal[k.Color]):
    sq = k.Square(2, fill=color, fill_opacity=0.6).place(at="center")
    s.play(k.draw(sq))

See also: k.Int, k.scene.

Members:

  • validate: Check that a value given on the command line is one of the options.

k.Choice.validate (method)

choice.validate(v: object) -> object

Check that a value given on the command line is one of the options.

Parameters:

Name Type Default Description
v object required

k.Str (class)

k.Str(default: str = "")

Text scene parameter: k.Str(default="..."). (k.Text is the text object; one name per concept.) Parameters reach the scene function as signals: in video they take the default (or --param name=value on the CLI) and in interactive output they become controls. Reading a parameter with .now freezes it at build time (lint W1301).

Parameters:

Name Type Default Description
default str "" Text scene parameter: k.Str(default="...").

Example:

@k.scene(params={"heading": k.Str(default="Hello")})
def greeting(s: k.Scene, heading: k.Signal[str]):
    title = k.Text(heading, size=0.9).place(at="center")
    s.play(k.write(title))

See also: k.Text, k.scene.

Members:

  • validate: Check a value given on the command line (--param).

k.Str.validate (method)

str.validate(v: object) -> object

Check a value given on the command line (--param).

Parameters:

Name Type Default Description
v object required