fxparams API Reference
Detailed explanations of the individual API functions related to fxparams
$fx.params()
(array) => void
Define collector-modifiable parameters for your piece by calling this with an array.
$fx.getParam()
(string) => any
Returns the value of a param via its ID.
$fx.getParams()
() => object
Returns a dictionary of all parameter key-value pairs, as currently set.
$fx.getRawParam()
(string) => string
Provides the raw parameter data (as a bytes string) as it was passed to the iteration.
von()
(string, function, function) => function
Registers an event listener and returns a function to deregister it.
$fx.emit()
(string, any) => void
Sends an event to the parent context, useful for dynamic parameter updates from within the code.
$fx.params(definition)
$fx.params(definition)
The $fx.params(definition)
function is necessary to create an fx(params) piece, it takes as input a list of parameters definitions that collectors can modulate and tweak to create their own custom iterations. Parameter definitions are object that contain a number of key/value pairs that describe the parameters.
You can learn more about the speficications for the these parameter definitions here:
Here is an example of this definition array:
Invoking the $fx.params()
function has a number of important effects:
It informs fxhash that the project is an fx(params) project and creates the respective controllers in the UI (if the params are not
code-driven
)It reads the
fxparams
URL parameter, processes the bytes and converts it into values based on the provided definitions and maps them to their respective variables to generate the corresponding artwork.The values of the parameters are stored and made accessible throughout the artist’s code via utility functions.
$fx.params()
must be called before trying to access any parameter value with the parameter fetching functions that follow.
$fx.getParam(id)
$fx.getParam(id)
Returns the value of a parameter based on the params definition provided to $fx.params(definition)
and the input bytes passed to the code via URL parameters (&fxparams={byte_sequence_here}
), the bytes sequence will be processed by $fx.params()
when it is called.
The $fx.getParam(id)
will fetch and return the value of parameter through its id
as defined in your params definition:
Depending on the type of the parameter, the fxhash snippet may apply extra processing to facilitate their usage in your code. For instance, in the case of color parameter, it will be returned in different forms. See the parameter definition specifications section for more details on each parameter type.
$fx.getParams()
$fx.getParams()
Returns an object containing all parameters, where the keys in this object are the individual parameter ids:
$fx.getRawParam(id)
$fx.getRawParam(id)
Given a parameter id, $fx.getRawParam(id)
returns the hexadecimal string byte sequence corresponding to that parameter, before processing and converting it into a value:
$fx.emit(eventId, data)
$fx.emit(eventId, data)
This function is mainly used for the purpose of updating parameters that have their update
mode set to code-driven
. As its name suggests, $fx.emit(eventId, data)
allows you to emit events (think of it like a signal), to an fxhash specific pipeline of events, which can then be listened to by the $fx.on()
function. Currently there is only one type of event that is supported, namely the param:update
signal.
Additionally, this event can also carry a payload which can be specified with the second input parameter of the $fx.emit
function, the data
variable. The data
variable should be an object where the key/value pairs are the parameter ids and the updated associated values respectively. This is still subject to the constraints of the parameter (as set by its parameter definition), so for instance if a number between 0 and 10 is expected and you pass a value of 12, it will clamp to 10. You are not required to pass all the parameters in the data, only those which need to be updated.
Here’s an example, let’s first set up a couple of parameters:
And then send out an event whenever we move the mouse:
Here we used a native Javascript eventlistener to detect whenever the mouse is moved, making it in turn trigger the $fx.emit()
function to update the mouse_x
parameter.
Following is the typescript definition of the $fx.emit
function:
$fx.on(eventId, handler, onDone)
$fx.on(eventId, handler, onDone)
The $fx.on()
function listens to events in the fxhash pipeline that are emitted by $fx.emit()
. Currently there is only one type of event that is supported, namely the param:update
event. $fx.on()
can then trigger functions when this event is registered and certain conditions are met. Note that the eventId
must match an existing eventId
that you can subscribe to.
The handler
is the function that is called when the event is triggered. Additionally you can opt-out of the default behaviour of an event handler by returning false
from the handler. The onDone
function is called as the last thing of any event, e.g. after the default behaviour of the event was applied.
Following is the typescript definition of the $fx.on
function:
The function returned by the $fx.on
function can be called to remove the registered event listener.
Note: there are 2 ways to apply changes to the UI when you emit a parameter from the code:
Last updated