HashLips / generative-art-opensource

Create generative art by using the canvas api and node js, feel free to contribute to this repo with new ideas.
MIT License
1.36k stars 695 forks source link

Cannot read property 'layers' of undefined #38

Closed tdr357 closed 2 years ago

tdr357 commented 2 years ago

This occurs when switching out HashLips's test layers for my own. Any help will be appreciated

pehcastro commented 2 years ago

in config.js for v1 brach, you will find everything you need to change to make it works.

first step is changing edition size for how many nfts you want, we are creating 10000 here.

const editionSize = 10000;

then create the rarity weights (this will be your subfolders on layer folders) you need to config

let rarityWeights = [
  addRarity('common', 1, 5200),
  addRarity('uncommon', 5200, 8000),
  addRarity('rare', 8000, 9100),
  addRarity('epic', 9100, 9900),
  addRarity('exotic', 9900, 10000),
];

where common 1,5200 is how many commons will have (5200) uncommon from 5200 to 8000 and so on, until reaching the edition size.

also, you need to change this line for code find your folders

const layers = [
  addLayer('foldername'),
];

change folder name to your folder name (in order).

my example;

const layers = [
  addLayer('ambience'),
  addLayer('body'),
  addLayer('shoes'),
  addLayer('pants'),
  addLayer('shirt'),
  addLayer('hair'),
  addLayer('eyes'),
  addLayer('gadget'),
];

this will get your layers in right place, always check if the folder name is correct. each subfolder should have your rarity names (normal, epic, etc) and then this should be on RarityWeights (at the start of this comment).

if you want to specify how many percent each layer will be drawn, you can edit in addRarityPercentForLayer like this, in common generating (in RarityWeight I have a common rarity from 1 to 1000)

//commons
addRarityPercentForLayer('common', 'ambience', { 'common': 60, 'uncommon': 40, 'rare': 0, 'epic': 0, 'exotic': 0 });
addRarityPercentForLayer('common', 'body', { 'common': 60, 'uncommon': 28, 'rare': 12, 'epic': 0, 'exotic': 0 });
addRarityPercentForLayer('common', 'shoes', { 'common': 60, 'uncommon': 28, 'rare': 12, 'epic': 0, 'exotic': 0 });
addRarityPercentForLayer('common', 'pants', { 'common': 60, 'uncommon': 28, 'rare': 12, 'epic': 0, 'exotic': 0 });
addRarityPercentForLayer('common', 'shirt', { 'common': 60, 'uncommon': 28, 'rare': 12, 'epic': 0, 'exotic': 0 });
addRarityPercentForLayer('common', 'hair', { 'common': 60, 'uncommon': 28, 'rare': 12, 'epic': 0, 'exotic': 0 });
addRarityPercentForLayer('common', 'eyes', { 'common': 60, 'uncommon': 28, 'rare': 12, 'epic': 0, 'exotic': 0 });
addRarityPercentForLayer('common', 'gadget', { 'common': 67, 'uncommon': 33, 'rare': 0, 'epic': 0, 'exotic': 0 });

were 'common' = rarity 'ambience' my first layer to draw and 'common':60 how many % of common images will be drawed on this first 1000 images. It will generate with 1000 commons with 60% common chance and 40% uncommon.

hope it helps.

ch264 commented 2 years ago

Thank you for the solution @pehcastro. I had the same error message 🚀

tdr357 commented 2 years ago

Fixed, thanks guys

trazpz commented 2 years ago

This doesn't work for me i still get the error, I've tried everything...

ch264 commented 2 years ago

@trazpz it worked for me. In config.js I changed the number of files to 20:

const editionSize = 20;

and also the number in original for the rarityWeights below:

letRarity = [
   addRarity('original', 5, 20)
]