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 692 forks source link

Dynamically load Layers #4

Open hurtwolf opened 3 years ago

hurtwolf commented 3 years ago

Yo, i thought i'd contribute to the project since i was messing with dynamically loading of the layers..

const layers = [];

const setLayers = () => {
  return (
    fs
    .readdirSync(`${dir}/gen_${gen}/`)
    // .filter((item) => !/(^|\/)\.[^\/\.]/g.test(item))
    .map((folder, i) => {
      layers.push({
        id: i + 1,
        gen: gen,
        name: folder,
        location: `${dir}/gen_${gen}/${folder}/`,
        elements: getElements(`${dir}/gen_${gen}/${folder}/`),
        position: { x: 0, y: 0 },
        size: { width: width, height: height },
      })
    })
  );
};

Note that I'm not an experience coder, but it works well. (obviously its edited for my project). That also remind me, mixing different layers (generations) would be a cool tutorial! Keep it up.

HashLips commented 3 years ago

Hi Thank you for contributing, I will be having a look, and then we can see how we can incorporate it in the latest update.