p5.touchgui has a collection of core library functions that enable you to create and draw your GUI (Graphical User Interface) as well as various buttons. These can each be called from within your p5.js sketch similary to p5.js's built-in functions (e.g. createCanvas()
).
- createGui()
- drawGui()
- createButton()
- createToggle()
- createCheckbox()
- createSlider()
- createSliderV()
- createCrossfader()
- createCrossfaderV()
- createSlider2d()
- createJoystick()
let gui;
function setup() {
createCanvas(400, 400);
gui = createGui();
}
Creates a new Gui
object, which retains and computes all of the information regarding your GUI, including style, user input, and object states. This should be called from within your sketch's setup()
function.
createGui()
None
Gui
draw() {
background(200);
drawGui();
}
Draws all of the objects in your Gui
. This should be called in your draw()
loop.
drawGui()
None
None
let gui;
let b;
function setup() {
createCanvas(400, 400);
gui = createGui();
b = createButton("Button", 50, 50);
}
Creates a new GuiButton
object. This is a momentary button.
createButton(label, x, y, [w], [h])
label
String: label for the GuiButtonx
Number: x-coordinate of the GuiButtony
Number: y-coordinate of the GuiButtonw
Number: width of the GuiButton (default is 128)h
Number: height of the GuiButton (default is 32)
GuiButton
let gui;
let t;
function setup() {
createCanvas(400, 400);
gui = createGui();
t = createToggle("Toggle", 50, 50);
}
Creates a new GuiToggle
object. This is a toggle button.
createToggle(label, x, y, [w], [h], [defaultVal])
label
String: label for the GuiTogglex
Number: x-coordinate of the GuiToggley
Number: y-coordinate of the GuiTogglew
Number: width of the GuiToggle (default is 128)h
Number: height of the GuiToggle (default is 32)defaultVal
Number: default value for your GuiToggle (default isfalse
)
GuiToggle
let gui;
let cb;
function setup() {
createCanvas(400, 400);
gui = createGui();
cb = createCheckbox("Checkbox", 50, 50);
}
Creates a new GuiCheckbox
object. This is a checkbox which functions like a toggle button.
createCheckbox(label, x, y, [w], [h], [defaultVal])
label
String: label for the GuiCheckboxx
Number: x-coordinate of the GuiCheckboxy
Number: y-coordinate of the GuiCheckboxw
Number: width of the GuiCheckbox (default is 32)h
Number: height of the GuiCheckbox (default is 32)defaultVal
Number: default value for your GuiCheckbox (default isfalse
)
GuiCheckbox
let gui;
let s;
function setup() {
createCanvas(400, 400);
gui = createGui();
s = createSlider("Slider", 50, 50);
}
Creates a new GuiSlider
object. This is a horizontal slider.
createSlider(label, x, y, [w], [h], [min], [max])
label
String: label for the GuiSliderx
Number: x-coordinate of the GuiSlidery
Number: y-coordinate of the GuiSliderw
Number: width of the GuiSlider (default is 128)h
Number: height of the GuiSlider (default is 32)min
Number: lower bound of the value's range (default value is 0)max
Number: upper bound of the value's range (default value is 1)
GuiSlider
let gui;
let s;
function setup() {
createCanvas(400, 400);
gui = createGui();
s = createSliderV("SliderV", 50, 50);
}
Creates a new GuiSliderV
object. This is a vertical slider.
createSliderV(label, x, y, [w], [h], [min], [max])
label
String: label for the GuiSliderVx
Number: x-coordinate of the GuiSliderVy
Number: y-coordinate of the GuiSliderVw
Number: width of the GuiSliderV (default is 32)h
Number: height of the GuiSliderV (default is 128)min
Number: lower bound of the value's range (default value is 0)max
Number: upper bound of the value's range (default value is 1)
GuiSliderV
let gui;
let cf;
function setup() {
createCanvas(400, 400);
gui = createGui();
cf = createCrossfader("Crossfader", 50, 50);
}
Creates a new GuiCrossfader
object. This is a horizontal slider with a center point.
createCrossfader(label, x, y, [w], [h], [min], [max])
label
String: label for the GuiCrossfaderx
Number: x-coordinate of the GuiCrossfadery
Number: y-coordinate of the GuiCrossfaderw
Number: width of the GuiCrossfader (default is 128)h
Number: height of the GuiCrossfader (default is 32)min
Number: lower bound of the value's range (default value is -1)max
Number: upper bound of the value's range (default value is 1)
GuiCrossfader
let gui;
let cf;
function setup() {
createCanvas(400, 400);
gui = createGui();
cf = createCrossfader("CrossfaderV", 50, 50);
}
Creates a new GuiCrossfaderV
object. This is a vertical slider with a center point.
createCrossfaderV(label, x, y, [w], [h], [min], [max])
label
String: label for the GuiCrossfaderVx
Number: x-coordinate of the GuiCrossfaderVy
Number: y-coordinate of the GuiCrossfaderVw
Number: width of the GuiCrossfaderV (default is 32)h
Number: height of the GuiCrossfaderV (default is 128)min
Number: lower bound of the value's range (default value is -1)max
Number: upper bound of the value's range (default value is 1)
GuiCrossfaderV
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
let gui;
let j;
function setup() {
createCanvas(400, 400);
gui = createGui();
j = createJoystick("Joystick", 50, 50);
}
Creates a new GuiJoystick
object. This is a 2 dimensional slider, and the handle snaps back to the center.
createJoystick(label, x, y, [w], [h], [minX], [maxX], [maxX], [maxY])
label
String: label for the GuiJoystickx
Number: x-coordinate of the GuiJoysticky
Number: y-coordinate of the GuiJoystickw
Number: width of the GuiJoystick (default is 256)h
Number: height of the GuiJoystick (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)
GuiJoystick