Aller au contenu principal

Getting Started

Let's get you up and running with your first Verlet.js simulation. Choose your preferred environment below.

1. Installation

npm install verlet-react verlet-engine

2. Create your Simulation

Use the <VerletCanvas> component to create a simulation world and add objects to it.

import React from 'react';
import { VerletCanvas, Point, DistanceConstraint } from 'verlet-react';
import { Vec2 } from 'verlet-engine';

const App = () => {
return (
<VerletCanvas width={500} height={500} gravity={{ x: 0, y: 0.5 }}>
<Point id="p1" pos={new Vec2(200, 50)} pinned />
<Point id="p2" pos={new Vec2(220, 50)} />
<Point id="p3" pos={new Vec2(240, 50)} />
<Point id="p4" pos={new Vec2(260, 50)} />

<DistanceConstraint from="p1" to="p2" />
<DistanceConstraint from="p2" to="p3" />
<DistanceConstraint from="p3" to="p4" />
</VerletCanvas>
);
};

export default App;