GuiSlider2d
August 26, 2019 ยท View on GitHub
GuiSlider2d
Example | Constructor | Variables | Functions
Description
Two-dimensional slider (trackpad) class.

Example
let gui;
// Create a variable for your Slider2d
let s;
function setup() {
createCanvas(400, 400);
gui = createGui();
// Create Slider2d.
// The last four optional arguments define minimum and maximum values
// for the x and y axes; minX, maxX, minY, maxY
// The default min and max values for all four are -1 and 1.
s = createSlider2d("Slider2d", 10, 210, 175, 175, 250, 350, 150, 50);
}
function draw() {
background(255, 235, 205);
drawGui();
if (s.isChanged) {
// Print a message when Slider2d is changed
// that displays its value.
print(s.label + " = {" + s.valX + ", " + s.valY + "}");
}
// Draw our ellipse using the Slider2d output values
fill( 95, 158, 160);
ellipse(s.valX, s.valY, 100);
}
/// Add these lines below sketch to prevent scrolling on mobile
function touchMoved() {
// do some stuff
return false;
}
Constructor
createSlider2d()
Example
let gui;
let s2d;
function setup() {
createCanvas(400, 400);
gui = createGui();
s2d = createSlider2d("Slider2d", 50, 50);
}
Description
Creates a new GuiSlider2d object. This is a 2 dimensional slider.
Syntax
createSlider2d(label, x, y, [w], [h], [minX], [maxX], [maxX], [maxY])
Parameters
labelString: label for the GuiSlider2dxNumber: x-coordinate of the GuiSlider2dyNumber: y-coordinate of the GuiSlider2dwNumber: width of the GuiSlider2d (default is 256)hNumber: height of the GuiSlider2d (default is 256)minXNumber: lower bound of the value's x range (default value is -1)maxXNumber: upper bound of the value's x range (default value is 1)minYNumber: lower bound of the value's y range (default value is -1)maxYNumber: upper bound of the value's y range (default value is 1)
Returns
GuiSlider2d
Variables
val
Example
slider2d.val = {x: 0.5, y: 0.5};
if (slider2d.isChanged) {
print(slider2d.val.x);
print(slider2d.val.y);
}
Description
Value of the GuiSlider2d returned as object {x: valX, y: valY}.
valX
Example
slider2d.valX = 0.5;
if (slider2d.isChanged) {
print(slider2d.valX);
}
Description
X value of the GuiSlider2d.
valY
Example
slider2d.valY = 0.5;
if (slider2d.isChanged) {
print(slider2d.valY);
}
Description
Y value of the GuiSlider2d.
minX
Example
slider2d.minX = -100;
Description
Lower x bound of the GuiSlider2d range.
maxX
Example
slider2d.maxX = 100;
Description
Upper x bound of the GuiSlider2d range.
minY
Example
slider2d.minY = -100;
Description
Lower y bound of the GuiSlider2d range.
maxY
Example
slider2d.maxY = 100;
Description
Upper y bound of the GuiSlider2d range.
isInteger
Example
slider2d.isInteger = True;
Description
Sets the mode of the GuiSlider2d so that all values are integers.
Functions
setStyle()
Example
slider2d.setStyle("fillBg", color(255, 0, 0));
slider2d.setStyle({
fillBg: color("#FF0000"),
rounding: 10,
handleRadius: 30
});
Description
Individual GuiSlider2d 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 GuiSlider2d style properties are:
strokeWeightNumber: the weight (in pixels) of the strokeroundingNumber: radius of cornershandleRadiusNumber: radius of handle in pixelsfillBgp5.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 color