Montspy / LooPyGen

Loopring Python Minter on Layer 2
17 stars 6 forks source link

feat: Random background generation #22

Closed Montspy closed 2 years ago

Montspy commented 2 years ago

Adds ability to pick background color or transparent background. Can also add a set of colors and weights for random generation. Example with random red/green/blue color:

## Layers dictionary
layers = [
    {   # Background color
        "layer_name": "Background color",
        "rgba": {
            "Red":   (192,  54,  54, 255),
            "Green": ( 54, 192,  54, 255),
            "Blue":  ( 54,  54, 192, 255),
        },
        "weights": [
            33,
            33,
            34
        ],
        "size": (640, 640)  # Adjust to the size of your images
    },
    {   # layer01
        "layer_name": "Pretty Trait Name 01",
        "filenames": {
            "Pretty Item Name 01": "item_01.png",
            "Pretty Item Name 02": "item_02.png"
        },
        "weights": [
            50,
            50
        ]
    },
    {   # layer02
        "layer_name": "Pretty Trait Name 02",
        "filenames": {
            "Pretty Item Name 01": "item_01.png",
            "Pretty Item Name 02": "item_02.png"
        },
        "weights": [
            50,
            50
        ]
    }
]
sk33z3r commented 2 years ago

I think the count function at the bottom has a problem that there isn't filename, and maybe doesn't check for variations considering the background colors. I double checked my traits.py to the example, and I don't see a difference in the function. Is there a traits.example.py update that didn't get committed maybe?

Traceback (most recent call last):
  File "/var/www/html/generator/generate.py", line 248, in <module>
    main()
  File "/var/www/html/generator/generate.py", line 123, in main
    if total_image > traits.get_variation_cnt():
  File "/var/www/html/generator/traits.py", line 161, in get_variation_cnt
    cnt *= len(l["filenames"])
KeyError: 'filenames'
Montspy commented 2 years ago

There's always a change I forget to propagate to traits.examples.py... Fixed in 7b22591971705fe94018909ac68e9a8dd1947145

sk33z3r commented 2 years ago

Feature looks good. We will need to do some explanation on this in the Wiki for those that are not familiar with rgba, but otherwise I love the implementation and I'm gonna merge into main.

I think I'm gonna move traits over to json next to avoid the traits confusion as well :+1:

The only potential thing I can see needing to be done here is after switching traits to JSON. I don't think we can put tuples as a JSON object, so will need to convert a list object to tuple when we grab the info.