Particlize

CurlNoiseConstraint

A constraint that applies curl noise forces to create fluid-like motion patterns

Constructor

new CurlNoiseConstraint(name: string, params?: CurlNoiseConstraintParams)

Parameters

ParameterTypeDescriptionDefault
namestringUnique name for the constraint-
paramsCurlNoiseConstraintParamsConfiguration options{}

CurlNoiseConstraintParams

ParameterTypeDescriptionDefault
strengthnumberIntensity of the curl noise force0.1
scalenumberScale of the noise pattern1.0
timeScalenumberSpeed of noise evolution over time1.0
property"velocity" | "position" | "force"Which particle property to affect"velocity"

Properties

PropertyTypeDescription
namestringUnique identifier for the constraint
activebooleanWhether the constraint is active
glslstringGenerated GLSL shader code
uniformsRecord<string, any>Uniform values for the shader
paramsRecord<string, any>Parameter definitions

Methods

build(): void

Processes the constraint's parameters and builds the final GLSL code with proper namespacing.

Example Usage

import { ParticleSystem, Particle, Frame } from 'particlize';
import { CurlNoiseConstraint } from 'particlize/constraints';

// Create particle system
const ps = new ParticleSystem({
  canvas: document.getElementById('canvas'),
  fboWidth: 512,
  fboHeight: 512
});

// Create particles
const particles = Array.from({ length: 10000 }, () => new Particle({
  position: [
    (Math.random() - 0.5) * 2,
    (Math.random() - 0.5) * 2,
    (Math.random() - 0.5) * 2
  ]
}));

ps.addParticles(new Frame({ particles }));

// Add curl noise for fluid motion
ps.manager.constrain('velocity', new CurlNoiseConstraint('fluidFlow', {
  strength: 0.02,
  scale: 3.0,
  timeScale: 0.5
}));

// Add curl noise affecting position for morphing effects
ps.manager.constrain('position', new CurlNoiseConstraint('morphing', {
  strength: 0.01,
  scale: 5.0,
  timeScale: 0.2,
  property: 'position'
}));

// Animation loop
function animate() {
  ps.update();
  requestAnimationFrame(animate);
}
animate();