p5.mapper


Reference

const pMapper = createProjectionMapper(this);

Creating Mapping Surfaces

Oscillator

Get the value of an oscillator (useful for LineMap animations):

Saving / Loading

pMapper.load("maps/map.json", () => console.log("done loading json"));

Calibrating

In calibration mode, dragging can be restricted:


QuadMap

Quads perform a perspective matrix transform of visuals (unlike the other surface objects). The following methods are available:


TriMap

A triangular surface with three control points (apex, bottom-left, bottom-right). Extends QuadMap and shares the same display interface:


BezierMap

const bezMap = pMapper.createBezierMap([numPoints]);

Bezier objects have the following display methods:

To add / remove points to a bezier map:


LineMap

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:

End cap control

Line width

Set the property directly:

lineMap.lineW = 20;

Mouse-over callback

Useful for click interactions:

function mousePressed() {
  for (const lineMap of lineMaps) {
    lineMap.isMouseOverCallback(lineClickedCallback);
  }
}

function lineClickedCallback(line) {
  selectedLine = line;
}

function setLineThickness(increment) {
  if (selectedLine != null) {
    selectedLine.lineW += increment;
  }
}