GuiCrossfader / GuiCrossfaderV
August 26, 2019 ยท View on GitHub
GuiCrossfader / GuiCrossfaderV
Example | Constructor | Variables | Functions
Description
Crossfader class.
Note: vertical crossfader class is virtually the same, just with a different orientation.

Example
let gui;
// Create a variable for your Crossfader
let c;
function setup() {
createCanvas(400, 400);
gui = createGui();
// Create Crossfader.
// The last two optional arguments define the min and max (minimum and maximum) values.
// The default min and max values are -1 and 1, respectively.
c = createCrossfader("Crossfader", 50, 50, 300, 32, 25, 100);
}
function draw() {
background(72, 61, 139);
drawGui();
if (c.isChanged) {
// Print a message when Crossfader is changed
// that displays its value.
print(c.label + " = " + c.val);
}
// Use Crossfader's value to determine where the ellipse is drawn.
fill(216, 191, 216);
ellipse(100, 300, 125-c.val);
ellipse(300, 300, c.val);
}
/// Add these lines below sketch to prevent scrolling on mobile
function touchMoved() {
// do some stuff
return false;
}
Constructor
createCrossfader()
Example
let gui;
let cf;
function setup() {
createCanvas(400, 400);
gui = createGui();
cf = createCrossfader("Crossfader", 50, 50);
}
Description
Creates a new GuiCrossfader object. This is a horizontal slider with a center point.
Note: For a vertical crossfader, instead use createCrossfaderV().
Syntax
createCrossfader(label, x, y, [w], [h], [min], [max])
Parameters
labelString: label for the GuiCrossfaderxNumber: x-coordinate of the GuiCrossfaderyNumber: y-coordinate of the GuiCrossfaderwNumber: width of the GuiCrossfader (default is 128)hNumber: height of the GuiCrossfader (default is 32)minNumber: lower bound of the value's range (default value is -1)maxNumber: upper bound of the value's range (default value is 1)
Returns
GuiCrossfader
Variables
val
Example
crossfader.val = 0.5;
if (crossfader.isChanged) {
print(crossfader.val);
}
Description
Value of the GuiCrossfader.
min
Example
crossfader.min = -100;
Description
Lower bound of the GuiCrossfader range.
max
Example
crossfader.max = 100;
Description
Upper bound of the GuiCrossfader range.
isInteger
Example
crossfader.isInteger = True;
Description
Sets the mode of the GuiCrossfader so that all values are integers.
Functions
setStyle()
Example
crossfader.setStyle("fillBg", color(255, 0, 0));
crossfader.setStyle({
fillBg: color("#FF0000"),
rounding: 10,
trackWidth: 0.1
});
Description
Individual GuiCrossfader objects can be styled using this method. There are two types of input it takes. Use an input string and value to set an individual property, and use an Object with key/value notation to set multiple properties at once.
Syntax
setStyle(property, value)
setStyle(Object)
Parameters
property String: name of property to be set
value Number|String|Object: value of property to be set
Object Object: multiple propertys and values to be set
Returns
None
Style
The GuiCrossfader style properties are:
strokeWeightNumber: the weight (in pixels) of the strokeroundingNumber: radius of cornerstrackWidthNumber: width of all crossfader tracks between 0 (line) and 1 (full)fillBgp5.Color: default background fill colorfillBgHoverp5.Color: hover background fill colorfillBgActivep5.Color: active background fill colorfillTrackp5.Color: default track fill colorfillTrackHoverp5.Color: hover track fill colorfillTrackActivep5.Color: active track fill colorfillHandlep5.Color: default handle fill colorfillHandleHoverp5.Color: hover handle fill colorfillHandleActivep5.Color: active handle fill colorstrokeBgp5.Color: default background stroke colorstrokeBgHoverp5.Color: hover background stroke colorstrokeBgActivep5.Color: active background stroke colorstrokeTrackp5.Color: default track stroke colorstrokeTrackHoverp5.Color: hover track stroke colorstrokeTrackActivep5.Color: active track stroke colorstrokeHandlep5.Color: default handle stroke colorstrokeHandleHoverp5.Color: hover handle stroke colorstrokeHandleActivep5.Color: active handle stroke colorstrokeCenterp5.Color: default center line stroke colorstrokeCenterHoverp5.Color: hover center line stroke colorstrokeCenterActivep5.Color: active center line stroke color