Objects
Shapes, groups, images, SVG and mass objects (points, vector fields, stream lines).
Contents:
k.Array: An array for algorithm videos: cells with the values and the indices under them (index=Falsehides them),cell=size.k.Callout: A speech bubble or callout besideto=(an object), with a tail pointing at it, that follows it:side=("top-right","left", ...),style="bubble"(filled),"box"(outlined) or"line"(text with a leader line),gap=,max_width=(the text wraps),size=,color=.k.Gauge: A dial whose needle followsvalue=(a number or a signal, clamped torange=): numberedticks=,sweep=degrees (240),zones=[(lo, hi, color)], a readout withlabel=under the hub.k.Card: A panel aroundcontent(sized to it, orw=,h=):title=in its top-left corner,caption=under it,accent=a color bar beside the title;pad=,radius=.k.Angle: Angle markers.k.RightAngle:k.RightAngle(a, vertex, b, size=0.3): the square mark of a right angle atvertex, along the rays towardaandb.k.Circle: Circle of radiusr, centered on its position.k.Dot: Filled dot (default radius 0.08), with no stroke.k.Ellipse: Ellipse of widthwand heighth, centered on its position.k.Rect: Rectangle of widthwand heighth, centered on its position;radius=rounds the corners (for rounded corners preferk.RoundedRect).k.RoundedRect: Rectangle with rounded corners (radius=0.15by default).k.Square: Square with sideside, centered on its position.k.Polygon: Polygon from its vertices (k.Polygon((0, 0), (2, 0), (1, 1))), centered on its bounding box.k.Triangle: Triangle from its three vertices (no arguments: equilateral with radius 1).k.Line: Segment fromstarttoend(local coordinates), or centered withlength=.k.Arrow: Arrow fromstarttoendwith a tip of sizetip.k.Sector: A pie slice from the center, or a ring slice withinner=(its inner radius):r=,angle=(degrees, counterclockwise; negative goes clockwise) andstart_angle=from +x.k.Arc: Circular arc of radiusr, starting atstart_angleand sweepingangledegrees (counterclockwise).k.Path: Path from SVG commands (d="M 0 0 L 1 1") or a polyline from a list of points;closed=Truecloses the outline.k.union: Boolean operations between shapes:k.union(a, b),k.intersect(a, b)andk.subtract(a, b)return a newk.Pathcomputed from the outlines at the cursor (with the style ofa, unless another one is passed).k.intersect: Shape covering bothaandb.k.subtract:awithbcut out.k.Bar: A value shown as a bar that grows from its base, with an optional label (label=True).k.Group: Groups objects: transforms compose and opacity multiplies.k.Graph: Nodes and edges:k.Graph(nodes, edges, layout=...)with names as nodes and(u, v)or(u, v, weight)edges (arrows withdirected=True).k.Matrix: A matrix whose entries are objects in a grid: numbers, TeX strings (typeset withk.Math) or any object, betweenbrackets=("[","(","|","none").k.matrix_product: Shows a product row by column:k.matrix_product(a, b, a @ b)draws the product's brackets, then for each entry indicates its row ofaand its column ofbwhile the entry appears (step=seconds each).k.Bits: A binary register: the bits of a value, most significant first, lit when 1.k.TitleCard: An episode's opening card: the title, akicker=above it, an accent rule under it and asubtitle=.k.EndCard: What comes next:heading=("Next") over the next title, thenbrand=,series=and aninvite=.k.LowerThird: A name and a role beside an accent bar, for a corner (side="right"mirrors it); place it as usual.k.BrowserWindow: Device frames that hold content, styled to the theme:k.BrowserWindow(content, url=, w=, h=)(dots and an address bar),k.Phone(content, w=, h=)andk.Laptop(content, w=).k.Laptop:k.Laptop(content, w=7): a laptop screen in its bezel above a keyboard base; the content fills the screen.k.Phone:k.Phone(content, w=2.4, h=5): a phone body with its screen, a camera pill and a home bar; the content fills the screen.k.Epicycles: The Fourier series of a closed path (points as tuples or complex numbers), as a chain ofnrotating circles, largest first, whose tip traces the path; orcoefficients=(frequency → complex amplitude) directly.k.Icon: A built-in icon, drawn with strokes on a square of sidesize=:"check","x","warning","lightbulb","gear","user","cpu", … (k.ICON_NAMESlists them).k.ICON_NAMES: A built-in icon, drawn with strokes on a square of sidesize=:"check","x","warning","lightbulb","gear","user","cpu", … (k.ICON_NAMESlists them).k.Image: Raster image (PNG or JPEG) drawn by the renderer, centered on its position.k.SVG: Imports an SVG illustration (a file or inline markup): each shape becomes ak.Pathwith the SVG's fill, stroke and stroke width, and each<g>becomes ak.Group.k.Brace: Curly brace (}) along one side of an object's box:direction="down", "up", "left" or "right",gapunits away from it, with the tip pointing outward.k.Points: Thousands of points in a single object, batch-drawn in the core.k.VectorField: Arrows of a fieldfn(x, y) -> (vx, vy)on a grid withdensitycolumns across the width of the region (x_range,y_range).k.StreamLines: Streamlines of a field (ak.VectorFieldor a function), integrated with RK4 in the core fromseeds(a count or points).
Methods in this area:
graph.add_node: A new node and itsedges=grow in; withoutat=the graph is laid out again with it and the other nodes move to make room.graph.path: Highlights a path: its nodes and the edges between them takecolorone after the other (the accent color by default), for searches and shortest paths.graph.relayout: Moves the nodes to a new layout as a transition (another named layout, positions, or the current one again after changes); edges follow their nodes.
Back to the reference index.
k.Array (class)#
k.Array(
values: Sequence[object],
*,
index: bool = True,
cell: float = 0.8,
size: float = 0.4,
gap: float = 0.0,
**props: Unpack[TransformKeywords],
)
An array for algorithm videos: cells with the values and the indices under them (index=False hides them), cell= size. arr.cells[i] is the cell now at index i (.box, .value); arr.swap(i, j) exchanges two cells along arcs, arr.compare(i, j) highlights them, arr.set(i, v) changes a value, and arr.pointer("i", 2) points a labelled arrow at an index (it fades in the first time, then slides).
Parameters:
| Name | Type | Default | Description |
|---|---|---|---|
values |
Sequence[object] |
required | |
index |
bool |
True |
An array for algorithm videos: cells with the values and the indices under them (index=False hides them), cell= size. |
cell |
float |
0.8 |
An array for algorithm videos: cells with the values and the indices under them (index=False hides them), cell= size. |
size |
float |
0.4 |
|
gap |
float |
0.0 |
|
**props |
Unpack[TransformKeywords] |
variadic | Keyword arguments (TransformKeywords): name: str | None, key: str | None, x: FloatVal, y: FloatVal, position: VecVal, rotate: FloatVal, anchor: VecVal, z: FloatVal, scale: FloatVal, scale_x: FloatVal, scale_y: FloatVal, opacity: FloatVal, visible: BoolVal, bleed: BoolVal, emphasis: Emphasis. |
Props inherited from k.Node: x, y, rotate, scale, scale_x, scale_y, anchor, opacity, z, visible, bleed, emphasis.
Example:
@k.scene
def bubble_step(s: k.Scene):
arr = k.Array([5, 2, 9, 1]).place(at="center")
s.play(k.fade_in(arr))
s.play(arr.pointer("j", 0))
for j in range(3):
s.play(arr.pointer("j", j), duration=0.4)
s.play(arr.compare(j, j + 1), duration=0.4)
a, b = arr.cells[j].value.text.now, arr.cells[j + 1].value.text.now
if int(a) > int(b):
s.play(arr.swap(j, j + 1), duration=0.5)
s.wait(0.5)
Members:
cells: The cells in index order at the cursor (after the swaps scheduled so far).swap: Exchange the cells atiandj(they move along arcs).compare: Highlight the cells atiandj(a temporary tint and pulse).set: Change the value shown ati(the old one crossfades into the new).pointer: Pointnameat indexi: a labelled arrow under the cell fades in the first time, then slides to the new index.
Inherited from k.Group: children, to, insert, pop, fit.
Inherited from k.Node: unbind, edge, age, entered, exited, copy, place, to_place, unpin.
k.Array.cells (property)
array.cells: list[ArrayCell] # read-only
The cells in index order at the cursor (after the swaps scheduled so far).
k.Array.swap (method)
array.swap(i: int, j: int, **kw: Unpack[ReorderTiming]) -> Animation
Exchange the cells at i and j (they move along arcs).
Parameters:
| Name | Type | Default | Description |
|---|---|---|---|
i |
int |
required | Exchange the cells at i and j (they move along arcs). |
j |
int |
required | Exchange the cells at i and j (they move along arcs). |
**kw |
Unpack[ReorderTiming] |
variadic | Keyword arguments (ReorderTiming): duration: float | None, ease: EaseLike | None, path: SwapPath. |
k.Array.compare (method)
array.compare(
i: int,
j: int,
*,
color: ColorLike = k.YELLOW,
duration: float | None = None,
) -> Animation
Highlight the cells at i and j (a temporary tint and pulse).
Parameters:
| Name | Type | Default | Description |
|---|---|---|---|
i |
int |
required | Highlight the cells at i and j (a temporary tint and pulse). |
j |
int |
required | Highlight the cells at i and j (a temporary tint and pulse). |
color |
ColorLike |
k.YELLOW |
|
duration |
float | None |
None |
k.Array.set (method)
array.set(i: int, value: object, *, duration: float | None = None) -> Animation
Change the value shown at i (the old one crossfades into the new).
Parameters:
| Name | Type | Default | Description |
|---|---|---|---|
i |
int |
required | Change the value shown at i (the old one crossfades into the new). |
value |
object |
required | |
duration |
float | None |
None |
k.Array.pointer (method)
array.pointer(
name: str,
i: int,
*,
color: ColorLike = k.YELLOW,
duration: float | None = None,
) -> Animation
Point name at index i: a labelled arrow under the cell fades in the first time, then slides to the new index. Pointers follow the array if it moves.
Parameters:
| Name | Type | Default | Description |
|---|---|---|---|
name |
str |
required | Point name at index i: a labelled arrow under the cell fades in the first time, then slides to the new index. |
i |
int |
required | Point name at index i: a labelled arrow under the cell fades in the first time, then slides to the new index. |
color |
ColorLike |
k.YELLOW |
|
duration |
float | None |
None |
k.Callout (class)#
k.Callout(
text: str,
*,
to: Node,
side: Side = "top-right",
style: Literal['bubble', 'box', 'line'] = "bubble",
gap: float = 0.45,
max_width: float = 4.0,
size: float = 0.32,
pad: float = 0.22,
color: ColorLike | None = None,
**props: Unpack[VisibilityKeywords],
)
A speech bubble or callout beside to= (an object), with a tail pointing at it, that follows it: side= ("top-right", "left", ...), style="bubble" (filled), "box" (outlined) or "line" (text with a leader line), gap=, max_width= (the text wraps), size=, color=. Parts: callout.box, callout.label, callout.tail.
Parameters:
| Name | Type | Default | Description |
|---|---|---|---|
text |
str |
required | k.Callout("Wait, what?", to=folio, side="top-right"): a box with text (wrapped at max_width=) beside to (an object), with a tail pointing at it, gap= away; it follows the target as it moves. |
to |
Node |
required | A speech bubble or callout beside to= (an object), with a tail pointing at it, that follows it: side= ("top-right", "left", ...), style="bubble" (filled), "box" (outlined) or "line" (text with a leader line), gap=, max_width= (the text wraps), size=, color=. |
side |
Side |
"top-right" |
A speech bubble or callout beside to= (an object), with a tail pointing at it, that follows it: side= ("top-right", "left", ...), style="bubble" (filled), "box" (outlined) or "line" (text with a leader line), gap=, max_width= (the text wraps), size=, color=. |
style |
Literal['bubble', 'box', 'line'] |
"bubble" |
A speech bubble or callout beside to= (an object), with a tail pointing at it, that follows it: side= ("top-right", "left", ...), style="bubble" (filled), "box" (outlined) or "line" (text with a leader line), gap=, max_width= (the text wraps), size=, color=. |
gap |
float |
0.45 |
A speech bubble or callout beside to= (an object), with a tail pointing at it, that follows it: side= ("top-right", "left", ...), style="bubble" (filled), "box" (outlined) or "line" (text with a leader line), gap=, max_width= (the text wraps), size=, color=. |
max_width |
float |
4.0 |
A speech bubble or callout beside to= (an object), with a tail pointing at it, that follows it: side= ("top-right", "left", ...), style="bubble" (filled), "box" (outlined) or "line" (text with a leader line), gap=, max_width= (the text wraps), size=, color=. |
size |
float |
0.32 |
A speech bubble or callout beside to= (an object), with a tail pointing at it, that follows it: side= ("top-right", "left", ...), style="bubble" (filled), "box" (outlined) or "line" (text with a leader line), gap=, max_width= (the text wraps), size=, color=. |
pad |
float |
0.22 |
|
color |
ColorLike | None |
None |
A speech bubble or callout beside to= (an object), with a tail pointing at it, that follows it: side= ("top-right", "left", ...), style="bubble" (filled), "box" (outlined) or "line" (text with a leader line), gap=, max_width= (the text wraps), size=, color=. |
**props |
Unpack[VisibilityKeywords] |
variadic | Keyword arguments (VisibilityKeywords): opacity: FloatVal, visible: BoolVal, bleed: BoolVal, emphasis: Emphasis. |
Props inherited from k.Node: x, y, rotate, scale, scale_x, scale_y, anchor, opacity, z, visible, bleed, emphasis.
Example:
@k.scene
def thought(s: k.Scene):
fox = k.Circle(r=0.6, fill=k.ORANGE, fill_opacity=1).place(at="center")
s.add(fox)
s.play(k.fade_in(k.Callout("Wait... the slope changes at every point?", to=fox, max_width=3)))
s.play(k.fade_in(k.Callout("the fox", to=fox, side="left", style="line")))
s.play(fox.to(x=-2, unpin=True), duration=1.5)
s.wait(0.5)
Inherited from k.Group: children, to, swap, insert, pop, fit.
Inherited from k.Node: set, unbind, edge, age, entered, exited, copy, place, to_place, unpin.
k.Gauge (class)#
k.Gauge(
*,
value: float | Signal[float] = 0.0,
range: tuple[float, float] = (0.0, 100.0),
ticks: int = 5,
sweep: float = 240.0,
r: float = 1.5,
label: str = "",
zones: Sequence[tuple[float, float, ColorLike]] = (),
readout: bool = True,
needle_color: ColorLike = k.RED,
digits: int = 0,
**props: Unpack[TransformKeywords],
)
A dial whose needle follows value= (a number or a signal, clamped to range=): numbered ticks=, sweep= degrees (240), zones=[(lo, hi, color)], a readout with label= under the hub. gauge.value is the signal and gauge.to(value=...) animates it. Parts: track, needle, hub, readout, ticks, labels, zones.
Parameters:
| Name | Type | Default | Description |
|---|---|---|---|
value |
float | Signal[float] |
0.0 |
A dial whose needle follows value= (a number or a signal, clamped to range=): numbered ticks=, sweep= degrees (240), zones=[(lo, hi, color)], a readout with label= under the hub. |
range |
tuple[float, float] |
(0.0, 100.0) |
A dial whose needle follows value= (a number or a signal, clamped to range=): numbered ticks=, sweep= degrees (240), zones=[(lo, hi, color)], a readout with label= under the hub. |
ticks |
int |
5 |
A dial whose needle follows value= (a number or a signal, clamped to range=): numbered ticks=, sweep= degrees (240), zones=[(lo, hi, color)], a readout with label= under the hub. |
sweep |
float |
240.0 |
A dial whose needle follows value= (a number or a signal, clamped to range=): numbered ticks=, sweep= degrees (240), zones=[(lo, hi, color)], a readout with label= under the hub. |
r |
float |
1.5 |
|
label |
str |
"" |
A dial whose needle follows value= (a number or a signal, clamped to range=): numbered ticks=, sweep= degrees (240), zones=[(lo, hi, color)], a readout with label= under the hub. |
zones |
Sequence[tuple[float, float, ColorLike]] |
() |
A dial whose needle follows value= (a number or a signal, clamped to range=): numbered ticks=, sweep= degrees (240), zones=[(lo, hi, color)], a readout with label= under the hub. |
readout |
bool |
True |
Parts: track, needle, hub, readout, ticks, labels, zones. |
needle_color |
ColorLike |
k.RED |
|
digits |
int |
0 |
|
**props |
Unpack[TransformKeywords] |
variadic | Keyword arguments (TransformKeywords): name: str | None, key: str | None, x: FloatVal, y: FloatVal, position: VecVal, rotate: FloatVal, anchor: VecVal, z: FloatVal, scale: FloatVal, scale_x: FloatVal, scale_y: FloatVal, opacity: FloatVal, visible: BoolVal, bleed: BoolVal, emphasis: Emphasis. |
Props inherited from k.Node: x, y, rotate, scale, scale_x, scale_y, anchor, opacity, z, visible, bleed, emphasis.
Example:
@k.scene
def speedometer(s: k.Scene):
gauge = k.Gauge(value=20, range=(0, 120), ticks=6, label="km/h", zones=[(90, 120, k.RED)]).place(at="center")
s.play(k.fade_in(gauge))
s.play(gauge.to(value=100), duration=2)
s.wait(0.5)
Members:
to:gauge.to(value=80): the needle (and readout) move to a new value; other props as for any group.
Inherited from k.Group: children, swap, insert, pop, fit.
Inherited from k.Node: set, unbind, edge, age, entered, exited, copy, place, to_place, unpin.
k.Gauge.to (method)
gauge.to(
*,
value: float | None = None,
duration: float | None = None,
ease: EaseLike | None = None,
**kw: object,
) -> Animation
gauge.to(value=80): the needle (and readout) move to a new value; other props as for any group.
Parameters:
| Name | Type | Default | Description |
|---|---|---|---|
value |
float | None |
None |
gauge.to(value=80): the needle (and readout) move to a new value; other props as for any group. |
duration |
float | None |
None |
|
ease |
EaseLike | None |
None |
|
**kw |
object |
variadic |
k.Card (class)#
k.Card(
content: Node | None = None,
*,
title: str | None = None,
caption: str | None = None,
accent: ColorLike | None = None,
w: float | None = None,
h: float | None = None,
pad: float = 0.35,
radius: float = 0.18,
title_size: float = 0.32,
caption_size: float = 0.28,
**props: Unpack[TransformKeywords],
)
A panel around content (sized to it, or w=, h=): title= in its top-left corner, caption= under it, accent= a color bar beside the title; pad=, radius=. Cards line up in a k.Row for side-by-side comparisons. Parts: card.box, card.content, card.title, card.caption, card.accent.
Parameters:
| Name | Type | Default | Description |
|---|---|---|---|
content |
Node | None |
None |
A panel around content (sized to it, or w=, h=): title= in its top-left corner, caption= under it, accent= a color bar beside the title; pad=, radius=. |
title |
str | None |
None |
A panel around content (sized to it, or w=, h=): title= in its top-left corner, caption= under it, accent= a color bar beside the title; pad=, radius=. |
caption |
str | None |
None |
A panel around content (sized to it, or w=, h=): title= in its top-left corner, caption= under it, accent= a color bar beside the title; pad=, radius=. |
accent |
ColorLike | None |
None |
A panel around content (sized to it, or w=, h=): title= in its top-left corner, caption= under it, accent= a color bar beside the title; pad=, radius=. |
w |
float | None |
None |
A panel around content (sized to it, or w=, h=): title= in its top-left corner, caption= under it, accent= a color bar beside the title; pad=, radius=. |
h |
float | None |
None |
A panel around content (sized to it, or w=, h=): title= in its top-left corner, caption= under it, accent= a color bar beside the title; pad=, radius=. |
pad |
float |
0.35 |
A panel around content (sized to it, or w=, h=): title= in its top-left corner, caption= under it, accent= a color bar beside the title; pad=, radius=. |
radius |
float |
0.18 |
A panel around content (sized to it, or w=, h=): title= in its top-left corner, caption= under it, accent= a color bar beside the title; pad=, radius=. |
title_size |
float |
0.32 |
|
caption_size |
float |
0.28 |
|
**props |
Unpack[TransformKeywords] |
variadic | Keyword arguments (TransformKeywords): name: str | None, key: str | None, x: FloatVal, y: FloatVal, position: VecVal, rotate: FloatVal, anchor: VecVal, z: FloatVal, scale: FloatVal, scale_x: FloatVal, scale_y: FloatVal, opacity: FloatVal, visible: BoolVal, bleed: BoolVal, emphasis: Emphasis. |
Props inherited from k.Node: x, y, rotate, scale, scale_x, scale_y, anchor, opacity, z, visible, bleed, emphasis.
Example:
@k.scene
def compare(s: k.Scene):
rocket = k.Card(k.Triangle.right(2, 2, scale=0.6), title="Rocket", caption="pushes the gas down", accent=k.ORANGE)
gas = k.Card(k.Circle(r=0.6, fill=k.BLUE, fill_opacity=0.6), title="Gas", caption="pushes the rocket up", accent=k.BLUE)
s.play(k.fade_in(k.Row(rocket, gas, gap=1).place(at="center")))
s.play(k.indicate(gas.content))
s.wait(0.5)
See also: k.Row, k.RoundedRect.
Inherited from k.Group: children, to, swap, insert, pop, fit.
Inherited from k.Node: set, unbind, edge, age, entered, exited, copy, place, to_place, unpin.
k.Angle (class)#
k.Angle(
a: VecVal,
vertex: VecVal,
b: VecVal,
*,
r: float = 0.5,
label: str | None = None,
show_value: bool = False,
unit: Literal['deg', 'rad'] = "deg",
color: ColorLike = k.YELLOW,
stroke_width: float = 3.0,
label_size: float = 0.34,
**props: Unpack[VisibilityKeywords],
)
Angle markers. k.Angle(a, vertex, b, r=0.5) draws the arc of the smaller angle between the rays vertex→a and vertex→b, with label="θ" beside it or show_value=True for its measure (unit="deg" or "rad"); k.RightAngle(a, vertex, b, size=0.3) draws the square mark. Points are tuples or reactive points (dot.world.center, a k.vec of signals), so the marker follows an angle as it opens. Points are world coordinates: use poly.sides (not poly.vertices) for a polygon's corners.
Parameters:
| Name | Type | Default | Description |
|---|---|---|---|
a |
VecVal |
required | |
vertex |
VecVal |
required | |
b |
VecVal |
required | |
r |
float |
0.5 |
k.Angle(a, vertex, b, r=0.5) draws the arc of the smaller angle between the rays vertex→a and vertex→b, with label="θ" beside it or show_value=True for its measure (unit="deg" or "rad"); k.RightAngle(a, vertex, b, size=0.3) draws the square mark. |
label |
str | None |
None |
k.Angle(a, vertex, b, r=0.5) draws the arc of the smaller angle between the rays vertex→a and vertex→b, with label="θ" beside it or show_value=True for its measure (unit="deg" or "rad"); k.RightAngle(a, vertex, b, size=0.3) draws the square mark. |
show_value |
bool |
False |
k.Angle(a, vertex, b, r=0.5) draws the arc of the smaller angle between the rays vertex→a and vertex→b, with label="θ" beside it or show_value=True for its measure (unit="deg" or "rad"); k.RightAngle(a, vertex, b, size=0.3) draws the square mark. |
unit |
Literal['deg', 'rad'] |
"deg" |
k.Angle(a, vertex, b, r=0.5) draws the arc of the smaller angle between the rays vertex→a and vertex→b, with label="θ" beside it or show_value=True for its measure (unit="deg" or "rad"); k.RightAngle(a, vertex, b, size=0.3) draws the square mark. |
color |
ColorLike |
k.YELLOW |
|
stroke_width |
float |
3.0 |
|
label_size |
float |
0.34 |
|
**props |
Unpack[VisibilityKeywords] |
variadic | Keyword arguments (VisibilityKeywords): opacity: FloatVal, visible: BoolVal, bleed: BoolVal, emphasis: Emphasis. |
Props inherited from k.Node: x, y, rotate, scale, scale_x, scale_y, anchor, opacity, z, visible, bleed, emphasis.
Example:
@k.scene
def opening(s: k.Scene):
deg = k.signal(30.0)
origin = (-1.5, -1.0)
tip = k.vec(-1.5 + 3 * k.cos(deg * k.pi / 180), -1 + 3 * k.sin(deg * k.pi / 180))
s.add(k.Line(start=origin, end=(1.5, -1.0)), k.Line(start=origin, end=tip))
theta = k.Angle((1.5, -1.0), origin, tip, r=0.8, label="θ", show_value=True)
s.play(k.draw(theta))
s.play(deg.to(90), duration=2)
corner = k.RightAngle((1.5, -1.0), origin, tip)
s.play(k.fade_out(theta), k.draw(corner))
s.wait(0.5)
Inherited from k.Group: children, to, swap, insert, pop, fit.
Inherited from k.Node: set, unbind, edge, age, entered, exited, copy, place, to_place, unpin.
k.RightAngle (class)#
k.RightAngle(
a: VecVal,
vertex: VecVal,
b: VecVal,
*,
size: float = 0.3,
color: ColorLike = k.YELLOW,
stroke_width: float = 3.0,
**props: Unpack[VisibilityKeywords],
)
k.RightAngle(a, vertex, b, size=0.3): the square mark of a right angle at vertex, along the rays toward a and b. Parts: mark.lines.
Documented together with k.Angle.
Parameters:
| Name | Type | Default | Description |
|---|---|---|---|
a |
VecVal |
required | k.RightAngle(a, vertex, b, size=0.3): the square mark of a right angle at vertex, along the rays toward a and b. |
vertex |
VecVal |
required | k.RightAngle(a, vertex, b, size=0.3): the square mark of a right angle at vertex, along the rays toward a and b. |
b |
VecVal |
required | k.RightAngle(a, vertex, b, size=0.3): the square mark of a right angle at vertex, along the rays toward a and b. |
size |
float |
0.3 |
k.RightAngle(a, vertex, b, size=0.3): the square mark of a right angle at vertex, along the rays toward a and b. |
color |
ColorLike |
k.YELLOW |
|
stroke_width |
float |
3.0 |
|
**props |
Unpack[VisibilityKeywords] |
variadic | Keyword arguments (VisibilityKeywords): opacity: FloatVal, visible: BoolVal, bleed: BoolVal, emphasis: Emphasis. |
Props inherited from k.Node: x, y, rotate, scale, scale_x, scale_y, anchor, opacity, z, visible, bleed, emphasis.
Inherited from k.Group: children, to, swap, insert, pop, fit.
Inherited from k.Node: set, unbind, edge, age, entered, exited, copy, place, to_place, unpin.
k.Circle (class)#
k.Circle(r: FloatVal = 1.0, **props: Unpack[StyleKeywords])
Circle of radius r, centered on its position. Like every shape, it accepts the style props color (shorthand for stroke and fill), fill, fill_opacity, stroke, stroke_width, dash and the transform props.
Parameters:
| Name | Type | Default | Description |
|---|---|---|---|
r |
FloatVal |
1.0 |
Circle of radius r, centered on its position. |
**props |
Unpack[StyleKeywords] |
variadic | Keyword arguments (StyleKeywords): name: str | None, key: str | None, x: FloatVal, y: FloatVal, position: VecVal, rotate: FloatVal, anchor: VecVal, z: FloatVal, scale: FloatVal, scale_x: FloatVal, scale_y: FloatVal, opacity: FloatVal, visible: BoolVal, bleed: BoolVal, emphasis: Emphasis, fill: ColorVal, fill_opacity: FloatVal, stroke: ColorVal, stroke_width: FloatVal, dash: FloatsVal, glow: FloatVal, glow_color: ColorVal, color: ColorVal. |
Props (animatable with .to(), settable with .set() or in the constructor):
| Prop | Kind | Default | Interpolation |
|---|---|---|---|
fill |
color | theme.fg |
linear |
fill_opacity |
float | 0.0 |
linear |
stroke |
color | theme.fg |
linear |
stroke_width |
float | theme.stroke_width |
linear |
dash |
floats | () |
step_end |
glow |
float | 0.0 |
linear |
glow_color |
color | theme.no_color |
linear |
r |
float | 1.0 |
linear |
Props inherited from k.Node: x, y, rotate, scale, scale_x, scale_y, anchor, opacity, z, visible, bleed, emphasis.
Example:
@k.scene
def circle(s: k.Scene):
c = k.Circle(r=1.2, stroke=k.BLUE, fill=k.BLUE, fill_opacity=0.3).place(at="center")
s.play(k.draw(c))
s.play(c.to(r=2))
See also: k.Dot, k.Ellipse, k.Arc.
Inherited from k.Node: set, to, unbind, edge, age, entered, exited, copy, place, to_place, unpin.
k.Dot (class)#
k.Dot(r: FloatVal = 0.08, **props: Unpack[StyleKeywords])
Filled dot (default radius 0.08), with no stroke. It is the marker used in charts and for points that follow curves.
Parameters:
| Name | Type | Default | Description |
|---|---|---|---|
r |
FloatVal |
0.08 |
|
**props |
Unpack[StyleKeywords] |
variadic | Keyword arguments (StyleKeywords): name: str | None, key: str | None, x: FloatVal, y: FloatVal, position: VecVal, rotate: FloatVal, anchor: VecVal, z: FloatVal, scale: FloatVal, scale_x: FloatVal, scale_y: FloatVal, opacity: FloatVal, visible: BoolVal, bleed: BoolVal, emphasis: Emphasis, fill: ColorVal, fill_opacity: FloatVal, stroke: ColorVal, stroke_width: FloatVal, dash: FloatsVal, glow: FloatVal, glow_color: ColorVal, color: ColorVal. |
Props (animatable with .to(), settable with .set() or in the constructor):
| Prop | Kind | Default | Interpolation |
|---|---|---|---|
fill |
color | theme.fg |
linear |
fill_opacity |
float | 1.0 |
linear |
stroke |
color | theme.fg |
linear |
stroke_width |
float | 0.0 |
linear |
dash |
floats | () |
step_end |
glow |
float | 0.0 |
linear |
glow_color |
color | theme.no_color |
linear |
r |
float | 0.08 |
linear |
Props inherited from k.Node: x, y, rotate, scale, scale_x, scale_y, anchor, opacity, z, visible, bleed, emphasis.
Example:
@k.scene
def dots(s: k.Scene):
a = k.Dot(r=0.15, fill=k.RED).place(at="center")
label = k.Text("P").place(above=a, gap=0.2)
s.play(k.fade_in(a, label))
s.wait(0.5)
See also: k.Circle, curve.point_at.
Inherited from k.Node: set, to, unbind, edge, age, entered, exited, copy, place, to_place, unpin.
k.Ellipse (class)#
k.Ellipse(w: FloatVal = 2.0, h: FloatVal = 1.0, **props: Unpack[StyleKeywords])
Ellipse of width w and height h, centered on its position.
Parameters:
| Name | Type | Default | Description |
|---|---|---|---|
w |
FloatVal |
2.0 |
Ellipse of width w and height h, centered on its position. |
h |
FloatVal |
1.0 |
Ellipse of width w and height h, centered on its position. |
**props |
Unpack[StyleKeywords] |
variadic | Keyword arguments (StyleKeywords): name: str | None, key: str | None, x: FloatVal, y: FloatVal, position: VecVal, rotate: FloatVal, anchor: VecVal, z: FloatVal, scale: FloatVal, scale_x: FloatVal, scale_y: FloatVal, opacity: FloatVal, visible: BoolVal, bleed: BoolVal, emphasis: Emphasis, fill: ColorVal, fill_opacity: FloatVal, stroke: ColorVal, stroke_width: FloatVal, dash: FloatsVal, glow: FloatVal, glow_color: ColorVal, color: ColorVal. |
Props (animatable with .to(), settable with .set() or in the constructor):
| Prop | Kind | Default | Interpolation |
|---|---|---|---|
fill |
color | theme.fg |
linear |
fill_opacity |
float | 0.0 |
linear |
stroke |
color | theme.fg |
linear |
stroke_width |
float | theme.stroke_width |
linear |
dash |
floats | () |
step_end |
glow |
float | 0.0 |
linear |
glow_color |
color | theme.no_color |
linear |
w |
float | 2.0 |
linear |
h |
float | 1.0 |
linear |
Props inherited from k.Node: x, y, rotate, scale, scale_x, scale_y, anchor, opacity, z, visible, bleed, emphasis.
Example:
@k.scene
def ellipse(s: k.Scene):
e = k.Ellipse(w=4, h=2, stroke=k.PURPLE).place(at="center")
s.play(k.draw(e))
s.play(e.to(w=2, h=3))
See also: k.Circle.
Inherited from k.Node: set, to, unbind, edge, age, entered, exited, copy, place, to_place, unpin.
k.Rect (class)#
k.Rect(w: FloatVal = 2.0, h: FloatVal = 1.0, **props: Unpack[RectKeywords])
Rectangle of width w and height h, centered on its position; radius= rounds the corners (for rounded corners prefer k.RoundedRect).
Parameters:
| Name | Type | Default | Description |
|---|---|---|---|
w |
FloatVal |
2.0 |
Rectangle of width w and height h, centered on its position; radius= rounds the corners (for rounded corners prefer k.RoundedRect). |
h |
FloatVal |
1.0 |
Rectangle of width w and height h, centered on its position; radius= rounds the corners (for rounded corners prefer k.RoundedRect). |
**props |
Unpack[RectKeywords] |
variadic | Keyword arguments (RectKeywords): name: str | None, key: str | None, x: FloatVal, y: FloatVal, position: VecVal, rotate: FloatVal, anchor: VecVal, z: FloatVal, scale: FloatVal, scale_x: FloatVal, scale_y: FloatVal, opacity: FloatVal, visible: BoolVal, bleed: BoolVal, emphasis: Emphasis, fill: ColorVal, fill_opacity: FloatVal, stroke: ColorVal, stroke_width: FloatVal, dash: FloatsVal, glow: FloatVal, glow_color: ColorVal, color: ColorVal, radius: FloatVal. |
Props (animatable with .to(), settable with .set() or in the constructor):
| Prop | Kind | Default | Interpolation |
|---|---|---|---|
fill |
color | theme.fg |
linear |
fill_opacity |
float | 0.0 |
linear |
stroke |
color | theme.fg |
linear |
stroke_width |
float | theme.stroke_width |
linear |
dash |
floats | () |
step_end |
glow |
float | 0.0 |
linear |
glow_color |
color | theme.no_color |
linear |
w |
float | 2.0 |
linear |
h |
float | 1.0 |
linear |
radius |
float | 0.0 |
linear |
Props inherited from k.Node: x, y, rotate, scale, scale_x, scale_y, anchor, opacity, z, visible, bleed, emphasis.
Example:
@k.scene
def rectangle(s: k.Scene):
r = k.Rect(w=4, h=2, fill=k.GREEN, fill_opacity=0.3).place(at="center")
s.play(k.draw(r))
s.play(r.to(w=6))
See also: k.RoundedRect, k.Square.
Inherited from k.Node: set, to, unbind, edge, age, entered, exited, copy, place, to_place, unpin.
k.RoundedRect (class)#
k.RoundedRect(
w: FloatVal = 2.0,
h: FloatVal = 1.0,
radius: FloatVal = 0.15,
**props: Unpack[StyleKeywords],
)
Rectangle with rounded corners (radius=0.15 by default). Good for boxes and cards with text inside.
Parameters:
| Name | Type | Default | Description |
|---|---|---|---|
w |
FloatVal |
2.0 |
|
h |
FloatVal |
1.0 |
|
radius |
FloatVal |
0.15 |
Rectangle with rounded corners (radius=0.15 by default). |
**props |
Unpack[StyleKeywords] |
variadic | Keyword arguments (StyleKeywords): name: str | None, key: str | None, x: FloatVal, y: FloatVal, position: VecVal, rotate: FloatVal, anchor: VecVal, z: FloatVal, scale: FloatVal, scale_x: FloatVal, scale_y: FloatVal, opacity: FloatVal, visible: BoolVal, bleed: BoolVal, emphasis: Emphasis, fill: ColorVal, fill_opacity: FloatVal, stroke: ColorVal, stroke_width: FloatVal, dash: FloatsVal, glow: FloatVal, glow_color: ColorVal, color: ColorVal. |
Props inherited from k.Rect: fill, fill_opacity, stroke, stroke_width, dash, glow, glow_color, w, h, radius.
Props inherited from k.Node: x, y, rotate, scale, scale_x, scale_y, anchor, opacity, z, visible, bleed, emphasis.
Example:
@k.scene
def card(s: k.Scene):
box = k.RoundedRect(w=4, h=2.4, radius=0.3).place(at="center")
title = k.Text("Card").place(inside=box, align="top", pad=0.3)
s.play(k.draw(box), k.write(title))
s.wait(0.5)
Inherited from k.Node: set, to, unbind, edge, age, entered, exited, copy, place, to_place, unpin.
k.Square (class)#
k.Square(side: FloatVal = 1.0, **props: Unpack[RectKeywords])
Square with side side, centered on its position. It is a k.Rect with w == h.
Parameters:
| Name | Type | Default | Description |
|---|---|---|---|
side |
FloatVal |
1.0 |
Square with side side, centered on its position. |
**props |
Unpack[RectKeywords] |
variadic | Keyword arguments (RectKeywords): name: str | None, key: str | None, x: FloatVal, y: FloatVal, position: VecVal, rotate: FloatVal, anchor: VecVal, z: FloatVal, scale: FloatVal, scale_x: FloatVal, scale_y: FloatVal, opacity: FloatVal, visible: BoolVal, bleed: BoolVal, emphasis: Emphasis, fill: ColorVal, fill_opacity: FloatVal, stroke: ColorVal, stroke_width: FloatVal, dash: FloatsVal, glow: FloatVal, glow_color: ColorVal, color: ColorVal, radius: FloatVal. |
Props inherited from k.Rect: fill, fill_opacity, stroke, stroke_width, dash, glow, glow_color, w, h, radius.
Props inherited from k.Node: x, y, rotate, scale, scale_x, scale_y, anchor, opacity, z, visible, bleed, emphasis.
Example:
@k.scene
def square(s: k.Scene):
sq = k.Square(2, fill=k.YELLOW, fill_opacity=0.4).place(at="center")
s.play(k.draw(sq))
s.play(sq.to(rotate=90))
See also: k.Rect.
Members:
on: The square built on a polygon edge, outside (or inside) the polygon.
Inherited from k.Node: set, to, unbind, edge, age, entered, exited, copy, place, to_place, unpin.
k.Square.on (staticmethod)
k.Square.on(
side: Side,
outward: bool = True,
**props: Unpack[UnplacedStyleKeywords],
) -> Polygon
The square built on a polygon edge, outside (or inside) the polygon.
Parameters:
| Name | Type | Default | Description |
|---|---|---|---|
side |
Side |
required | |
outward |
bool |
True |
|
**props |
Unpack[UnplacedStyleKeywords] |
variadic | Keyword arguments (UnplacedStyleKeywords): name: str | None, key: str | None, rotate: FloatVal, anchor: VecVal, z: FloatVal, scale: FloatVal, scale_x: FloatVal, scale_y: FloatVal, opacity: FloatVal, visible: BoolVal, bleed: BoolVal, emphasis: Emphasis, fill: ColorVal, fill_opacity: FloatVal, stroke: ColorVal, stroke_width: FloatVal, dash: FloatsVal, glow: FloatVal, glow_color: ColorVal, color: ColorVal. |
k.Polygon (class)#
k.Polygon(*points: VecLike | list[VecLike], **props: Unpack[StyleKeywords])
Polygon from its vertices (k.Polygon((0, 0), (2, 0), (1, 1))), centered on its bounding box. k.Polygon.regular(n, r=) creates the regular n-sided polygon.
Parameters:
| Name | Type | Default | Description |
|---|---|---|---|
*points |
VecLike | list[VecLike] |
variadic | |
**props |
Unpack[StyleKeywords] |
variadic | Keyword arguments (StyleKeywords): name: str | None, key: str | None, x: FloatVal, y: FloatVal, position: VecVal, rotate: FloatVal, anchor: VecVal, z: FloatVal, scale: FloatVal, scale_x: FloatVal, scale_y: FloatVal, opacity: FloatVal, visible: BoolVal, bleed: BoolVal, emphasis: Emphasis, fill: ColorVal, fill_opacity: FloatVal, stroke: ColorVal, stroke_width: FloatVal, dash: FloatsVal, glow: FloatVal, glow_color: ColorVal, color: ColorVal. |
Props (animatable with .to(), settable with .set() or in the constructor):
| Prop | Kind | Default | Interpolation |
|---|---|---|---|
fill |
color | theme.fg |
linear |
fill_opacity |
float | 0.0 |
linear |
stroke |
color | theme.fg |
linear |
stroke_width |
float | theme.stroke_width |
linear |
dash |
floats | () |
step_end |
glow |
float | 0.0 |
linear |
glow_color |
color | theme.no_color |
linear |
points |
points | [] |
pointwise |
Props inherited from k.Node: x, y, rotate, scale, scale_x, scale_y, anchor, opacity, z, visible, bleed, emphasis.
Example:
@k.scene
def hexagon(s: k.Scene):
hex_ = k.Polygon.regular(6, r=1.5).place(at="center")
s.play(k.draw(hex_))
s.play(hex_.to(rotate=30))
See also: k.Triangle, k.Path.
Members:
regular: Regular polygon withnsides (a signal works: the shape follows it) and circumradiusr, a vertex on top.sides: Edges in world coordinates, at the cursor.vertices: Vertices in the polygon's own coordinates, at the cursor.
Inherited from k.Node: set, to, unbind, edge, age, entered, exited, copy, place, to_place, unpin.
k.Polygon.regular (classmethod)
k.Polygon.regular(
n: FloatVal,
r: FloatVal = 1.0,
**props: Unpack[StyleKeywords],
) -> RegularPolygon
Regular polygon with n sides (a signal works: the shape follows it) and circumradius r, a vertex on top.
Parameters:
| Name | Type | Default | Description |
|---|---|---|---|
n |
FloatVal |
required | Regular polygon with n sides (a signal works: the shape follows it) and circumradius r, a vertex on top. |
r |
FloatVal |
1.0 |
Regular polygon with n sides (a signal works: the shape follows it) and circumradius r, a vertex on top. |
**props |
Unpack[StyleKeywords] |
variadic | Keyword arguments (StyleKeywords): name: str | None, key: str | None, x: FloatVal, y: FloatVal, position: VecVal, rotate: FloatVal, anchor: VecVal, z: FloatVal, scale: FloatVal, scale_x: FloatVal, scale_y: FloatVal, opacity: FloatVal, visible: BoolVal, bleed: BoolVal, emphasis: Emphasis, fill: ColorVal, fill_opacity: FloatVal, stroke: ColorVal, stroke_width: FloatVal, dash: FloatsVal, glow: FloatVal, glow_color: ColorVal, color: ColorVal. |
k.Polygon.sides (property)
polygon.sides: list[Side] # read-only
Edges in world coordinates, at the cursor.
k.Polygon.vertices (property)
polygon.vertices: list[tuple[float, float]] # read-only
Vertices in the polygon's own coordinates, at the cursor.
k.Triangle (class)#
k.Triangle(*points: VecLike | list[VecLike], **props: Unpack[StyleKeywords])
Triangle from its three vertices (no arguments: equilateral with radius 1). k.Triangle.right(a, b, scale=) creates the right triangle with legs a and b.
Parameters:
| Name | Type | Default | Description |
|---|---|---|---|
*points |
VecLike | list[VecLike] |
variadic | |
**props |
Unpack[StyleKeywords] |
variadic | Keyword arguments (StyleKeywords): name: str | None, key: str | None, x: FloatVal, y: FloatVal, position: VecVal, rotate: FloatVal, anchor: VecVal, z: FloatVal, scale: FloatVal, scale_x: FloatVal, scale_y: FloatVal, opacity: FloatVal, visible: BoolVal, bleed: BoolVal, emphasis: Emphasis, fill: ColorVal, fill_opacity: FloatVal, stroke: ColorVal, stroke_width: FloatVal, dash: FloatsVal, glow: FloatVal, glow_color: ColorVal, color: ColorVal. |
Props inherited from k.Polygon: fill, fill_opacity, stroke, stroke_width, dash, glow, glow_color, points.
Props inherited from k.Node: x, y, rotate, scale, scale_x, scale_y, anchor, opacity, z, visible, bleed, emphasis.
Example:
@k.scene
def triangle(s: k.Scene):
tri = k.Triangle.right(3, 4, scale=0.6).place(at="center")
s.play(k.draw(tri))
s.wait(0.5)
See also: k.Polygon.
Members:
right: Right triangle with legsa(horizontal) andb(vertical).
Inherited from k.Polygon: regular, sides, vertices.
Inherited from k.Node: set, to, unbind, edge, age, entered, exited, copy, place, to_place, unpin.
k.Triangle.right (classmethod)
k.Triangle.right(
a: float,
b: float,
scale: float = 1.0,
**props: Unpack[UnscaledStyleKeywords],
) -> Triangle
Right triangle with legs a (horizontal) and b (vertical).
Parameters:
| Name | Type | Default | Description |
|---|---|---|---|
a |
float |
required | Right triangle with legs a (horizontal) and b (vertical). |
b |
float |
required | Right triangle with legs a (horizontal) and b (vertical). |
scale |
float |
1.0 |
|
**props |
Unpack[UnscaledStyleKeywords] |
variadic | Keyword arguments (UnscaledStyleKeywords): name: str | None, key: str | None, x: FloatVal, y: FloatVal, position: VecVal, rotate: FloatVal, anchor: VecVal, z: FloatVal, opacity: FloatVal, visible: BoolVal, bleed: BoolVal, emphasis: Emphasis, fill: ColorVal, fill_opacity: FloatVal, stroke: ColorVal, stroke_width: FloatVal, dash: FloatsVal, glow: FloatVal, glow_color: ColorVal, color: ColorVal. |
k.Line (class)#
k.Line(
start: VecVal | None = None,
end: VecVal | None = None,
*,
length: float | None = None,
**props: Unpack[StyleKeywords],
)
Segment from start to end (local coordinates), or centered with length=. The endpoints accept signals, which makes the line follow other objects.
Parameters:
| Name | Type | Default | Description |
|---|---|---|---|
start |
VecVal | None |
None |
Segment from start to end (local coordinates), or centered with length=. |
end |
VecVal | None |
None |
Segment from start to end (local coordinates), or centered with length=. |
length |
float | None |
None |
Segment from start to end (local coordinates), or centered with length=. |
**props |
Unpack[StyleKeywords] |
variadic | Keyword arguments (StyleKeywords): name: str | None, key: str | None, x: FloatVal, y: FloatVal, position: VecVal, rotate: FloatVal, anchor: VecVal, z: FloatVal, scale: FloatVal, scale_x: FloatVal, scale_y: FloatVal, opacity: FloatVal, visible: BoolVal, bleed: BoolVal, emphasis: Emphasis, fill: ColorVal, fill_opacity: FloatVal, stroke: ColorVal, stroke_width: FloatVal, dash: FloatsVal, glow: FloatVal, glow_color: ColorVal, color: ColorVal. |
Props (animatable with .to(), settable with .set() or in the constructor):
| Prop | Kind | Default | Interpolation |
|---|---|---|---|
fill |
color | theme.fg |
linear |
fill_opacity |
float | 0.0 |
linear |
stroke |
color | theme.fg |
linear |
stroke_width |
float | theme.stroke_width |
linear |
dash |
floats | () |
step_end |
glow |
float | 0.0 |
linear |
glow_color |
color | theme.no_color |
linear |
start |
vec2 | (-1.0, 0.0) |
linear |
end |
vec2 | (1.0, 0.0) |
linear |
Props inherited from k.Node: x, y, rotate, scale, scale_x, scale_y, anchor, opacity, z, visible, bleed, emphasis.
Example:
@k.scene
def line(s: k.Scene):
floor = k.Line(length=10).place(at="bottom", margin=1.5)
ray = k.Line(start=(0, 0), end=(2, 1), stroke=k.BLUE)
s.play(k.draw(floor), k.draw(ray))
s.wait(0.5)
Inherited from k.Node: set, to, unbind, edge, age, entered, exited, copy, place, to_place, unpin.
k.Arrow (class)#
k.Arrow(
start: VecVal | None = None,
end: VecVal | None = None,
**props: Unpack[ArrowKeywords],
)
Arrow from start to end with a tip of size tip. The endpoints accept signals.
Parameters:
| Name | Type | Default | Description |
|---|---|---|---|
start |
VecVal | None |
None |
Arrow from start to end with a tip of size tip. |
end |
VecVal | None |
None |
Arrow from start to end with a tip of size tip. |
**props |
Unpack[ArrowKeywords] |
variadic | Keyword arguments (ArrowKeywords): name: str | None, key: str | None, x: FloatVal, y: FloatVal, position: VecVal, rotate: FloatVal, anchor: VecVal, z: FloatVal, scale: FloatVal, scale_x: FloatVal, scale_y: FloatVal, opacity: FloatVal, visible: BoolVal, bleed: BoolVal, emphasis: Emphasis, fill: ColorVal, fill_opacity: FloatVal, stroke: ColorVal, stroke_width: FloatVal, dash: FloatsVal, glow: FloatVal, glow_color: ColorVal, color: ColorVal, tip: FloatVal. |
Props (animatable with .to(), settable with .set() or in the constructor):
| Prop | Kind | Default | Interpolation |
|---|---|---|---|
fill |
color | theme.fg |
linear |
fill_opacity |
float | 1.0 |
linear |
stroke |
color | theme.fg |
linear |
stroke_width |
float | theme.stroke_width |
linear |
dash |
floats | () |
step_end |
glow |
float | 0.0 |
linear |
glow_color |
color | theme.no_color |
linear |
start |
vec2 | (-1.0, 0.0) |
linear |
end |
vec2 | (1.0, 0.0) |
linear |
tip |
float | 0.25 |
linear |
Props inherited from k.Node: x, y, rotate, scale, scale_x, scale_y, anchor, opacity, z, visible, bleed, emphasis.
Example:
@k.scene
def arrow(s: k.Scene):
a = k.Text("A").place(at="left", margin=3)
b = k.Text("B").place(at="right", margin=3)
link = k.Arrow(start=(-3.5, 0), end=(3.5, 0), stroke=k.YELLOW, fill=k.YELLOW)
s.add(a, b)
s.play(k.draw(link))
See also: k.Line.
Inherited from k.Node: set, to, unbind, edge, age, entered, exited, copy, place, to_place, unpin.
k.Sector (class)#
k.Sector(
r: FloatVal = 1.0,
angle: FloatVal = 90.0,
start_angle: FloatVal = 0.0,
*,
inner: FloatVal = 0.0,
**props: Unpack[StyleKeywords],
)
A pie slice from the center, or a ring slice with inner= (its inner radius): r=, angle= (degrees, counterclockwise; negative goes clockwise) and start_angle= from +x. Every prop animates, so a slice can open or turn.
Parameters:
| Name | Type | Default | Description |
|---|---|---|---|
r |
FloatVal |
1.0 |
A pie slice from the center, or a ring slice with inner= (its inner radius): r=, angle= (degrees, counterclockwise; negative goes clockwise) and start_angle= from +x. |
angle |
FloatVal |
90.0 |
A pie slice from the center, or a ring slice with inner= (its inner radius): r=, angle= (degrees, counterclockwise; negative goes clockwise) and start_angle= from +x. |
start_angle |
FloatVal |
0.0 |
A pie slice from the center, or a ring slice with inner= (its inner radius): r=, angle= (degrees, counterclockwise; negative goes clockwise) and start_angle= from +x. |
inner |
FloatVal |
0.0 |
A pie slice from the center, or a ring slice with inner= (its inner radius): r=, angle= (degrees, counterclockwise; negative goes clockwise) and start_angle= from +x. |
**props |
Unpack[StyleKeywords] |
variadic | Keyword arguments (StyleKeywords): name: str | None, key: str | None, x: FloatVal, y: FloatVal, position: VecVal, rotate: FloatVal, anchor: VecVal, z: FloatVal, scale: FloatVal, scale_x: FloatVal, scale_y: FloatVal, opacity: FloatVal, visible: BoolVal, bleed: BoolVal, emphasis: Emphasis, fill: ColorVal, fill_opacity: FloatVal, stroke: ColorVal, stroke_width: FloatVal, dash: FloatsVal, glow: FloatVal, glow_color: ColorVal, color: ColorVal. |
Props (animatable with .to(), settable with .set() or in the constructor):
| Prop | Kind | Default | Interpolation |
|---|---|---|---|
fill |
color | theme.fg |
linear |
fill_opacity |
float | 0.0 |
linear |
stroke |
color | theme.fg |
linear |
stroke_width |
float | theme.stroke_width |
linear |
dash |
floats | () |
step_end |
glow |
float | 0.0 |
linear |
glow_color |
color | theme.no_color |
linear |
r |
float | 1.0 |
linear |
inner |
float | 0.0 |
linear |
start_angle |
float | 0.0 |
linear |
angle |
float | 90.0 |
linear |
Props inherited from k.Node: x, y, rotate, scale, scale_x, scale_y, anchor, opacity, z, visible, bleed, emphasis.
Example:
@k.scene
def slice_(s: k.Scene):
wedge = k.Sector(r=2, angle=60, start_angle=90, inner=0.8, fill=k.YELLOW, fill_opacity=0.9).place(at="center")
s.play(k.draw(wedge))
s.play(wedge.to(angle=300), duration=1.5)
See also: k.Arc, k.PieChart.
Inherited from k.Node: set, to, unbind, edge, age, entered, exited, copy, place, to_place, unpin.
k.Arc (class)#
k.Arc(
r: FloatVal = 1.0,
start_angle: FloatVal = 0.0,
angle: FloatVal = 90.0,
**props: Unpack[StyleKeywords],
)
Circular arc of radius r, starting at start_angle and sweeping angle degrees (counterclockwise).
Parameters:
| Name | Type | Default | Description |
|---|---|---|---|
r |
FloatVal |
1.0 |
Circular arc of radius r, starting at start_angle and sweeping angle degrees (counterclockwise). |
start_angle |
FloatVal |
0.0 |
Circular arc of radius r, starting at start_angle and sweeping angle degrees (counterclockwise). |
angle |
FloatVal |
90.0 |
Circular arc of radius r, starting at start_angle and sweeping angle degrees (counterclockwise). |
**props |
Unpack[StyleKeywords] |
variadic | Keyword arguments (StyleKeywords): name: str | None, key: str | None, x: FloatVal, y: FloatVal, position: VecVal, rotate: FloatVal, anchor: VecVal, z: FloatVal, scale: FloatVal, scale_x: FloatVal, scale_y: FloatVal, opacity: FloatVal, visible: BoolVal, bleed: BoolVal, emphasis: Emphasis, fill: ColorVal, fill_opacity: FloatVal, stroke: ColorVal, stroke_width: FloatVal, dash: FloatsVal, glow: FloatVal, glow_color: ColorVal, color: ColorVal. |
Props (animatable with .to(), settable with .set() or in the constructor):
| Prop | Kind | Default | Interpolation |
|---|---|---|---|
fill |
color | theme.fg |
linear |
fill_opacity |
float | 0.0 |
linear |
stroke |
color | theme.fg |
linear |
stroke_width |
float | theme.stroke_width |
linear |
dash |
floats | () |
step_end |
glow |
float | 0.0 |
linear |
glow_color |
color | theme.no_color |
linear |
r |
float | 1.0 |
linear |
start_angle |
float | 0.0 |
linear |
angle |
float | 90.0 |
linear |
Props inherited from k.Node: x, y, rotate, scale, scale_x, scale_y, anchor, opacity, z, visible, bleed, emphasis.
Example:
@k.scene
def arc(s: k.Scene):
sweep = k.Arc(r=1.5, start_angle=0, angle=270, stroke=k.ORANGE).place(at="center")
s.play(k.draw(sweep))
s.play(sweep.to(angle=360))
See also: k.Circle.
Inherited from k.Node: set, to, unbind, edge, age, entered, exited, copy, place, to_place, unpin.
k.Path (class)#
k.Path(
d: str | Sequence[VecLike] = "",
*,
closed: bool = False,
**props: Unpack[StyleKeywords],
)
Path from SVG commands (d="M 0 0 L 1 1") or a polyline from a list of points; closed=True closes the outline.
Parameters:
| Name | Type | Default | Description |
|---|---|---|---|
d |
str | Sequence[VecLike] |
"" |
Path from SVG commands (d="M 0 0 L 1 1") or a polyline from a list of points; closed=True closes the outline. |
closed |
bool |
False |
Path from SVG commands (d="M 0 0 L 1 1") or a polyline from a list of points; closed=True closes the outline. |
**props |
Unpack[StyleKeywords] |
variadic | Keyword arguments (StyleKeywords): name: str | None, key: str | None, x: FloatVal, y: FloatVal, position: VecVal, rotate: FloatVal, anchor: VecVal, z: FloatVal, scale: FloatVal, scale_x: FloatVal, scale_y: FloatVal, opacity: FloatVal, visible: BoolVal, bleed: BoolVal, emphasis: Emphasis, fill: ColorVal, fill_opacity: FloatVal, stroke: ColorVal, stroke_width: FloatVal, dash: FloatsVal, glow: FloatVal, glow_color: ColorVal, color: ColorVal. |
Props (animatable with .to(), settable with .set() or in the constructor):
| Prop | Kind | Default | Interpolation |
|---|---|---|---|
fill |
color | theme.fg |
linear |
fill_opacity |
float | 0.0 |
linear |
stroke |
color | theme.fg |
linear |
stroke_width |
float | theme.stroke_width |
linear |
dash |
floats | () |
step_end |
glow |
float | 0.0 |
linear |
glow_color |
color | theme.no_color |
linear |
d |
str | "" |
step_end |
closed |
bool | False |
step_end |
Props inherited from k.Node: x, y, rotate, scale, scale_x, scale_y, anchor, opacity, z, visible, bleed, emphasis.
Example:
@k.scene
def path(s: k.Scene):
zigzag = k.Path([(-3, 0), (-1, 1), (1, -1), (3, 0)], stroke=k.TEAL).place(at="center")
s.play(k.draw(zigzag), duration=1.5)
s.wait(0.5)
See also: k.Polygon, k.follow.
Inherited from k.Node: set, to, unbind, edge, age, entered, exited, copy, place, to_place, unpin.
k.union (function)#
k.union(a: Node, b: Node, **style: Unpack[StyleKeywords]) -> Path
Boolean operations between shapes: k.union(a, b), k.intersect(a, b) and k.subtract(a, b) return a new k.Path computed from the outlines at the cursor (with the style of a, unless another one is passed).
Parameters:
| Name | Type | Default | Description |
|---|---|---|---|
a |
Node |
required | Boolean operations between shapes: k.union(a, b), k.intersect(a, b) and k.subtract(a, b) return a new k.Path computed from the outlines at the cursor (with the style of a, unless another one is passed). |
b |
Node |
required | Shape covering a or b (style of a unless given). |
**style |
Unpack[StyleKeywords] |
variadic | Keyword arguments (StyleKeywords): name: str | None, key: str | None, x: FloatVal, y: FloatVal, position: VecVal, rotate: FloatVal, anchor: VecVal, z: FloatVal, scale: FloatVal, scale_x: FloatVal, scale_y: FloatVal, opacity: FloatVal, visible: BoolVal, bleed: BoolVal, emphasis: Emphasis, fill: ColorVal, fill_opacity: FloatVal, stroke: ColorVal, stroke_width: FloatVal, dash: FloatsVal, glow: FloatVal, glow_color: ColorVal, color: ColorVal. |
Example:
@k.scene
def moon(s: k.Scene):
disk = k.Circle(1.5, fill=k.YELLOW, fill_opacity=1, stroke_width=0)
shadow = k.Circle(1.3, x=0.8)
crescent = k.subtract(disk, shadow)
s.play(k.draw(crescent))
k.intersect (function)#
k.intersect(a: Node, b: Node, **style: Unpack[StyleKeywords]) -> Path
Shape covering both a and b.
Documented together with k.union.
Parameters:
| Name | Type | Default | Description |
|---|---|---|---|
a |
Node |
required | Shape covering both a and b. |
b |
Node |
required | Shape covering both a and b. |
**style |
Unpack[StyleKeywords] |
variadic | Keyword arguments (StyleKeywords): name: str | None, key: str | None, x: FloatVal, y: FloatVal, position: VecVal, rotate: FloatVal, anchor: VecVal, z: FloatVal, scale: FloatVal, scale_x: FloatVal, scale_y: FloatVal, opacity: FloatVal, visible: BoolVal, bleed: BoolVal, emphasis: Emphasis, fill: ColorVal, fill_opacity: FloatVal, stroke: ColorVal, stroke_width: FloatVal, dash: FloatsVal, glow: FloatVal, glow_color: ColorVal, color: ColorVal. |
k.subtract (function)#
k.subtract(a: Node, b: Node, **style: Unpack[StyleKeywords]) -> Path
a with b cut out.
Documented together with k.union.
Parameters:
| Name | Type | Default | Description |
|---|---|---|---|
a |
Node |
required | a with b cut out. |
b |
Node |
required | a with b cut out. |
**style |
Unpack[StyleKeywords] |
variadic | Keyword arguments (StyleKeywords): name: str | None, key: str | None, x: FloatVal, y: FloatVal, position: VecVal, rotate: FloatVal, anchor: VecVal, z: FloatVal, scale: FloatVal, scale_x: FloatVal, scale_y: FloatVal, opacity: FloatVal, visible: BoolVal, bleed: BoolVal, emphasis: Emphasis, fill: ColorVal, fill_opacity: FloatVal, stroke: ColorVal, stroke_width: FloatVal, dash: FloatsVal, glow: FloatVal, glow_color: ColorVal, color: ColorVal. |
k.Bar (class)#
k.Bar(
value: FloatVal = 0.0,
*,
label: bool = False,
width: float = 0.6,
unit: float = 0.4,
color: ColorLike | None = None,
**props: Unpack[TransformKeywords],
)
A value shown as a bar that grows from its base, with an optional label (label=True). bar.value is a signal: animating it changes the height and the label. Used in algorithms and charts.
Parameters:
| Name | Type | Default | Description |
|---|---|---|---|
value |
FloatVal |
0.0 |
|
label |
bool |
False |
A value shown as a bar that grows from its base, with an optional label (label=True). |
width |
float |
0.6 |
|
unit |
float |
0.4 |
|
color |
ColorLike | None |
None |
|
**props |
Unpack[TransformKeywords] |
variadic | Keyword arguments (TransformKeywords): name: str | None, key: str | None, x: FloatVal, y: FloatVal, position: VecVal, rotate: FloatVal, anchor: VecVal, z: FloatVal, scale: FloatVal, scale_x: FloatVal, scale_y: FloatVal, opacity: FloatVal, visible: BoolVal, bleed: BoolVal, emphasis: Emphasis. |
Props (animatable with .to(), settable with .set() or in the constructor):
| Prop | Kind | Default | Interpolation |
|---|---|---|---|
value |
float | 0.0 |
linear |
Props inherited from k.Node: x, y, rotate, scale, scale_x, scale_y, anchor, opacity, z, visible, bleed, emphasis.
Example:
@k.scene
def bar(s: k.Scene):
b = k.Bar(3, label=True).place(at="center")
s.play(k.grow(b, from_="bottom"))
s.play(b.to(value=7))
s.wait(0.5)
See also: k.grow, k.Row, group.swap.
Inherited from k.Group: children, to, swap, insert, pop, fit.
Inherited from k.Node: set, unbind, edge, age, entered, exited, copy, place, to_place, unpin.
k.Group (class)#
k.Group(*children: ChildT | Sequence[ChildT], **props: Unpack[GroupKeywords])
Groups objects: transforms compose and opacity multiplies. An object has exactly one parent. Groups are iterable and indexable (g[0]), with indices at the cursor.
Parameters:
| Name | Type | Default | Description |
|---|---|---|---|
*children |
ChildT | Sequence[ChildT] |
variadic | |
**props |
Unpack[GroupKeywords] |
variadic |
Props inherited from k.Node: x, y, rotate, scale, scale_x, scale_y, anchor, opacity, z, visible, bleed, emphasis.
Example:
@k.scene
def group(s: k.Scene):
sun = k.Circle(r=0.6, fill=k.YELLOW, fill_opacity=1)
ray = k.Line(start=(0.8, 0), end=(1.4, 0), stroke=k.YELLOW)
icon = k.Group(sun, ray).place(at="center")
s.play(k.draw(icon))
s.play(icon.to(scale=1.5, rotate=90))
See also: k.Row, k.Stack, k.Component.
Members:
children: Children at the cursor, in order (reflects reorders already scheduled).to: Animated change of state;children=reorders, inserts or removes children with an animated reflow (path="straight": children that pass each other move in straight lines instead of arcs).swap: Named transition: swaps the places of two children and the container animates the reflow.insert: Named transition: inserts a child at positioni; it enters together with the reflow.pop: Named transition: removes the child at positioni(default: the last one); it exits together with the reflow.fit: Scales the group once, at the cursor, until it fits an area (usuallys.frame.safe, the frame's safe area), with an optionalmargin=.
Inherited from k.Node: set, unbind, edge, age, entered, exited, copy, place, to_place, unpin.
k.Group.children (property)
group.children: list[ChildT] # read-only
Children at the cursor, in order (reflects reorders already scheduled).
k.Group.to (method)
group.to(
*,
duration: float | None = None,
ease: EaseLike | None = None,
delay: float = 0.0,
blend: Blend = "replace",
place: PlaceKeywords | Mapping[str, object] | None = None,
children: Sequence[Node] | None = None,
path: SwapPath = "arc",
**props: Unpack[PropChanges],
) -> Animation
Animated change of state; children= reorders, inserts or removes children with an animated reflow (path="straight": children that pass each other move in straight lines instead of arcs).
Parameters:
| Name | Type | Default | Description |
|---|---|---|---|
duration |
float | None |
None |
|
ease |
EaseLike | None |
None |
|
delay |
float |
0.0 |
|
blend |
Blend |
"replace" |
|
place |
PlaceKeywords | Mapping[str, object] | None |
None |
|
children |
Sequence[Node] | None |
None |
Animated change of state; children= reorders, inserts or removes children with an animated reflow (path="straight": children that pass each other move in straight lines instead of arcs). |
path |
SwapPath |
"arc" |
Animated change of state; children= reorders, inserts or removes children with an animated reflow (path="straight": children that pass each other move in straight lines instead of arcs). |
**props |
Unpack[PropChanges] |
variadic |
k.Group.swap (method)
group.swap(i: int, j: int, **kw: Unpack[ReorderTiming]) -> Animation
Named transition: swaps the places of two children and the container animates the reflow. Equivalent to group.to(children=[...]) with i and j swapped. Children that pass each other travel on opposite arcs; path="straight" moves them in straight lines (calmer for bar-like rows at high tempo).
Parameters:
| Name | Type | Default | Description |
|---|---|---|---|
i |
int |
required | Equivalent to group.to(children=[...]) with i and j swapped. |
j |
int |
required | Equivalent to group.to(children=[...]) with i and j swapped. |
**kw |
Unpack[ReorderTiming] |
variadic | Keyword arguments (ReorderTiming): duration: float | None, ease: EaseLike | None, path: SwapPath. |
Example:
@k.scene
def swap(s: k.Scene):
bars = [k.Bar(v, label=True) for v in [4, 1, 3]]
row = k.Row(*bars, gap=0.3, align="bottom").place(at="center")
s.add(row)
s.play(row.swap(0, 1), duration=0.6)
s.play(row.swap(1, 2), duration=0.6)
See also: group.insert, group.pop, k.Row.
k.Group.insert (method)
group.insert(i: int, obj: Node, **kw: Unpack[ReorderTiming]) -> Animation
Named transition: inserts a child at position i; it enters together with the reflow. Equivalent to group.to(children=[...]).
Parameters:
| Name | Type | Default | Description |
|---|---|---|---|
i |
int |
required | Named transition: inserts a child at position i; it enters together with the reflow. |
obj |
Node |
required | |
**kw |
Unpack[ReorderTiming] |
variadic | Keyword arguments (ReorderTiming): duration: float | None, ease: EaseLike | None, path: SwapPath. |
Example:
@k.scene
def insert(s: k.Scene):
row = k.Row(k.Square(0.8), k.Square(0.8), gap=0.4).place(at="center")
s.add(row)
s.play(row.insert(1, k.Circle(r=0.4, fill=k.RED, fill_opacity=1)))
s.wait(0.5)
See also: group.pop, group.swap.
k.Group.pop (method)
group.pop(i: int = -1, **kw: Unpack[ReorderTiming]) -> Animation
Named transition: removes the child at position i (default: the last one); it exits together with the reflow. Equivalent to group.to(children=[...]).
Parameters:
| Name | Type | Default | Description |
|---|---|---|---|
i |
int |
-1 |
Named transition: removes the child at position i (default: the last one); it exits together with the reflow. |
**kw |
Unpack[ReorderTiming] |
variadic | Keyword arguments (ReorderTiming): duration: float | None, ease: EaseLike | None, path: SwapPath. |
Example:
@k.scene
def remove(s: k.Scene):
row = k.Row(*[k.Square(0.8) for _ in range(4)], gap=0.4).place(at="center")
s.add(row)
s.play(row.pop(0))
s.wait(0.5)
See also: group.insert, group.swap.
k.Group.fit (method)
group.fit(area: FrameRect, margin: float = 0.0) -> Group
Scales the group once, at the cursor, until it fits an area (usually s.frame.safe, the frame's safe area), with an optional margin=.
Parameters:
| Name | Type | Default | Description |
|---|---|---|---|
area |
FrameRect |
required | Scale (once, at the cursor) so the group fits inside area (e.g. |
margin |
float |
0.0 |
Scales the group once, at the cursor, until it fits an area (usually s.frame.safe, the frame's safe area), with an optional margin=. |
Example:
@k.scene
def fit(s: k.Scene):
cards = [k.RoundedRect(w=3, h=2) for _ in range(12)]
grid = k.Grid(*cards, cols=4, gap=0.4).place(at="center").fit(s.frame.safe)
s.play(k.draw(grid))
s.wait(0.5)
See also: k.Grid.
k.Graph (class)#
k.Graph(
nodes: Sequence[NodeName],
edges: Sequence[EdgeSpec] = (),
*,
layout: GraphLayout = "force",
root: NodeName | None = None,
directed: bool = False,
width: float = 10.0,
height: float = 5.5,
radius: float = 0.35,
size: float = 0.3,
**props: Unpack[TransformKeywords],
)
Nodes and edges: k.Graph(nodes, edges, layout=...) with names as nodes and (u, v) or (u, v, weight) edges (arrows with directed=True). Layouts: "force", "tree" (from root=), "layered" (left to right, for networks), "circle" or a dict of positions. g.node(name) and g.edge_between(u, v) give the parts; edges follow their nodes.
Parameters:
| Name | Type | Default | Description |
|---|---|---|---|
nodes |
Sequence[NodeName] |
required | |
edges |
Sequence[EdgeSpec] |
() |
|
layout |
GraphLayout |
"force" |
Nodes and edges: k.Graph(nodes, edges, layout=...) with names as nodes and (u, v) or (u, v, weight) edges (arrows with directed=True). |
root |
NodeName | None |
None |
Layouts: "force", "tree" (from root=), "layered" (left to right, for networks), "circle" or a dict of positions. |
directed |
bool |
False |
Nodes and edges: k.Graph(nodes, edges, layout=...) with names as nodes and (u, v) or (u, v, weight) edges (arrows with directed=True). |
width |
float |
10.0 |
|
height |
float |
5.5 |
|
radius |
float |
0.35 |
|
size |
float |
0.3 |
|
**props |
Unpack[TransformKeywords] |
variadic | Keyword arguments (TransformKeywords): name: str | None, key: str | None, x: FloatVal, y: FloatVal, position: VecVal, rotate: FloatVal, anchor: VecVal, z: FloatVal, scale: FloatVal, scale_x: FloatVal, scale_y: FloatVal, opacity: FloatVal, visible: BoolVal, bleed: BoolVal, emphasis: Emphasis. |
Props inherited from k.Node: x, y, rotate, scale, scale_x, scale_y, anchor, opacity, z, visible, bleed, emphasis.
Example:
@k.scene
def tree(s: k.Scene):
g = k.Graph(["a", "b", "c", "d", "e"], [("a", "b"), ("a", "c", 4), ("b", "d"), ("b", "e")], layout="tree", width=7, height=4)
s.play(k.draw(g))
s.play(k.indicate(g.node("c")))
See also: graph.add_node, graph.path, graph.relayout.
Members:
node: The node calledname(.circle,.label).edge_between: The edge betweenuandv(.line,.label); either order for undirected graphs.nodes: The nodes, in the order they were added.edges: The edges, in the order they were added.add_node: A new node and itsedges=grow in; withoutat=the graph is laid out again with it and the other nodes move to make room.add_edge: A new edge grows in between two existing nodes.remove: Remove nodes (with their edges) or edges given as(u, v): they shrink away.relayout: Moves the nodes to a new layout as a transition (another named layout, positions, or the current one again after changes); edges follow their nodes.path: Highlights a path: its nodes and the edges between them takecolorone after the other (the accent color by default), for searches and shortest paths.
Inherited from k.Group: children, to, swap, insert, pop, fit.
Inherited from k.Node: set, unbind, edge, age, entered, exited, copy, place, to_place, unpin.
k.Graph.node (method)
graph.node(name: NodeName) -> GraphNode
The node called name (.circle, .label).
Parameters:
| Name | Type | Default | Description |
|---|---|---|---|
name |
NodeName |
required | The node called name (.circle, .label). |
k.Graph.edge_between (method)
graph.edge_between(u: NodeName, v: NodeName) -> GraphEdge
The edge between u and v (.line, .label); either order for undirected graphs.
Parameters:
| Name | Type | Default | Description |
|---|---|---|---|
u |
NodeName |
required | The edge between u and v (.line, .label); either order for undirected graphs. |
v |
NodeName |
required | The edge between u and v (.line, .label); either order for undirected graphs. |
k.Graph.nodes (property)
graph.nodes: list[GraphNode] # read-only
The nodes, in the order they were added.
k.Graph.edges (property)
graph.edges: list[GraphEdge] # read-only
The edges, in the order they were added.
k.Graph.add_node (method)
graph.add_node(
name: NodeName,
*,
edges: Sequence[EdgeSpec] = (),
at: Position | None = None,
**kw: Unpack[ReorderTiming],
) -> Animation
A new node and its edges= grow in; without at= the graph is laid out again with it and the other nodes move to make room. g.add_edge(u, v, weight) adds an edge and g.remove(name, (u, v)) shrinks nodes (with their edges) and edges away.
Parameters:
| Name | Type | Default | Description |
|---|---|---|---|
name |
NodeName |
required | |
edges |
Sequence[EdgeSpec] |
() |
A new node and its edges= grow in; without at= the graph is laid out again with it and the other nodes move to make room. |
at |
Position | None |
None |
A new node and its edges= grow in; without at= the graph is laid out again with it and the other nodes move to make room. |
**kw |
Unpack[ReorderTiming] |
variadic | Keyword arguments (ReorderTiming): duration: float | None, ease: EaseLike | None, path: SwapPath. |
Example:
@k.scene
def grow_tree(s: k.Scene):
g = k.Graph(["a", "b", "c"], [("a", "b"), ("a", "c")], layout="tree", width=7, height=4)
s.play(k.draw(g))
s.play(g.add_node("d", edges=[("c", "d")]))
s.play(g.add_edge("b", "d"))
s.play(g.remove("b"))
See also: k.Graph, graph.relayout.
k.Graph.add_edge (method)
graph.add_edge(
u: NodeName,
v: NodeName,
weight: object = None,
**kw: Unpack[ReorderTiming],
) -> Animation
A new edge grows in between two existing nodes.
Parameters:
| Name | Type | Default | Description |
|---|---|---|---|
u |
NodeName |
required | |
v |
NodeName |
required | |
weight |
object |
None |
|
**kw |
Unpack[ReorderTiming] |
variadic | Keyword arguments (ReorderTiming): duration: float | None, ease: EaseLike | None, path: SwapPath. |
k.Graph.remove (method)
graph.remove(
*targets: NodeName | tuple[NodeName, NodeName],
**kw: Unpack[ReorderTiming],
) -> Animation
Remove nodes (with their edges) or edges given as (u, v): they shrink away.
Parameters:
| Name | Type | Default | Description |
|---|---|---|---|
*targets |
NodeName | tuple[NodeName, NodeName] |
variadic | |
**kw |
Unpack[ReorderTiming] |
variadic | Keyword arguments (ReorderTiming): duration: float | None, ease: EaseLike | None, path: SwapPath. |
k.Graph.relayout (method)
graph.relayout(
layout: GraphLayout | None = None,
**kw: Unpack[ReorderTiming],
) -> Animation
Moves the nodes to a new layout as a transition (another named layout, positions, or the current one again after changes); edges follow their nodes.
Parameters:
| Name | Type | Default | Description |
|---|---|---|---|
layout |
GraphLayout | None |
None |
|
**kw |
Unpack[ReorderTiming] |
variadic | Keyword arguments (ReorderTiming): duration: float | None, ease: EaseLike | None, path: SwapPath. |
Example:
@k.scene
def relayout(s: k.Scene):
g = k.Graph(list("abcdef"), [("a", "b"), ("b", "c"), ("c", "d"), ("d", "e"), ("e", "f"), ("f", "a")], layout="force", width=6, height=4)
s.play(k.draw(g))
s.play(g.relayout("circle"), duration=1.5)
See also: k.Graph, graph.path.
k.Graph.path (method)
graph.path(
names: Sequence[NodeName],
*,
color: ColorLike | None = None,
lag: float = 0.15,
duration: float | None = None,
) -> Animation
Highlights a path: its nodes and the edges between them take color one after the other (the accent color by default), for searches and shortest paths.
Parameters:
| Name | Type | Default | Description |
|---|---|---|---|
names |
Sequence[NodeName] |
required | |
color |
ColorLike | None |
None |
Highlights a path: its nodes and the edges between them take color one after the other (the accent color by default), for searches and shortest paths. |
lag |
float |
0.15 |
|
duration |
float | None |
None |
Example:
@k.scene
def network(s: k.Scene):
layers = [["x1", "x2"], ["h1", "h2", "h3"], ["y"]]
edges = [(a, b) for left, right in zip(layers, layers[1:]) for a in left for b in right]
net = k.Graph([n for layer in layers for n in layer], edges, layout="layered", directed=True, width=7, height=4)
s.play(k.draw(net))
s.play(net.path(["x1", "h2", "y"]))
See also: k.Graph, graph.add_node.
k.Matrix (class)#
k.Matrix(
entries: Sequence[Sequence[Entry]],
*,
brackets: Brackets = "[",
size: float = 0.5,
column_gap: float | None = None,
row_gap: float | None = None,
**props: Unpack[TransformKeywords],
)
A matrix whose entries are objects in a grid: numbers, TeX strings (typeset with k.Math) or any object, between brackets= ("[", "(", "|", "none"). m[i, j] is an entry, m.row(i) / m.column(j) list them, m.box(row=i) frames a row to draw, and a @ b is the product of numeric matrices (a new matrix).
Parameters:
| Name | Type | Default | Description |
|---|---|---|---|
entries |
Sequence[Sequence[Entry]] |
required | |
brackets |
Brackets |
"[" |
A matrix whose entries are objects in a grid: numbers, TeX strings (typeset with k.Math) or any object, between brackets= ("[", "(", "|", "none"). |
size |
float |
0.5 |
|
column_gap |
float | None |
None |
|
row_gap |
float | None |
None |
|
**props |
Unpack[TransformKeywords] |
variadic | Keyword arguments (TransformKeywords): name: str | None, key: str | None, x: FloatVal, y: FloatVal, position: VecVal, rotate: FloatVal, anchor: VecVal, z: FloatVal, scale: FloatVal, scale_x: FloatVal, scale_y: FloatVal, opacity: FloatVal, visible: BoolVal, bleed: BoolVal, emphasis: Emphasis. |
Props inherited from k.Node: x, y, rotate, scale, scale_x, scale_y, anchor, opacity, z, visible, bleed, emphasis.
Example:
@k.scene
def grid(s: k.Scene):
m = k.Matrix([[1, 2], [3, 4]]).place(at="center")
s.play(k.fade_in(m))
s.play(k.draw(m.box(column=1)))
s.play(m[1, 0].to(color=k.YELLOW))
See also: k.matrix_product, k.Math.
Members:
shape: (rows, columns).row: The entries of rowindex.column: The entries of columnindex.box: A rounded frame around a row or a column (in the matrix: it moves with it), not yet in the scene: draw it (k.draw(m.box(row=0))).
Inherited from k.Group: children, to, swap, insert, pop, fit.
Inherited from k.Node: set, unbind, edge, age, entered, exited, copy, place, to_place, unpin.
k.Matrix.shape (property)
matrix.shape: tuple[int, int] # read-only
(rows, columns).
k.Matrix.row (method)
matrix.row(index: int) -> list[Node]
The entries of row index.
Parameters:
| Name | Type | Default | Description |
|---|---|---|---|
index |
int |
required | The entries of row index. |
k.Matrix.column (method)
matrix.column(index: int) -> list[Node]
The entries of column index.
Parameters:
| Name | Type | Default | Description |
|---|---|---|---|
index |
int |
required | The entries of column index. |
k.Matrix.box (method)
matrix.box(
*,
row: int | None = None,
column: int | None = None,
color: ColorLike | None = None,
) -> RoundedRect
A rounded frame around a row or a column (in the matrix: it moves with it), not yet in the scene: draw it (k.draw(m.box(row=0))).
Parameters:
| Name | Type | Default | Description |
|---|---|---|---|
row |
int | None |
None |
A rounded frame around a row or a column (in the matrix: it moves with it), not yet in the scene: draw it (k.draw(m.box(row=0))). |
column |
int | None |
None |
|
color |
ColorLike | None |
None |
k.matrix_product (function)#
k.matrix_product(
a: Matrix,
b: Matrix,
product: Matrix,
*,
step: float = 0.8,
) -> Animation
Shows a product row by column: k.matrix_product(a, b, a @ b) draws the product's brackets, then for each entry indicates its row of a and its column of b while the entry appears (step= seconds each).
Parameters:
| Name | Type | Default | Description |
|---|---|---|---|
a |
Matrix |
required | Shows a product row by column: k.matrix_product(a, b, a @ b) draws the product's brackets, then for each entry indicates its row of a and its column of b while the entry appears (step= seconds each). |
b |
Matrix |
required | Shows a product row by column: k.matrix_product(a, b, a @ b) draws the product's brackets, then for each entry indicates its row of a and its column of b while the entry appears (step= seconds each). |
product |
Matrix |
required | Show product (from a @ b) cell by cell: for each entry, its row of a and its column of b are indicated while the entry appears. |
step |
float |
0.8 |
Shows a product row by column: k.matrix_product(a, b, a @ b) draws the product's brackets, then for each entry indicates its row of a and its column of b while the entry appears (step= seconds each). |
Example:
@k.scene
def product(s: k.Scene):
a = k.Matrix([[1, 2], [3, 4]]).place(at=(-3.5, 0))
b = k.Matrix([[5, 6], [7, 8]]).place(at=(-0.5, 0))
c = (a @ b).place(at=(3, 0))
s.play(k.fade_in(a, b))
s.play(k.matrix_product(a, b, c, step=0.6))
See also: k.Matrix.
k.Bits (class)#
k.Bits(
value: int = 0,
width: int = 8,
*,
signed: bool = False,
place_values: bool = False,
group: int | None = None,
fields: Mapping[str, tuple[int, int]] | None = None,
size: float = 0.5,
color: ColorLike | None = None,
**props: Unpack[TransformKeywords],
)
A binary register: the bits of a value, most significant first, lit when 1. bits.to(value=n) flips the cells that change, from the least significant up. signed=True (two's complement), place_values=True (128 64 … 1 above), group=4 (a gap every 4 bits) and fields={"sign": (0, 1), ...} (labelled ranges of cells). bits.bit(0) is the least significant cell (.box, .digit).
Parameters:
| Name | Type | Default | Description |
|---|---|---|---|
value |
int |
0 |
bits.to(value=n) flips the cells that change, from the least significant up. |
width |
int |
8 |
k.Bits(13, width=8): the bits of a value, most significant first. |
signed |
bool |
False |
signed=True (two's complement), place_values=True (128 64 … 1 above), group=4 (a gap every 4 bits) and fields={"sign": (0, 1), ...} (labelled ranges of cells). |
place_values |
bool |
False |
signed=True (two's complement), place_values=True (128 64 … 1 above), group=4 (a gap every 4 bits) and fields={"sign": (0, 1), ...} (labelled ranges of cells). |
group |
int | None |
None |
signed=True (two's complement), place_values=True (128 64 … 1 above), group=4 (a gap every 4 bits) and fields={"sign": (0, 1), ...} (labelled ranges of cells). |
fields |
Mapping[str, tuple[int, int]] | None |
None |
signed=True (two's complement), place_values=True (128 64 … 1 above), group=4 (a gap every 4 bits) and fields={"sign": (0, 1), ...} (labelled ranges of cells). |
size |
float |
0.5 |
|
color |
ColorLike | None |
None |
|
**props |
Unpack[TransformKeywords] |
variadic | Keyword arguments (TransformKeywords): name: str | None, key: str | None, x: FloatVal, y: FloatVal, position: VecVal, rotate: FloatVal, anchor: VecVal, z: FloatVal, scale: FloatVal, scale_x: FloatVal, scale_y: FloatVal, opacity: FloatVal, visible: BoolVal, bleed: BoolVal, emphasis: Emphasis. |
Props inherited from k.Node: x, y, rotate, scale, scale_x, scale_y, anchor, opacity, z, visible, bleed, emphasis.
Example:
@k.scene
def counting(s: k.Scene):
reg = k.Bits(13, width=8, place_values=True, group=4).place(at="center")
s.play(k.fade_in(reg))
s.play(reg.to(value=14))
s.play(k.indicate(reg.bit(0)))
See also: k.Array.
Members:
value: The value shown (after the changes scheduled so far).bit: The cell of bitindex, 0 being the least significant.to: Change the value: the cells whose bit changes flip (digit and fill), from the least significant up,lagseconds apart.
Inherited from k.Group: children, swap, insert, pop, fit.
Inherited from k.Node: set, unbind, edge, age, entered, exited, copy, place, to_place, unpin.
k.Bits.value (property)
bits.value: int # read-only
The value shown (after the changes scheduled so far).
k.Bits.bit (method)
bits.bit(index: int) -> BitCell
The cell of bit index, 0 being the least significant.
Parameters:
| Name | Type | Default | Description |
|---|---|---|---|
index |
int |
required | The cell of bit index, 0 being the least significant. |
k.Bits.to (method)
bits.to(*, value: int, lag: float = 0.04, duration: float | None = None) -> Animation
Change the value: the cells whose bit changes flip (digit and fill), from the least significant up, lag seconds apart.
Parameters:
| Name | Type | Default | Description |
|---|---|---|---|
value |
int |
required | |
lag |
float |
0.04 |
Change the value: the cells whose bit changes flip (digit and fill), from the least significant up, lag seconds apart. |
duration |
float | None |
None |
k.TitleCard (class)#
k.TitleCard(
title: str,
*,
kicker: str | None = None,
subtitle: str | None = None,
accent: ColorLike | None = None,
size: float = 0.9,
**props: Unpack[TransformKeywords],
)
An episode's opening card: the title, a kicker= above it, an accent rule under it and a subtitle=. k.draw(card) fades the kicker in and writes the title, draws the rule, then shows the subtitle. Parts: card.kicker, card.title, card.rule, card.subtitle.
Parameters:
| Name | Type | Default | Description |
|---|---|---|---|
title |
str |
required | |
kicker |
str | None |
None |
An episode's opening card: the title, a kicker= above it, an accent rule under it and a subtitle=. |
subtitle |
str | None |
None |
An episode's opening card: the title, a kicker= above it, an accent rule under it and a subtitle=. |
accent |
ColorLike | None |
None |
|
size |
float |
0.9 |
|
**props |
Unpack[TransformKeywords] |
variadic | Keyword arguments (TransformKeywords): name: str | None, key: str | None, x: FloatVal, y: FloatVal, position: VecVal, rotate: FloatVal, anchor: VecVal, z: FloatVal, scale: FloatVal, scale_x: FloatVal, scale_y: FloatVal, opacity: FloatVal, visible: BoolVal, bleed: BoolVal, emphasis: Emphasis. |
Props inherited from k.Node: x, y, rotate, scale, scale_x, scale_y, anchor, opacity, z, visible, bleed, emphasis.
Example:
@k.scene
def opening(s: k.Scene):
card = k.TitleCard("How a Computer Adds", kicker="EPISODE 2", subtitle="How computers do math").place(at="center")
s.play(k.draw(card))
s.wait(1)
See also: k.EndCard, k.LowerThird.
Members:
enter: method.
Inherited from k.Group: children, to, swap, insert, pop, fit.
Inherited from k.Node: set, unbind, edge, age, entered, exited, copy, place, to_place, unpin.
k.TitleCard.enter (method)
titlecard.enter() -> Animation
k.EndCard (class)#
k.EndCard(
next_title: str | None = None,
*,
heading: str = "Next",
brand: str | None = None,
series: str | None = None,
invite: str | None = None,
accent: ColorLike | None = None,
size: float = 0.7,
**props: Unpack[TransformKeywords],
)
What comes next: heading= ("Next") over the next title, then brand=, series= and an invite=. k.draw(card) writes the heading and the title, then fades the rest in. Parts: card.heading, card.next, card.brand, card.series, card.invite.
Parameters:
| Name | Type | Default | Description |
|---|---|---|---|
next_title |
str | None |
None |
|
heading |
str |
"Next" |
What comes next: heading= ("Next") over the next title, then brand=, series= and an invite=. |
brand |
str | None |
None |
What comes next: heading= ("Next") over the next title, then brand=, series= and an invite=. |
series |
str | None |
None |
What comes next: heading= ("Next") over the next title, then brand=, series= and an invite=. |
invite |
str | None |
None |
What comes next: heading= ("Next") over the next title, then brand=, series= and an invite=. |
accent |
ColorLike | None |
None |
|
size |
float |
0.7 |
|
**props |
Unpack[TransformKeywords] |
variadic | Keyword arguments (TransformKeywords): name: str | None, key: str | None, x: FloatVal, y: FloatVal, position: VecVal, rotate: FloatVal, anchor: VecVal, z: FloatVal, scale: FloatVal, scale_x: FloatVal, scale_y: FloatVal, opacity: FloatVal, visible: BoolVal, bleed: BoolVal, emphasis: Emphasis. |
Props inherited from k.Node: x, y, rotate, scale, scale_x, scale_y, anchor, opacity, z, visible, bleed, emphasis.
Example:
@k.scene
def closing(s: k.Scene):
card = k.EndCard("Floating Point, Unmasked", brand="Until It Clicks", series="How computers do math").place(at="center")
s.play(k.draw(card))
s.play(k.indicate(card.heading, scale=1.05))
See also: k.TitleCard.
Members:
enter: method.
Inherited from k.Group: children, to, swap, insert, pop, fit.
Inherited from k.Node: set, unbind, edge, age, entered, exited, copy, place, to_place, unpin.
k.EndCard.enter (method)
endcard.enter() -> Animation
k.LowerThird (class)#
k.LowerThird(
title: str,
role: str | None = None,
*,
side: LowerThirdSide = "left",
accent: ColorLike | None = None,
size: float = 0.42,
**props: Unpack[TransformKeywords],
)
A name and a role beside an accent bar, for a corner (side="right" mirrors it); place it as usual. k.draw(card) grows the bar, then slides the texts in. Parts: card.bar, card.title, card.role.
Parameters:
| Name | Type | Default | Description |
|---|---|---|---|
title |
str |
required | |
role |
str | None |
None |
k.LowerThird("Ada Lovelace", role="Mathematician"): a name and a role beside an accent bar, for the bottom-left corner (side="right" for the other one; place it as usual). |
side |
LowerThirdSide |
"left" |
A name and a role beside an accent bar, for a corner (side="right" mirrors it); place it as usual. |
accent |
ColorLike | None |
None |
|
size |
float |
0.42 |
|
**props |
Unpack[TransformKeywords] |
variadic | Keyword arguments (TransformKeywords): name: str | None, key: str | None, x: FloatVal, y: FloatVal, position: VecVal, rotate: FloatVal, anchor: VecVal, z: FloatVal, scale: FloatVal, scale_x: FloatVal, scale_y: FloatVal, opacity: FloatVal, visible: BoolVal, bleed: BoolVal, emphasis: Emphasis. |
Props inherited from k.Node: x, y, rotate, scale, scale_x, scale_y, anchor, opacity, z, visible, bleed, emphasis.
Example:
@k.scene
def speaker(s: k.Scene):
who = k.LowerThird("Ada Lovelace", role="Mathematician").place(at="bottom-left", gap=0.6)
s.play(k.draw(who))
s.wait(1)
s.play(k.fade_out(who))
See also: k.TitleCard.
Members:
enter: method.
Inherited from k.Group: children, to, swap, insert, pop, fit.
Inherited from k.Node: set, unbind, edge, age, entered, exited, copy, place, to_place, unpin.
k.LowerThird.enter (method)
lowerthird.enter() -> Animation
k.BrowserWindow (class)#
k.BrowserWindow(
content: Node | None = None,
*,
url: str = "example.com",
w: float = 8.0,
h: float = 5.0,
**props: Unpack[TransformKeywords],
)
Device frames that hold content, styled to the theme: k.BrowserWindow(content, url=, w=, h=) (dots and an address bar), k.Phone(content, w=, h=) and k.Laptop(content, w=). The content sits in the screen, scaled down to fit when it is larger. Parts such as window.page, phone.screen, laptop.base and .content.
Parameters:
| Name | Type | Default | Description |
|---|---|---|---|
content |
Node | None |
None |
|
url |
str |
"example.com" |
Device frames that hold content, styled to the theme: k.BrowserWindow(content, url=, w=, h=) (dots and an address bar), k.Phone(content, w=, h=) and k.Laptop(content, w=). |
w |
float |
8.0 |
Device frames that hold content, styled to the theme: k.BrowserWindow(content, url=, w=, h=) (dots and an address bar), k.Phone(content, w=, h=) and k.Laptop(content, w=). |
h |
float |
5.0 |
Device frames that hold content, styled to the theme: k.BrowserWindow(content, url=, w=, h=) (dots and an address bar), k.Phone(content, w=, h=) and k.Laptop(content, w=). |
**props |
Unpack[TransformKeywords] |
variadic | Keyword arguments (TransformKeywords): name: str | None, key: str | None, x: FloatVal, y: FloatVal, position: VecVal, rotate: FloatVal, anchor: VecVal, z: FloatVal, scale: FloatVal, scale_x: FloatVal, scale_y: FloatVal, opacity: FloatVal, visible: BoolVal, bleed: BoolVal, emphasis: Emphasis. |
Props inherited from k.Node: x, y, rotate, scale, scale_x, scale_y, anchor, opacity, z, visible, bleed, emphasis.
Example:
@k.scene
def screens(s: k.Scene):
page = k.BrowserWindow(k.Text("Docs", size=0.6), url="kinemo.dev/docs", w=6, h=3.6).place(at=(-2.5, 0))
phone = k.Phone(k.Circle(r=0.5, fill=k.GREEN, fill_opacity=1), w=1.8, h=3.6).place(at=(3, 0))
s.play(k.fade_in(page, phone))
See also: k.Terminal, k.Card.
Inherited from k.Group: children, to, swap, insert, pop, fit.
Inherited from k.Node: set, unbind, edge, age, entered, exited, copy, place, to_place, unpin.
k.Laptop (class)#
k.Laptop(
content: Node | None = None,
*,
w: float = 7.0,
**props: Unpack[TransformKeywords],
)
k.Laptop(content, w=7): a laptop screen in its bezel above a keyboard base; the content fills the screen. Parts: laptop.lid, laptop.screen, laptop.base, laptop.content.
Documented together with k.BrowserWindow.
Parameters:
| Name | Type | Default | Description |
|---|---|---|---|
content |
Node | None |
None |
|
w |
float |
7.0 |
k.Laptop(content, w=7): a laptop screen in its bezel above a keyboard base; the content fills the screen. |
**props |
Unpack[TransformKeywords] |
variadic | Keyword arguments (TransformKeywords): name: str | None, key: str | None, x: FloatVal, y: FloatVal, position: VecVal, rotate: FloatVal, anchor: VecVal, z: FloatVal, scale: FloatVal, scale_x: FloatVal, scale_y: FloatVal, opacity: FloatVal, visible: BoolVal, bleed: BoolVal, emphasis: Emphasis. |
Props inherited from k.Node: x, y, rotate, scale, scale_x, scale_y, anchor, opacity, z, visible, bleed, emphasis.
Inherited from k.Group: children, to, swap, insert, pop, fit.
Inherited from k.Node: set, unbind, edge, age, entered, exited, copy, place, to_place, unpin.
k.Phone (class)#
k.Phone(
content: Node | None = None,
*,
w: float = 2.4,
h: float = 5.0,
**props: Unpack[TransformKeywords],
)
k.Phone(content, w=2.4, h=5): a phone body with its screen, a camera pill and a home bar; the content fills the screen. Parts: phone.body, phone.screen, phone.content.
Documented together with k.BrowserWindow.
Parameters:
| Name | Type | Default | Description |
|---|---|---|---|
content |
Node | None |
None |
|
w |
float |
2.4 |
k.Phone(content, w=2.4, h=5): a phone body with its screen, a camera pill and a home bar; the content fills the screen. |
h |
float |
5.0 |
k.Phone(content, w=2.4, h=5): a phone body with its screen, a camera pill and a home bar; the content fills the screen. |
**props |
Unpack[TransformKeywords] |
variadic | Keyword arguments (TransformKeywords): name: str | None, key: str | None, x: FloatVal, y: FloatVal, position: VecVal, rotate: FloatVal, anchor: VecVal, z: FloatVal, scale: FloatVal, scale_x: FloatVal, scale_y: FloatVal, opacity: FloatVal, visible: BoolVal, bleed: BoolVal, emphasis: Emphasis. |
Props inherited from k.Node: x, y, rotate, scale, scale_x, scale_y, anchor, opacity, z, visible, bleed, emphasis.
Inherited from k.Group: children, to, swap, insert, pop, fit.
Inherited from k.Node: set, unbind, edge, age, entered, exited, copy, place, to_place, unpin.
k.Epicycles (class)#
k.Epicycles(
points: Sequence[Any] | None = None,
n: int = 50,
*,
coefficients: Mapping[int, complex] | None = None,
color: ColorLike | None = None,
circle_color: ColorLike | None = None,
**props: Unpack[UnplacedKeywords],
)
The Fourier series of a closed path (points as tuples or complex numbers), as a chain of n rotating circles, largest first, whose tip traces the path; or coefficients= (frequency → complex amplitude) directly. epi.run(turns=1) turns the chain and the curve appears behind the tip. Parts: epi.circles, epi.arms, epi.curve, epi.tip.
Parameters:
| Name | Type | Default | Description |
|---|---|---|---|
points |
Sequence[Any] | None |
None |
k.Epicycles(points, n=50): the Fourier series of the closed path through points (tuples or complex numbers), drawn as a chain of n rotating circles, largest first, whose tip traces the path; or coefficients={1: 1+0j, -1: 0.5j, ...} directly. |
n |
int |
50 |
The Fourier series of a closed path (points as tuples or complex numbers), as a chain of n rotating circles, largest first, whose tip traces the path; or coefficients= (frequency → complex amplitude) directly. |
coefficients |
Mapping[int, complex] | None |
None |
The Fourier series of a closed path (points as tuples or complex numbers), as a chain of n rotating circles, largest first, whose tip traces the path; or coefficients= (frequency → complex amplitude) directly. |
color |
ColorLike | None |
None |
|
circle_color |
ColorLike | None |
None |
|
**props |
Unpack[UnplacedKeywords] |
variadic | Keyword arguments (UnplacedKeywords): name: str | None, key: str | None, rotate: FloatVal, anchor: VecVal, z: FloatVal, scale: FloatVal, scale_x: FloatVal, scale_y: FloatVal, opacity: FloatVal, visible: BoolVal, bleed: BoolVal, emphasis: Emphasis. |
Props (animatable with .to(), settable with .set() or in the constructor):
| Prop | Kind | Default | Interpolation |
|---|---|---|---|
t |
float | 0.0 |
linear |
Props inherited from k.Node: x, y, rotate, scale, scale_x, scale_y, anchor, opacity, z, visible, bleed, emphasis.
Example:
import math
import kinemo as k
SQUARE = [(2 * math.copysign(min(1, abs(math.cos(a)) * 1.5), math.cos(a)), 2 * math.copysign(min(1, abs(math.sin(a)) * 1.5), math.sin(a))) for a in (2 * math.pi * i / 120 for i in range(120))]
@k.scene
def fourier(s: k.Scene):
epi = k.Epicycles(SQUARE, n=20).place(at="center")
s.play(k.draw(epi))
s.play(epi.run(turns=1, duration=4))
Members:
enter:k.draw(epi): the circles and arms are drawn, the tip appears (the curve waits forrun).run: Turn the chainturnstimes at a steady speed (the tip traces the path once per turn;ease=for another speed profile).
Inherited from k.Group: children, to, swap, insert, pop, fit.
Inherited from k.Node: set, unbind, edge, age, entered, exited, copy, place, to_place, unpin.
k.Epicycles.enter (method)
epicycles.enter() -> Animation
k.draw(epi): the circles and arms are drawn, the tip appears (the curve waits for run).
k.Epicycles.run (method)
epicycles.run(
turns: float = 1.0,
*,
duration: float | None = None,
ease: EaseLike | None = None,
) -> Animation
Turn the chain turns times at a steady speed (the tip traces the path once per turn; ease= for another speed profile).
Parameters:
| Name | Type | Default | Description |
|---|---|---|---|
turns |
float |
1.0 |
Turn the chain turns times at a steady speed (the tip traces the path once per turn; ease= for another speed profile). |
duration |
float | None |
None |
|
ease |
EaseLike | None |
None |
Turn the chain turns times at a steady speed (the tip traces the path once per turn; ease= for another speed profile). |
k.Icon (class)#
k.Icon(
icon: str,
*,
size: float = 1.0,
color: ColorLike | None = None,
stroke_width: float = 3.0,
**props: Unpack[TransformKeywords],
)
A built-in icon, drawn with strokes on a square of side size=: "check", "x", "warning", "lightbulb", "gear", "user", "cpu", … (k.ICON_NAMES lists them). color= sets the stroke; icon.to(stroke=...) recolors it. An unknown name is K0105 with the closest names.
Parameters:
| Name | Type | Default | Description |
|---|---|---|---|
icon |
str |
required | |
size |
float |
1.0 |
A built-in icon, drawn with strokes on a square of side size=: "check", "x", "warning", "lightbulb", "gear", "user", "cpu", … (k.ICON_NAMES lists them). |
color |
ColorLike | None |
None |
color= sets the stroke; icon.to(stroke=...) recolors it. |
stroke_width |
float |
3.0 |
stroke and stroke_width are the icon's own props: icon.to(stroke=k.RED) recolors every stroke. |
**props |
Unpack[TransformKeywords] |
variadic | Keyword arguments (TransformKeywords): name: str | None, key: str | None, x: FloatVal, y: FloatVal, position: VecVal, rotate: FloatVal, anchor: VecVal, z: FloatVal, scale: FloatVal, scale_x: FloatVal, scale_y: FloatVal, opacity: FloatVal, visible: BoolVal, bleed: BoolVal, emphasis: Emphasis. |
Props (animatable with .to(), settable with .set() or in the constructor):
| Prop | Kind | Default | Interpolation |
|---|---|---|---|
stroke |
color | theme.fg |
linear |
stroke_width |
float | 3.0 |
linear |
Props inherited from k.Node: x, y, rotate, scale, scale_x, scale_y, anchor, opacity, z, visible, bleed, emphasis.
Example:
@k.scene
def idea(s: k.Scene):
bulb = k.Icon("lightbulb", size=1.5, color=k.YELLOW).place(at="center")
s.play(k.draw(bulb))
s.play(bulb.to(stroke=k.ORANGE))
See also: k.SVG.
Inherited from k.Group: children, to, swap, insert, pop, fit.
Inherited from k.Node: set, unbind, edge, age, entered, exited, copy, place, to_place, unpin.
k.ICON_NAMES (value)#
k.ICON_NAMES: tuple = ('arrow-down', 'arrow-left', 'arrow-right', 'arrow-up', 'bolt', 'book', 'chart', 'check', 'clock', 'cloud', 'cpu', 'database', 'flag', 'gear', 'globe', 'home', 'info', 'lightbulb', 'lock', 'mail', 'minus', 'pause', 'play', 'plus', 'question', 'search', 'star', 'user', 'warning', 'x')
Documented together with k.Icon. A built-in icon, drawn with strokes on a square of side size=: "check", "x", "warning", "lightbulb", "gear", "user", "cpu", … (k.ICON_NAMES lists them). color= sets the stroke; icon.to(stroke=...) recolors it. An unknown name is K0105 with the closest names.
k.Image (class)#
k.Image(
path: str | os.PathLike[str],
width: float | None = None,
height: float | None = None,
**props: Unpack[TransformKeywords],
)
Raster image (PNG or JPEG) drawn by the renderer, centered on its position. Without a size it is 3 units tall; with width= or height= the other side follows the file's aspect ratio (props w and h, animatable). Relative paths start from the folder of the scene file. Accepts scale, rotate and opacity; morphs and layout treat it as its rectangle, and the exported SVG embeds the file.
Parameters:
| Name | Type | Default | Description |
|---|---|---|---|
path |
str | os.PathLike[str] |
required | |
width |
float | None |
None |
Without a size it is 3 units tall; with width= or height= the other side follows the file's aspect ratio (props w and h, animatable). |
height |
float | None |
None |
Without a size it is 3 units tall; with width= or height= the other side follows the file's aspect ratio (props w and h, animatable). |
**props |
Unpack[TransformKeywords] |
variadic | Keyword arguments (TransformKeywords): name: str | None, key: str | None, x: FloatVal, y: FloatVal, position: VecVal, rotate: FloatVal, anchor: VecVal, z: FloatVal, scale: FloatVal, scale_x: FloatVal, scale_y: FloatVal, opacity: FloatVal, visible: BoolVal, bleed: BoolVal, emphasis: Emphasis. |
Props (animatable with .to(), settable with .set() or in the constructor):
| Prop | Kind | Default | Interpolation |
|---|---|---|---|
src |
str | "" |
step_end |
w |
float | 1.0 |
linear |
h |
float | 1.0 |
linear |
Props inherited from k.Node: x, y, rotate, scale, scale_x, scale_y, anchor, opacity, z, visible, bleed, emphasis.
Example:
@k.scene
def image(s: k.Scene):
photo = k.Image("photo.png", height=4)
s.play(k.fade_in(photo), photo.to(scale=0.8, rotate=-5))
Inherited from k.Node: set, to, unbind, edge, age, entered, exited, copy, place, to_place, unpin.
k.SVG (class)#
k.SVG(
source: str | os.PathLike[str],
height: float = 3.0,
**props: Unpack[TransformKeywords],
)
Imports an SVG illustration (a file or inline markup): each shape becomes a k.Path with the SVG's fill, stroke and stroke width, and each <g> becomes a k.Group. The drawing is scaled to be height units tall and centered on the position. Elements with an id are addressable: svg["#motor"] returns that object, which animates like any other; svg.ids lists the ids.
Parameters:
| Name | Type | Default | Description |
|---|---|---|---|
source |
str | os.PathLike[str] |
required | |
height |
float |
3.0 |
The drawing is scaled to be height units tall and centered on the position. |
**props |
Unpack[TransformKeywords] |
variadic | Keyword arguments (TransformKeywords): name: str | None, key: str | None, x: FloatVal, y: FloatVal, position: VecVal, rotate: FloatVal, anchor: VecVal, z: FloatVal, scale: FloatVal, scale_x: FloatVal, scale_y: FloatVal, opacity: FloatVal, visible: BoolVal, bleed: BoolVal, emphasis: Emphasis. |
Props inherited from k.Node: x, y, rotate, scale, scale_x, scale_y, anchor, opacity, z, visible, bleed, emphasis.
Example:
@k.scene
def illustration(s: k.Scene):
machine = k.SVG("motor.svg", height=3)
s.play(k.draw(machine))
s.play(machine["#polia"].to(fill=k.RED), k.indicate(machine["#motor"]))
See also: k.Path, k.Image, k.Group.
Members:
ids: Ids of the addressable elements, in document order.
Inherited from k.Group: children, to, swap, insert, pop, fit.
Inherited from k.Node: set, unbind, edge, age, entered, exited, copy, place, to_place, unpin.
k.SVG.ids (property)
svg.ids: list[str] # read-only
Ids of the addressable elements, in document order.
k.Brace (class)#
k.Brace(
target: Node,
direction: BraceDirection = "down",
label: str | Node | None = None,
gap: FloatVal = 0.1,
*,
depth: FloatVal = 0.25,
color: ColorLike | None = None,
label_gap: float = 0.12,
**props: Unpack[TransformKeywords],
)
Curly brace (}) along one side of an object's box: direction= "down", "up", "left" or "right", gap units away from it, with the tip pointing outward. It is recomputed every frame from the target's layout, so it follows the object when it moves or changes size. label= (text or an object) sits beyond the tip, as brace.label; the brace itself is brace.shape.
Parameters:
| Name | Type | Default | Description |
|---|---|---|---|
target |
Node |
required | |
direction |
BraceDirection |
"down" |
Curly brace (}) along one side of an object's box: direction= "down", "up", "left" or "right", gap units away from it, with the tip pointing outward. |
label |
str | Node | None |
None |
label= (text or an object) sits beyond the tip, as brace.label; the brace itself is brace.shape. |
gap |
FloatVal |
0.1 |
Curly brace (}) along one side of an object's box: direction= "down", "up", "left" or "right", gap units away from it, with the tip pointing outward. |
depth |
FloatVal |
0.25 |
|
color |
ColorLike | None |
None |
|
label_gap |
float |
0.12 |
|
**props |
Unpack[TransformKeywords] |
variadic | Keyword arguments (TransformKeywords): name: str | None, key: str | None, x: FloatVal, y: FloatVal, position: VecVal, rotate: FloatVal, anchor: VecVal, z: FloatVal, scale: FloatVal, scale_x: FloatVal, scale_y: FloatVal, opacity: FloatVal, visible: BoolVal, bleed: BoolVal, emphasis: Emphasis. |
Props inherited from k.Node: x, y, rotate, scale, scale_x, scale_y, anchor, opacity, z, visible, bleed, emphasis.
Example:
@k.scene
def brace(s: k.Scene):
bar = k.Rect(w=3, h=0.6, fill=k.BLUE, fill_opacity=0.8)
s.play(k.draw(bar), k.draw(k.Brace(bar, "down", label="width")))
s.play(bar.to(w=6))
Inherited from k.Group: children, to, swap, insert, pop, fit.
Inherited from k.Node: set, unbind, edge, age, entered, exited, copy, place, to_place, unpin.
k.Points (class)#
k.Points(
xy: PointsInput | None = None,
radius: PerPointFloat = 0.02,
color: PerPointColor | None = None,
*,
x: FloatColumn | None = None,
y: FloatColumn | None = None,
**props: Unpack[UnplacedKeywords],
)
Thousands of points in a single object, batch-drawn in the core. xy is a numpy array (n, 2), a list of (x, y) or columns (x=, y=). radius and color accept one value, one per point, or a function of the symbolic point p (p.x, p.y, p.index, p.t), traced and vectorized in Rust. Never create thousands of k.Dot in a loop (W0901).
Parameters:
| Name | Type | Default | Description |
|---|---|---|---|
xy |
PointsInput | None |
None |
xy is a numpy array (n, 2), a list of (x, y) or columns (x=, y=). |
radius |
PerPointFloat |
0.02 |
radius and color accept one value, one per point, or a function of the symbolic point p (p.x, p.y, p.index, p.t), traced and vectorized in Rust. |
color |
PerPointColor | None |
None |
radius and color accept one value, one per point, or a function of the symbolic point p (p.x, p.y, p.index, p.t), traced and vectorized in Rust. |
x |
FloatColumn | None |
None |
xy is a numpy array (n, 2), a list of (x, y) or columns (x=, y=). |
y |
FloatColumn | None |
None |
xy is a numpy array (n, 2), a list of (x, y) or columns (x=, y=). |
**props |
Unpack[UnplacedKeywords] |
variadic | Keyword arguments (UnplacedKeywords): name: str | None, key: str | None, rotate: FloatVal, anchor: VecVal, z: FloatVal, scale: FloatVal, scale_x: FloatVal, scale_y: FloatVal, opacity: FloatVal, visible: BoolVal, bleed: BoolVal, emphasis: Emphasis. |
Props (animatable with .to(), settable with .set() or in the constructor):
| Prop | Kind | Default | Interpolation |
|---|---|---|---|
xy |
points | [] |
pointwise |
radius |
float | 0.02 |
linear |
color |
color | theme.accent |
linear |
Props inherited from k.Node: x, y, rotate, scale, scale_x, scale_y, anchor, opacity, z, visible, bleed, emphasis.
Example:
import numpy as np
import kinemo as k
@k.scene
def cloud(s: k.Scene):
xy = np.random.default_rng(1).uniform((-6, -3), (6, 3), size=(5000, 2))
pts = k.Points(xy, radius=0.03, color=lambda t, p: k.mix(k.BLUE, k.RED, (p.x + 6) / 12))
s.play(k.draw(pts), duration=2)
See also: k.VectorField, k.StreamLines, k.python.
Inherited from k.Node: set, to, unbind, edge, age, entered, exited, copy, place, to_place, unpin.
k.VectorField (class)#
k.VectorField(
fn: FieldFunction,
density: FloatVal = 30,
*,
length: FloatVal = 0.8,
x_range: VecVal | None = None,
y_range: VecVal | None = None,
color: PerPointColor | None = None,
**props: Unpack[FieldKeywords],
)
Arrows of a field fn(x, y) -> (vx, vy) on a grid with density columns across the width of the region (x_range, y_range). Size and color (theme accent → secondary) follow the magnitude; length scales the arrows. fn is traced once and may use k.time.
Parameters:
| Name | Type | Default | Description |
|---|---|---|---|
fn |
FieldFunction |
required | fn is traced once and may use k.time. |
density |
FloatVal |
30 |
Arrows of a field fn(x, y) -> (vx, vy) on a grid with density columns across the width of the region (x_range, y_range). |
length |
FloatVal |
0.8 |
Size and color (theme accent → secondary) follow the magnitude; length scales the arrows. |
x_range |
VecVal | None |
None |
Arrows of a field fn(x, y) -> (vx, vy) on a grid with density columns across the width of the region (x_range, y_range). |
y_range |
VecVal | None |
None |
Arrows of a field fn(x, y) -> (vx, vy) on a grid with density columns across the width of the region (x_range, y_range). |
color |
PerPointColor | None |
None |
Arrow length is length × cell × |v| / max|v|; color mixes color_low → color_high (theme accent → secondary) by the same magnitude, unless color is given (a value or a function of the point). |
**props |
Unpack[FieldKeywords] |
variadic | Keyword arguments (FieldKeywords): name: str | None, key: str | None, x: FloatVal, y: FloatVal, position: VecVal, rotate: FloatVal, anchor: VecVal, z: FloatVal, scale: FloatVal, scale_x: FloatVal, scale_y: FloatVal, opacity: FloatVal, visible: BoolVal, bleed: BoolVal, emphasis: Emphasis, stroke_width: FloatVal, color_low: ColorVal, color_high: ColorVal. |
Props (animatable with .to(), settable with .set() or in the constructor):
| Prop | Kind | Default | Interpolation |
|---|---|---|---|
field |
vec2 | (0.0, 0.0) |
linear |
density |
float | 30.0 |
linear |
length |
float | 0.8 |
linear |
x_range |
vec2 | None |
linear |
y_range |
vec2 | None |
linear |
color |
color | None |
linear |
color_low |
color | theme.accent |
linear |
color_high |
color | theme._secondary |
linear |
stroke_width |
float | 2.5 |
linear |
Props inherited from k.Node: x, y, rotate, scale, scale_x, scale_y, anchor, opacity, z, visible, bleed, emphasis.
Example:
@k.scene
def rotation(s: k.Scene):
field = k.VectorField(lambda x, y: (-y, x), density=24)
s.play(k.draw(field), duration=2)
See also: k.StreamLines, k.Points.
Inherited from k.Node: set, to, unbind, edge, age, entered, exited, copy, place, to_place, unpin.
k.StreamLines (class)#
k.StreamLines(
field: FieldFunction,
seeds: int | PointsInput = 200,
*,
step: FloatVal = 0.05,
steps: FloatVal = 60,
progress: FloatVal = 1.0,
tail: FloatVal = 1.0,
fade: FloatVal = 0.0,
x_range: VecVal | None = None,
y_range: VecVal | None = None,
color: PerPointColor | None = None,
**props: Unpack[FieldKeywords],
)
Streamlines of a field (a k.VectorField or a function), integrated with RK4 in the core from seeds (a count or points). progress draws the lines over time; tail is the visible fraction behind the head and fade the opacity of the tail.
Parameters:
| Name | Type | Default | Description |
|---|---|---|---|
field |
FieldFunction |
required | Lines that follow field (a VectorField, or a function like VectorField's). lines = k.StreamLines(field, seeds=200) s.play(lines.to(progress=1), duration=3) seeds: a count (deterministic Halton points over the region) or the starting points ((n, 2) array or list). |
seeds |
int | PointsInput |
200 |
Streamlines of a field (a k.VectorField or a function), integrated with RK4 in the core from seeds (a count or points). |
step |
FloatVal |
0.05 |
Lines advance step units per RK4 step along the field direction, at most steps steps, and stop at the region border or where the field vanishes. |
steps |
FloatVal |
60 |
Lines advance step units per RK4 step along the field direction, at most steps steps, and stop at the region border or where the field vanishes. |
progress |
FloatVal |
1.0 |
progress draws the lines over time; tail is the visible fraction behind the head and fade the opacity of the tail. |
tail |
FloatVal |
1.0 |
progress draws the lines over time; tail is the visible fraction behind the head and fade the opacity of the tail. |
fade |
FloatVal |
0.0 |
progress draws the lines over time; tail is the visible fraction behind the head and fade the opacity of the tail. |
x_range |
VecVal | None |
None |
|
y_range |
VecVal | None |
None |
|
color |
PerPointColor | None |
None |
Colors mix color_low → color_high by mean magnitude, unless color is given. |
**props |
Unpack[FieldKeywords] |
variadic | Keyword arguments (FieldKeywords): name: str | None, key: str | None, x: FloatVal, y: FloatVal, position: VecVal, rotate: FloatVal, anchor: VecVal, z: FloatVal, scale: FloatVal, scale_x: FloatVal, scale_y: FloatVal, opacity: FloatVal, visible: BoolVal, bleed: BoolVal, emphasis: Emphasis, stroke_width: FloatVal, color_low: ColorVal, color_high: ColorVal. |
Props (animatable with .to(), settable with .set() or in the constructor):
| Prop | Kind | Default | Interpolation |
|---|---|---|---|
field |
vec2 | (0.0, 0.0) |
linear |
seeds |
points | [] |
step_end |
seed_count |
float | 200.0 |
step_end |
step |
float | 0.05 |
linear |
steps |
float | 60.0 |
step_end |
progress |
float | 1.0 |
linear |
tail |
float | 1.0 |
linear |
fade |
float | 0.0 |
linear |
x_range |
vec2 | None |
linear |
y_range |
vec2 | None |
linear |
color |
color | None |
linear |
color_low |
color | theme.accent |
linear |
color_high |
color | theme._secondary |
linear |
stroke_width |
float | 2.0 |
linear |
Props inherited from k.Node: x, y, rotate, scale, scale_x, scale_y, anchor, opacity, z, visible, bleed, emphasis.
Example:
@k.scene
def stream(s: k.Scene):
field = k.VectorField(lambda x, y: (-y, x), density=24)
lines = k.StreamLines(field, seeds=150, progress=0.0, tail=0.5)
s.add(field)
s.play(k.fade_in(lines), lines.to(progress=1), duration=3)
See also: k.VectorField.
Inherited from k.Node: set, to, unbind, edge, age, entered, exited, copy, place, to_place, unpin.