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

Adding weight doesn't guarantee usage of trait element #159

Open jasan-s opened 2 years ago

jasan-s commented 2 years ago

In the following example for headwear layer with None element has 30% weight and remaining all have 10% each, see code.

      {
        name: "Headwear",
        elements: [
          {
            id: 0,
            name: "None",
            path: `${dir}/headwear/none.png`,
            weight: 100, //30%
          },
          {
            id: 1,
            name: "Headphones",
            path: `${dir}/headwear/headphones.png`,
            weight: 70, // 10%
          },
          {
            id: 2,
            name: "Beanie",
            path: `${dir}/headwear/beanie.png`,
            weight: 60, // 10%
          },
          {
            id: 3,
            name: "Brain",
            path: `${dir}/headwear/brain.png`,
            weight: 50, // 10%
          },
          {
            id: 4,
            name: "Birds",
            path: `${dir}/headwear/birds.png`,
            weight: 40, // 10%
          },
          {
            id: 5,
            name: "Tattoo",
            path: `${dir}/headwear/tattoo.png`,
            weight: 30, // 10%
          },
          {
            id: 6,
            name: "Zombie hat",
            path: `${dir}/headwear/zombie hat.png`,
            weight: 20,// 10%
          },
          {
            id: 7,
            name: "Alien headset",
            path: `${dir}/headwear/alien headset.png`,
            weight: 10, // 10%
          },
        ],
        position: { x: 0, y: 0 },
        size: { width: width, height: height },
      }

Expected: With editionSize set to 100, Out of 100 output files, each of non-None elements(Headphones, Beanie. etc) should represent 10% of the headwears and 30% of files should have None headwear

Actually Happening: Some headwear elements are not included in any outputted files.

calebharris216 commented 2 years ago

Yeah these rarity weights are unbelievably confusing. In one of the videos he says to have them ordered from highest to lowest with no duplicate values, though even when I account for this, whatever element I put at the top gets vastly overrepresented. I am struggling for answers.