addPattern = function addPattern(key, pattern) {
    // only add it if it is not already present (the keys provided by the user must be unique!)
    if (patternMap[key]) return;
    var prefix = pattern instanceof ShadingPattern ? "Sh" : "P";
    var patternKey = prefix + (Object.keys(patterns).length + 1).toString(10);
    pattern.id = patternKey;
    patternMap[key] = patternKey;
    patterns[patternKey] = pattern;
    events.publish("addPattern", pattern);
  }
Adds a new pattern for later use.
@param {String} key The key by it can be referenced later. The keys must be unique!
@param {API.Pattern} pattern The pattern