File size: 6,330 Bytes
baa8e90 |
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 |
#---------------------------------------------------------------------------------------------------------------------#
# Comfyroll Custom Nodes by RockOfFire and Akatsuzi https://github.com/Suzie1/ComfyUI_Comfyroll_CustomNodes
# for ComfyUI https://github.com/comfyanonymous/ComfyUI
#---------------------------------------------------------------------------------------------------------------------#
import random
import string
from .graphics_functions import random_hex_color, random_rgb
from ..categories import icons
#---------------------------------------------------------------------------------------------------------------------#
# Random values
#---------------------------------------------------------------------------------------------------------------------#
class CR_RandomHexColor:
@classmethod
def INPUT_TYPES(cls):
return {"required": {"seed": ("INT", {"default": 0, "min": 0, "max": 0xffffffffffffffff}),}}
RETURN_TYPES = ("STRING", "STRING", "STRING", "STRING", "STRING", )
RETURN_NAMES = ("hex_color1", "hex_color2", "hex_color3", "hex_color4", "show_help", )
FUNCTION = "get_colors"
CATEGORY = icons.get("Comfyroll/Utils/Random")
def get_colors(self, seed):
# Set the seed
random.seed(seed)
hex_color1 = random_hex_color()
hex_color2 = random_hex_color()
hex_color3 = random_hex_color()
hex_color4 = random_hex_color()
show_help = "https://github.com/Suzie1/ComfyUI_Comfyroll_CustomNodes/wiki/Other-Nodes#cr-random-hex-color"
return (hex_color1, hex_color2, hex_color3, hex_color4, show_help, )
#---------------------------------------------------------------------------------------------------------------------#
class CR_RandomRGB:
@classmethod
def INPUT_TYPES(cls):
return {"required": {"seed": ("INT", {"default": 0, "min": 0, "max": 0xffffffffffffffff}),}}
RETURN_TYPES = ("STRING", "STRING", "STRING", "STRING", "STRING", )
RETURN_NAMES = ("rgb_1", "rgb_2", "rgb_3", "rgb_4", "show_help", )
FUNCTION = "get_colors"
CATEGORY = icons.get("Comfyroll/Utils/Random")
def get_colors(self, seed):
# Set the seed
random.seed(seed)
rgb_1 = random_rgb()
rgb_2 = random_rgb()
rgb_3 = random_rgb()
rgb_4 = random_rgb()
show_help = "https://github.com/Suzie1/ComfyUI_Comfyroll_CustomNodes/wiki/Other-Nodes#cr-random-rgb"
return (rgb_1, rgb_2, rgb_3, rgb_4, show_help, )
#---------------------------------------------------------------------------------------------------------------------#
class CR_RandomMultilineValues:
@classmethod
def INPUT_TYPES(cls):
types = ["binary", "decimal", "hexadecimal", "alphabetic", "alphanumeric"]
return {"required": {"seed": ("INT", {"default": 0, "min": 0, "max": 0xffffffffffffffff}),
"value_type": (types,),
"rows": ("INT", {"default": 5, "min": 1, "max": 2048}),
"string_length": ("INT", {"default": 5, "min": 1, "max": 2048}),
}
}
RETURN_TYPES = ("STRING", "STRING", )
RETURN_NAMES = ("multiline_text", "show_help", )
FUNCTION = "generate"
CATEGORY = icons.get("Comfyroll/Utils/Random")
def generate(self, value_type, rows, string_length, seed):
# Set the seed
random.seed(seed)
if value_type == "binary":
choice_str = '01'
elif value_type == "decimal":
choice_str = '0123456789'
elif value_type == "hexadecimal":
choice_str = '0123456789abcdef'
elif value_type == "alphabetic":
choice_str = string.ascii_letters
elif value_type == "alphanumeric":
choice_str = string.ascii_letters + string.digits
multiline_text = '\n'.join([''.join(random.choice(choice_str) for _ in range(string_length)) for _ in range(rows)])
show_help = "https://github.com/Suzie1/ComfyUI_Comfyroll_CustomNodes/wiki/Other-Nodes#cr-random-multiline-values"
return (multiline_text, show_help, )
#---------------------------------------------------------------------------------------------------------------------#
class CR_RandomRGBGradient:
@classmethod
def INPUT_TYPES(cls):
return {"required": {"seed": ("INT", {"default": 0, "min": 0, "max": 0xffffffffffffffff}),
"rows": ("INT", {"default": 5, "min": 1, "max": 2048}),
}
}
RETURN_TYPES = ("STRING", "STRING", )
RETURN_NAMES = ("multiline_text", "show_help", )
FUNCTION = "generate"
CATEGORY = icons.get("Comfyroll/Utils/Random")
def generate(self, rows, seed):
# Set the seed
random.seed(seed)
temp = 0
multiline_text = ""
for i in range(1, rows + 1):
print(temp)
if temp <= 99 - rows + i:
upper_bound = min(99, temp + (99 - temp) // (rows - i + 1))
current_value = random.randint(temp, upper_bound)
multiline_text += f'{current_value}:{random.randint(0, 255)},{random.randint(0, 255)},{random.randint(0, 255)}\n'
print(multiline_text)
temp = current_value + 1
show_help = "https://github.com/Suzie1/ComfyUI_Comfyroll_CustomNodes/wiki/Other-Nodes#cr-random-RGB-gradient"
return (multiline_text, show_help, )
#---------------------------------------------------------------------------------------------------------------------#
# MAPPINGS
#---------------------------------------------------------------------------------------------------------------------#
# For reference only, actual mappings are in __init__.py
'''
NODE_CLASS_MAPPINGS = {
# Random
"CR Random Hex Color": CR_RandomHexColor,
"CR Random RGB": CR_RandomRGB,
"CR Random Multiline Values": CR_RandomMultilineValues,
"CR Random RGB Gradient": CR_RandomRGBGradient,
}
'''
|