上下文函数(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
Section titled “button”button(n: Int) -> BoolWhether 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() -> DoubleThe session’s time in seconds, whole: the same clock as time(), exact for years. Its Kernel runs where Doubles run.
需要能力: time.read
coord() -> Vec2coord() -> Vec3This 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
Section titled “domain”domain() -> Intdomain() -> Vec2domain() -> Vec3The output’s extent in its shape.
只能在 Kernel 主体中调用
element
Section titled “element”element() -> IntThis element’s index over rows; a scan’s step.
只能在 Kernel 主体中调用
icoord
Section titled “icoord”icoord() -> IVec2icoord() -> IVec3This element’s coordinates as integers, for arithmetic on cells.
只能在 Kernel 主体中调用
idomain
Section titled “idomain”idomain() -> Intidomain() -> IVec2idomain() -> IVec3The output’s extent as integers.
只能在 Kernel 主体中调用
index() -> IntThe iteration of the innermost loop, or a scan’s step outside every loop.
key(code: Int) -> BoolWhether 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() -> IntHow many pads are connected: a player shows a pad’s prompts while one is, whether or not it has been touched.
需要能力: input.read
pointer
Section titled “pointer”pointer() -> Vec2The pointer in the output’s pixels from its top left; a player maps its window’s into them.
需要能力: input.read
pointer_down
Section titled “pointer_down”pointer_down() -> BoolWhether the left button is held.
需要能力: input.read
queued
Section titled “queued”queued() -> IntThe 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() -> FloatThe sound device’s samples per second, zero without one.
需要能力: time.read
scale() -> FloatThe window’s physical pixels per logical pixel, one without a window.
需要能力: input.read
stick(n: Int) -> Vec2A 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() -> FloatThe 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) -> IntThe 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() -> Vec2What the wheel scrolled since the last evaluation, in lines: x sideways, y positive away.
需要能力: input.read
window
Section titled “window”window() -> Vec2The window’s size in physical pixels, zero by zero without one; a node’s domain may take it.
需要能力: input.read

