Example | Constructor | Variables | Functions
Two-dimensional slider (trackpad) class.
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;
}
let gui;
let s2d;
function setup() {
createCanvas(400, 400);
gui = createGui();
s2d = createSlider2d("Slider2d", 50, 50);
}
Creates a new GuiSlider2d
object. This is a 2 dimensional slider.
createSlider2d(label, x, y, [w], [h], [minX], [maxX], [maxX], [maxY])
label
String: label for the GuiSlider2dx
Number: x-coordinate of the GuiSlider2dy
Number: y-coordinate of the GuiSlider2dw
Number: width of the GuiSlider2d (default is 256)h
Number: height of the GuiSlider2d (default is 256)minX
Number: lower bound of the value's x range (default value is -1)maxX
Number: upper bound of the value's x range (default value is 1)minY
Number: lower bound of the value's y range (default value is -1)maxY
Number: upper bound of the value's y range (default value is 1)
GuiSlider2d
slider2d.val = {x: 0.5, y: 0.5};
if (slider2d.isChanged) {
print(slider2d.val.x);
print(slider2d.val.y);
}
Value of the GuiSlider2d
returned as object {x: valX, y: valY}
.
slider2d.valX = 0.5;
if (slider2d.isChanged) {
print(slider2d.valX);
}
X value of the GuiSlider2d
.
slider2d.valY = 0.5;
if (slider2d.isChanged) {
print(slider2d.valY);
}
Y value of the GuiSlider2d
.
slider2d.minX = -100;
Lower x bound of the GuiSlider2d
range.
slider2d.maxX = 100;
Upper x bound of the GuiSlider2d
range.
slider2d.minY = -100;
Lower y bound of the GuiSlider2d
range.
slider2d.maxY = 100;
Upper y bound of the GuiSlider2d
range.
slider2d.isInteger = True;
Sets the mode of the GuiSlider2d
so that all values are integers.
slider2d.setStyle("fillBg", color(255, 0, 0));
slider2d.setStyle({
fillBg: color("#FF0000"),
rounding: 10,
handleRadius: 30
});
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.
setStyle(property, value)
setStyle(Object)
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
None
The GuiSlider2d
style properties are:
strokeWeight
Number: the weight (in pixels) of the strokerounding
Number: radius of cornershandleRadius
Number: radius of handle in pixelsfillBg
p5.Color: default background fill colorfillBgHover
p5.Color: hover background fill colorfillBgActive
p5.Color: active background fill colorfillTrack
p5.Color: default track fill colorfillTrackHover
p5.Color: hover track fill colorfillTrackActive
p5.Color: active track fill colorfillHandle
p5.Color: default handle fill colorfillHandleHover
p5.Color: hover handle fill colorfillHandleActive
p5.Color: active handle fill colorstrokeBg
p5.Color: default background stroke colorstrokeBgHover
p5.Color: hover background stroke colorstrokeBgActive
p5.Color: active background stroke colorstrokeTrack
p5.Color: default track stroke colorstrokeTrackHover
p5.Color: hover track stroke colorstrokeTrackActive
p5.Color: active track stroke colorstrokeHandle
p5.Color: default handle stroke colorstrokeHandleHover
p5.Color: hover handle stroke colorstrokeHandleActive
p5.Color: active handle stroke color