Repository: HashLips/generative-art-opensource
File: input/config.js (JavaScript)

Code before:
const height = 1000;
// description for NFT in metadata file
const description = "This is an NFT made by the coolest generative code.";
// base url to use in metadata file
// the id of the nft will be added to this url, in the example e.g. https://hashlips/nft/1 for NFT with id 1
const baseImageUri = "https://hashlips/nft";
// id for edition to start from
const startEditionFrom = 1;
// amount of NFTs to generate in edition
const editionSize = 10;
// prefix to add to edition dna ids (to distinguish dna counts from different generation processes for the same collection)
const editionDnaPrefix = 0

// create required weights
// for each weight, call 'addRarity' with the id and from which to which element this rarity should be applied
let rarityWeights = [
  addRarity('super_rare', 1, 1),
  addRarity('rare', 2, 5),
  addRarity('original', 5, 10)
];

// create required layers
// for each layer, call 'addLayer' with the id and optionally the positioning and size
// the id would be the name of the folder in your input directory, e.g. 'ball' for ./input/ball
const layers = [
  addLayer('ball'),
  addLayer('eye color'),
  addLayer('iris'),
  addLayer('shine'),
  addLayer('bottom lid'),
  addLayer('top lid')
];

// provide any specific percentages that are required for a given layer and rarity level
// all provided options are used based on their percentage values to decide which layer to select from
addRarityPercentForLayer('super_rare', 'ball', { 'super_rare': 33, 'rare': 33, 'original': 33 });
addRarityPercentForLayer('super_rare', 'eye color', { 'super_rare': 50, 'rare': 25, 'original': 25 });
addRarityPercentForLayer('original', 'eye color', { 'super_rare': 50, 'rare': 25, 'original': 25 });

module.exports = {
  layers,
  width,
  height,
  description,
  baseImageUri,
  editionSize,
  startEditionFrom,
  rarityWeights,
};


Review comment (suggestion):
`addLayer` is now much more readable. It takes the provided layer name in combination with the previously defined rarities to find the necessary elements. It also uses position and size optionally - in most cases users can just use same size layers (like in the examples). 

Code after:
const height = 1000;
// description for NFT in metadata file
const description = "This is an NFT made by the coolest generative code.";
// base url to use in metadata file
// the id of the nft will be added to this url, in the example e.g. https://hashlips/nft/1 for NFT with id 1
const baseImageUri = "https://hashlips/nft";
// id for edition to start from
const startEditionFrom = 1;
// amount of NFTs to generate in edition
const editionSize = 10;
// prefix to add to edition dna ids (to distinguish dna counts from different generation processes for the same collection)
const editionDnaPrefix = 0

// create required weights
// for each weight, call 'addRarity' with the id and from which to which element this rarity should be applied
let rarityWeights = [
  addRarity('super_rare', 1, 1),
  addRarity('rare', 2, 5),
  addRarity('original', 5, 10)
];

// create required layers
// for each layer, call 'addLayer' with the id and optionally the positioning and size
// the id would be the name of the folder in your input directory, e.g. 'ball' for ./input/ball
const layers = [
  addLayer('ball', { x: 0, y: 0 }, { width: width, height: height }),
  addLayer('eye color'),
  addLayer('iris'),
  addLayer('shine'),
  addLayer('bottom lid'),
  addLayer('top lid')
];

// provide any specific percentages that are required for a given layer and rarity level
// all provided options are used based on their percentage values to decide which layer to select from
addRarityPercentForLayer('super_rare', 'ball', { 'super_rare': 33, 'rare': 33, 'original': 33 });
addRarityPercentForLayer('super_rare', 'eye color', { 'super_rare': 50, 'rare': 25, 'original': 25 });
addRarityPercentForLayer('original', 'eye color', { 'super_rare': 50, 'rare': 25, 'original': 25 });

module.exports = {
  layers,
  width,
  height,
  description,
  baseImageUri,
  editionSize,
  startEditionFrom,
  rarityWeights,
};