Created
March 4, 2022 02:04
-
-
Save Moishe/e1f7099c1e47ca2d81dd3549e78ebd46 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import itertools | |
import json | |
base_config = { | |
"blurUniforms": { | |
"blurMultiplier": 10000, | |
"fadeDecrement": 0.00021 | |
}, | |
"colonies": { | |
"dense": { | |
"directionMomentum": 0.0, | |
"directionRandomization": 0.4, | |
"growth": { | |
"birthInterval": 0, | |
"growth": { | |
"ratio": 0.001 | |
}, | |
"initial": { | |
"ratio": 0.1 | |
}, | |
"max": { | |
"ratio": 0.5 | |
}, | |
"spawnFromExisting": True, | |
"spawnNewFromExisting": True, | |
"spawnRegenFromExisting": True, | |
"spawnWithTextureColor": True | |
}, | |
"intensity": 1, | |
"location": { | |
"distributed": True, | |
"ratio": { | |
"x": 0.5, | |
"y": 0.5 | |
} | |
}, | |
"lookDistance": range(1, 3), | |
"lookRadians": range(1, 2), | |
"lookSlices": 2, | |
"maxSpeed": 1.0333333333333332, | |
"spawnProbability": 1.0, | |
"spawnRandomOffset": 0.1 | |
} | |
}, | |
"output": { | |
"count": 1, | |
"filename-base": "sample-0-0-2-1-", | |
"interval": 1000, | |
"path": "/Volumes/fast-external 1/batch-output/" | |
}, | |
"rngSeed": 1, | |
"texturePath": "/Users/moishe/Desktop/flash_tree.jpg" | |
} | |
def find_ranges(d, p=[]): | |
print(d, p) | |
ranges = [] | |
for k,v in d.items(): | |
if type(v) == range: | |
ranges.append((p + [k], v)) | |
elif type(v) == dict: | |
ranges += find_ranges(v, p+[k]) | |
return ranges | |
def expand_dictionary(d): | |
ranges = find_ranges(d) | |
values = itertools.product(*[r[1] for r in ranges]) | |
for v in values: | |
for (i, el) in enumerate(v): | |
subd = d | |
for k in ranges[i][0][:-1]: | |
subd = subd[k] | |
subd[ranges[i][0][-1]] = el | |
print(json.dumps(d, indent=2)) | |
if __name__ == "__main__": | |
ranges = expand_dictionary(base_config) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment