{
const width = 600,
height = 200,
target = object(),
car = object({
location: cm.vec(width / 2, height / 2),
maxSpeed: 4,
maxForce: 0.1,
r: 6
});
function update(app) {
app.append(cm.clear, { fill: cm.rgb(255) });
app
.datum(target)
.process(cm.each, (d) =>
d.location.set(app.prop("mouseX"), app.prop("mouseY"))
)
.append(cm.circle, {
x: (d) => d.location.x,
y: (d) => d.location.y,
r: 24,
stroke: "black",
fill: cm.rgb(175),
strokeWidth: 2
});
app
.datum(car)
.process(cm.each, (d) => seek(d, target))
.process(cm.each, move)
.append(cm.group, {
x: (d) => d.location.x,
y: (d) => d.location.y,
rotate: (d) => d.velocity.angle()
})
.append(cm.triangle, {
x: (d) => d.r * 2,
y: 0,
x1: (d) => -d.r * 2,
y1: (d) => -d.r,
x2: (d) => -d.r * 2,
y2: (d) => d.r,
fill: cm.rgb(175),
stroke: cm.rgb(0),
strokeWidth: 2
});
}
function dispose(app) {
invalidation.then(() => app.dispose());
}
return cm
.app({ width, height })
.on("update", update)
.call(border)
.call(dispose)
.start()
.node();
}