const pMapper = createProjectionMapper(this);Methods to create mapping surfaces:
pMapper.createQuadMap(width, height, [resolution])pMapper.createTriMap(width, height, [resolution])pMapper.createPolyMap([numPoints])pMapper.createBezierMap([numPoints])pMapper.createLineMap([x0], [y0], [x1], [y1])
Get the value of an oscillator (useful for LineMap animations):
pMapper.getOscillator(seconds, [offset])- Returns a number 0–1 that oscillates with a
seconds-long period and an optional phaseoffset(sine wave helper)
- Returns a number 0–1 that oscillates with a
Saving / loading methods:
pMapper.save([filename.json])pMapper.load([directory/filename.json], [callback])
pMapper.load("maps/map.json", () => console.log("done loading json"));Calibrating methods:
pMapper.startCalibration()pMapper.stopCalibration()pMapper.toggleCalibration()
In calibration mode, dragging can be restricted:
pMapper.moveAll()- allows dragging surfaces or control points
pMapper.moveSurfaces()- limits movement to dragging surfaces (not control points)
pMapper.moveControlPoints()- limits movement to control points only
Quads perform a perspective matrix transform of visuals (unlike the other surface objects). The following methods are available:
display([color])displayTexture(img, [x], [y], [w], [h])- img — a
p5.Image,p5.Element, orp5.Texture - x, y — top-left corner of the source image (default: 0, 0)
- w, h — source dimensions (default: image size)
- img — a
displaySketch(fn, [x], [y], [w], [h])- fn — a function that receives a
p5.Graphicsobject and draws on it
- fn — a function that receives a
A triangular surface with three control points (apex, bottom-left, bottom-right). Extends QuadMap and shares the same display interface:
display([color])displayTexture(img, [x], [y], [w], [h])displaySketch(fn, [x], [y], [w], [h])
const bezMap = pMapper.createBezierMap([numPoints]);Bezier objects have the following display methods:
bezMap.display([color])bezMap.displayTexture(img, [x], [y], [w], [h])- img — a
p5.Image,p5.Element, orp5.Texture - x, y — top-left corner of the source image (default: 0, 0)
- w, h — source dimensions (default: image size)
- img — a
bezMap.displaySketch(fn, [x], [y], [w], [h])- fn — a function that receives a
p5.Graphicsobject and draws on it
- fn — a function that receives a
To add / remove points to a bezier map:
bezMap.addSegment([x], [y])- x, y default to mouse position; otherwise specify coordinates
bezMap.removeSegment([x], [y])- x, y default to mouse position (deletes closest anchor); otherwise specify coordinates
To create a line map:
const lineMap = pMapper.createLineMap();Initialize with explicit coordinates:
const lineMap = pMapper.createLineMap(-200, 0, 100, 100);Display methods (all accept an optional color and stroke weight):
lineMap.display([color], [strokeWeight])lineMap.displayNone()- draws the line in black (hides it on a black background)
lineMap.displayPercent(percent, [color], [strokeWeight])- draws from
p0to a pointpercentof the way towardp1
- draws from
lineMap.displayCenterPulse(percent, [color], [strokeWeight])- pulses outward from the center toward both endpoints
lineMap.displayPercentWidth(percent, [color])- keeps the full line but scales stroke width by
percent
- keeps the full line but scales stroke width by
lineMap.displaySegment(startPercent, sizePercent, [color], [strokeWeight])- draws a segment of the line starting at
startPercentwith lengthsizePercent
- draws a segment of the line starting at
lineMap.displayRainbowCycle()- HSB hue cycle tied to
frameCount
- HSB hue cycle tied to
lineMap.displayGradientLine(color0, color1, percent, [phase], [flip])- swept two-color gradient along the line
lineMap.displayNumber()- renders the line's id at its midpoint — helpful when line order matters
End cap control:
lineMap.setEndCapsOn()(default)lineMap.setEndCapsOff()
Setting line width — set the property directly:
lineMap.lineW = 20;Mouse-over callback (useful for click interactions):
lineMap.isMouseOverCallback(callback)
function mousePressed() {
for (const lineMap of lineMaps) {
lineMap.isMouseOverCallback(lineClickedCallback);
}
}
function lineClickedCallback(line) {
selectedLine = line;
}
function setLineThickness(increment) {
if (selectedLine != null) {
selectedLine.lineW += increment;
}
}