From 40e47956858ea3667f697bdbb0f760535b7aba9f Mon Sep 17 00:00:00 2001 From: "JO Jr." Date: Sat, 27 Jan 2024 11:42:10 -0500 Subject: [PATCH] RandomSize, init, and sizes.yaml --- __init__.py | 10 ++++++++++ random_size.py | 21 +++++++++++++++++++++ sizes.yaml | 22 ++++++++++++++++++++++ 3 files changed, 53 insertions(+) create mode 100644 __init__.py create mode 100644 random_size.py create mode 100644 sizes.yaml diff --git a/__init__.py b/__init__.py new file mode 100644 index 0000000..576f8cc --- /dev/null +++ b/__init__.py @@ -0,0 +1,10 @@ + +from .random_size import RandomSize +LIVE_NODE_CLASS_MAPPINGS = { + "JOJR_RandomSize": RandomSize, +} + +NODE_DISPLAY_NAME_MAPPINGS = { + "JOJR_RandomSize": "Random Size", +} +__all__ = ['NODE_CLASS_MAPPINGS', 'NODE_DISPLAY_NAME_MAPPINGS'] \ No newline at end of file diff --git a/random_size.py b/random_size.py new file mode 100644 index 0000000..3e39744 --- /dev/null +++ b/random_size.py @@ -0,0 +1,21 @@ +import yaml, os, random +module_root_directory = os.path.dirname(os.path.realpath(__file__)) +config_file = os.path.join(module_root_directory,'sizes.yaml') + +def read_config(item): + with open(config_file, 'r') as file: + return yaml.safe_load(file)[item] + +class RandomSize: + CATEGORY = "quicknodes" + RETURN_TYPES = ("INT","INT") + RETURN_NAMES = ("width","height") + FUNCTION = "func" + def func(self,size:str): + sizes = read_config('sizes') + rand_obj = random.random.Random() + idx = rand_obj.randint(0, len(sizes)) + size = sizes[idx] + x, y = [int(v) for v in size.split('x')] + return (x,y) + diff --git a/sizes.yaml b/sizes.yaml new file mode 100644 index 0000000..6294ae2 --- /dev/null +++ b/sizes.yaml @@ -0,0 +1,22 @@ +sizes: +- 512x512 +- 512x768 +- 640x768 +- 512x1024 +- 640x640 +- 640x896 +- 768x512 +- 768x640 +- 768x768 +- 768x1024 +- 1024x512 +- 1024x768 +- 640x1536 +- 768x1344 +- 832x1216 +- 840x1176 +- 896x1152 +- 960x1088 +- 1024x1024 +- 1216x832 +- 1344x768 \ No newline at end of file