跳转到内容
查看源码

上下文函数(context)自动生成

读取当前元素与外部世界:坐标、定义域、时间、指针、按键、窗口等。

返回 函数 需要能力
Bool button (n: Int) input.read
Double clock () time.read
Vec2 coord () +1 —
Int domain () +2 —
Int element () —
IVec2 icoord () +1 —
Int idomain () +2 —
Int index () —
Bool key (code: Int) input.read
Int pads () input.read
Vec2 pointer () input.read
Bool pointer_down () input.read
Int queued () time.read
Float rate () time.read
Float scale () input.read
Vec2 stick (n: Int) input.read
Float time () time.read
Int typed (k: Int) input.read
Vec2 wheel () input.read
Vec2 window () input.read
button(n: Int) -> Bool

Whether button n is held: 0 left, 1 right, 2 middle of a pointer; a pad’s from 8 (south, east, west, north, shoulders, thumbs, start, select).

需要能力: input.read


clock() -> Double

The session’s time in seconds, whole: the same clock as time(), exact for years. Its Kernel runs where Doubles run.

需要能力: time.read


coord() -> Vec2
coord() -> Vec3

This element’s column and row (and layer) over a grid or a volume, whole numbers from 0 with row 0 at the top; the element’s center is coord() + 0.5. Rows have element().

只能在 Kernel 主体中调用


domain() -> Int
domain() -> Vec2
domain() -> Vec3

The output’s extent in its shape.

只能在 Kernel 主体中调用


element() -> Int

This element’s index over rows; a scan’s step.

只能在 Kernel 主体中调用


icoord() -> IVec2
icoord() -> IVec3

This element’s coordinates as integers, for arithmetic on cells.

只能在 Kernel 主体中调用


idomain() -> Int
idomain() -> IVec2
idomain() -> IVec3

The output’s extent as integers.

只能在 Kernel 主体中调用


index() -> Int

The iteration of the innermost loop, or a scan’s step outside every loop.


key(code: Int) -> Bool

Whether the key with this code is held, the browser’s codes: letters and digits by uppercase ASCII; backspace 8, tab 9, enter 13, shift 16, control 17, alt 18, escape 27, space 32, page up 33, page down 34, end 35, home 36, arrows 37 to 40 (left, up, right, down), delete 46, command or windows 91; ; 186, = 187, , 188, - 189, . 190, / 191, ` 192, [ 219, \ 220, ] 221, ’ 222. A character typed with shift is the key under it on a US keyboard: ( is 57, : is 186.

需要能力: input.read


pads() -> Int

How many pads are connected: a player shows a pad’s prompts while one is, whether or not it has been touched.

需要能力: input.read


pointer() -> Vec2

The pointer in the output’s pixels from its top left; a player maps its window’s into them.

需要能力: input.read


pointer_down() -> Bool

Whether the left button is held.

需要能力: input.read


queued() -> Int

The samples (per channel) the sound device holds and has not yet played, zero without one: a sound made to the time can keep the device this far ahead.

需要能力: time.read


rate() -> Float

The sound device’s samples per second, zero without one.

需要能力: time.read


scale() -> Float

The window’s physical pixels per logical pixel, one without a window.

需要能力: input.read


stick(n: Int) -> Vec2

A pad’s axis pair: 0 the left stick, 1 the right, 2 the two triggers (x left, y right). Sticks run -1 to 1 with y away from the person, triggers 0 to 1; all zero without a pad.

需要能力: input.read


time() -> Float

The session’s time in seconds, rounded to a Float: finer than a millisecond for the first hours, a quarter second after a month. A session meant to run long times with clock().

需要能力: time.read


typed(k: Int) -> Int

The kth character typed since the last evaluation, as a Unicode code point, 0 after the last: what the keyboard or an input method commits, Chinese as well as ASCII, 32 at most an evaluation (those past them wait for the next). key() tells which keys are held; typed() what they wrote.

需要能力: input.read


wheel() -> Vec2

What the wheel scrolled since the last evaluation, in lines: x sideways, y positive away.

需要能力: input.read


window() -> Vec2

The window’s size in physical pixels, zero by zero without one; a node’s domain may take it.

需要能力: input.read