JavaScript Deformer
Pro features are only available with a Professional licence. To upgrade, visit cavalry.scenegroup.co.
Intro
The JavaScript Deformer can be used to manipulate the points of a Shape in interesting and novel ways.
For more information on how JavaScript can be used across all JavaScript Layers see JavaScript Layers.
See JavaScript Layers→This deformer is similar to the JavaScript Shape and JavaScript Utility, only it has some additional syntax available to it so that it has access to a Shape's geometry. This has access to all of the Context Module which means data can be saved and loaded for use between frames.
See the Deformer Module for Member Functions exclusive to this Layer.
UI
JavaScript Expression - Enter JavaScript code here.
+ button - Add Dynamic Attributes as variables.
- Create a Basic Line.
- Create a JavaScript Deformer.
- Replace the default JavaScript Expression with:
var points = def.getPoints();
var bbox = def.getBoundingBox();
var maxX = bbox.x+bbox.width;
var frequency = 10;
var amplitude = 50;
for (let pt of points) {
let normX = cavalry.norm(pt.x, bbox.x, maxX);
pt.y += Math.sin((normX+n0*.1)*frequency)*amplitude;
}
def.setPoints(points);
- Connect javaScriptDeformer.id→basicLine.deformers.
This will deform the line into a wave. Try replacing let frequency = 10;
on line 4 with let frequency = n0;
and using the n0 attribute at the bottom to change the deformer's frequency.