Spaces:
Running
on
L40S
Running
on
L40S
File size: 10,584 Bytes
4450790 |
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 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 |
#---------------------------------------------------------------------------------------------------------------------#
# Comfyroll Studio 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 .functions_graphics import random_hex_color, random_rgb
from ..categories import icons
try:
import matplotlib.pyplot as plt
import matplotlib.colors as mcolors
except ImportError:
import pip
pip.main(['install', 'matplotlib'])
import matplotlib.pyplot as plt
import matplotlib.colors as mcolors
class AnyType(str):
# Credit to pythongosssss
def __ne__(self, __value: object) -> bool:
return False
any_type = AnyType("*")
#---------------------------------------------------------------------------------------------------------------------#
# 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", "natural", "hexadecimal", "alphabetic", "alphanumeric", "custom"]
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": 1024}),
"custom_values": ("STRING", {"multiline": False, "default": "123ABC"}),
"prepend_text": ("STRING", {"multiline": False, "default": ""}),
}
}
RETURN_TYPES = (any_type, "STRING", )
RETURN_NAMES = ("multiline_text", "show_help", )
FUNCTION = "generate"
CATEGORY = icons.get("Comfyroll/Utils/Random")
def generate(self, value_type, rows, string_length, custom_values, seed, prepend_text):
show_help = "https://github.com/Suzie1/ComfyUI_Comfyroll_CustomNodes/wiki/Other-Nodes#cr-random-multiline-values"
# Set the seed
random.seed(seed)
if value_type == "binary":
choice_str = '01'
elif value_type == "decimal":
choice_str = '0123456789'
elif value_type == "natural":
choice_str = '123456789'
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
elif value_type == "custom":
choice_str = custom_values
else:
pass
multiline_text = '\n'.join([prepend_text + ''.join(random.choice(choice_str) for _ in range(string_length)) for _ in range(rows)])
return (multiline_text, show_help, )
#---------------------------------------------------------------------------------------------------------------------#
class CR_RandomMultilineColors:
@classmethod
def INPUT_TYPES(cls):
types = ["rgb", "hex color", "matplotlib xkcd"]
return {"required": {"seed": ("INT", {"default": 0, "min": 0, "max": 0xffffffffffffffff}),
"value_type": (types,),
"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, value_type, rows, seed):
show_help = "https://github.com/Suzie1/ComfyUI_Comfyroll_CustomNodes/wiki/Other-Nodes#cr-random-multiline-colors"
# Set the seed
random.seed(seed)
# Get the list of XKCD color names
xkcd_colors = mcolors.XKCD_COLORS
if value_type == "hex color":
choice_str = '0123456789ABCDEF'
if value_type == "hex color":
multiline_text = '\n'.join(['#' + ''.join(random.choice(choice_str) for _ in range(6)) for _ in range(rows)])
elif value_type == "rgb":
multiline_text = '\n'.join([f'{random.randint(0, 255)},{random.randint(0, 255)},{random.randint(0, 255)}' for _ in range(rows)])
elif value_type == "matplotlib xkcd":
multiline_text = '\n'.join([random.choice(list(xkcd_colors.keys())).replace('xkcd:', '') for _ in range(rows)])
else:
pass
return (multiline_text, show_help, )
#---------------------------------------------------------------------------------------------------------------------#
class CR_RandomPanelCodes:
@classmethod
def INPUT_TYPES(cls):
return {"required": {"seed": ("INT", {"default": 0, "min": 0, "max": 0xffffffffffffffff}),
"rows": ("INT", {"default": 5, "min": 1, "max": 2048}),
"string_length": ("INT", {"default": 5, "min": 1, "max": 1024}),
"values": ("STRING", {"multiline": False, "default": "123"}),
}
}
RETURN_TYPES = ("STRING", "STRING", )
RETURN_NAMES = ("multiline_text", "show_help", )
FUNCTION = "generate"
CATEGORY = icons.get("Comfyroll/Utils/Random")
def generate(self, rows, string_length, values, seed):
show_help = "https://github.com/Suzie1/ComfyUI_Comfyroll_CustomNodes/wiki/Other-Nodes#cr-random-panel-codes"
# Set the seed
random.seed(seed)
start_letter = random.choice('HV')
value_range = random.choice(values)
codes = []
for _ in range(rows):
# Generate a random number within the specified range
number = ''.join(random.choice(values) for _ in range(string_length))
# Append the code to the list
codes.append(f"{start_letter}{number}")
multiline_text = '\n'.join(codes)
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):
show_help = "https://github.com/Suzie1/ComfyUI_Comfyroll_CustomNodes/wiki/Other-Nodes#cr-random-RGB-gradient"
# 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'
temp = current_value + 1
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 Multiline Colors": CR_RandomMultilineColors,
"CR Random RGB Gradient": CR_RandomRGBGradient,
"CR Random Panel Codes": CR_RandomPanelCodes,
}
'''
|