Generator Registry

The Generator Registry manages background generators with parameter schemas.

Listing Generators

const generators = app.generatorRegistry.getAll();
// Returns array of generator definitions with params

Executing Generators

app.executeGenerator('drawSunburst', {
  rayCount: 16,
  colors: ['#FF6B6B', '#4ECDC4']
});

Async Execution

For generators that use Web Workers:

await app.generatorRegistry.executeAsync('drawPoissonShapesAsync', {
  shape: 'circle',
  minDistance: 40
});

Registering Custom Generators

app.generatorRegistry.register('myGenerator', {
  displayName: 'My Generator',
  description: 'Creates a custom pattern',
  category: 'custom',

  params: {
    color: { type: 'color', default: '#3b82f6' },
    count: { type: 'number', default: 10, min: 1, max: 100 },
    style: { type: 'select', options: ['a', 'b'], default: 'a' }
  },

  fn: function(ctx) {
    const { params, patternGroup, view, register } = ctx;
    // Create pattern elements...
    register(group, 'myGenerator', params);
  }
});

Parameter Types

Type Properties
number default, min, max, step
color default
boolean default
select options, default
string default

Generator Context

The generator function receives:

Property Description
params Resolved parameters
patternGroup Parent group for elements
view Paper.js view
register Registration function
app PinePaper instance
async Async helpers (for async generators)

Async Helpers

For async generators:

const points = await ctx.async.poissonDiskSampling(w, h, dist);
const spiral = await ctx.async.goldenRatioDistribution(count, w, h);
const simplified = await ctx.async.simplifyPath(points, tolerance);

Animation Callback

Add per-frame animation:

app.generatorRegistry.register('animated', {
  // ...config

  onAnimate: function(event, elements, params) {
    elements.forEach(el => el.rotate(event.delta * params.speed));
  }
});

Checking Existence

if (app.generatorRegistry.has('myGenerator')) {
  // Generator exists
}