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));
  }
});

PinePaper Wrapper Methods

registerGenerator(name, definition)

Register a custom generator via the PinePaper API.

Parameters:

  • name (string): Generator name
  • definition (object): Generator definition (see Registering Custom Generators above)
app.registerGenerator('myPattern', {
  displayName: 'My Pattern',
  description: 'Custom dot pattern',
  category: 'custom',
  params: {
    color: { type: 'color', default: '#3b82f6' },
    count: { type: 'number', default: 20, min: 1, max: 100 }
  },
  fn: function(ctx) {
    const { params, patternGroup } = ctx;
    for (let i = 0; i < params.count; i++) {
      const dot = new paper.Path.Circle({
        center: [Math.random() * 800, Math.random() * 600],
        radius: 5,
        fillColor: params.color,
        parent: patternGroup
      });
    }
  }
});

getRegisteredGenerators()

Get a list of all registered generators.

Returns: Array<object> - Array of generator definitions

const generators = app.getRegisteredGenerators();
generators.forEach(g => {
  console.log(g.name, g.category, g.description);
});

Checking Existence

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