From d72d0b6b901a78b8d3bbd6b360c42abf8165d6ab Mon Sep 17 00:00:00 2001 From: Roblox-Thot <67937010+Roblox-Thot@users.noreply.github.com> Date: Sun, 29 Sep 2024 11:05:02 -0400 Subject: [PATCH] move methods into its own file --- OneUploader.py | 120 ++-------------------------------------------- methods.py | 128 +++++++++++++++++++++++++++++++++++++++++++++++++ 2 files changed, 131 insertions(+), 117 deletions(-) create mode 100644 methods.py diff --git a/OneUploader.py b/OneUploader.py index fb6ab93..ac85c1c 100644 --- a/OneUploader.py +++ b/OneUploader.py @@ -3,7 +3,8 @@ from PIL import Image from rblxopencloud import exceptions from time import sleep, time -import random, io, threading, requests, json,string +from methods import do_method +import random, io, threading, requests, json CONFIG:json = json.load(open('config.json')) OUT:bool = CONFIG['save decals'] # Save decals/imgs to out.csv @@ -89,125 +90,10 @@ def run(thread_num:int, creator:DecalClass, barrier:threading.Barrier, buffer:io #if random.randint(0,1) == 1: rgba.transpose(Image.FLIP_LEFT_RIGHT) data = rgba.getdata() - newData = [] #METHOD = random.choice(["alpha","static","tstatic","shadow","light","test","test2"]) #print(METHOD) def rand(): return random.randint(-intensity,intensity) - match METHOD.lower(): - case "alpha": - newData = [ - ( - item[0] + rand(), - item[1] + rand(), # Used fo a tiny bit of static so that you can use this more than once - item[2] + rand(), - 255-a - ) for item in data - ] - - case "static": # WIP new method - # newData = [ - # ( - # item[0] + random.randint(-intensity, intensity), - # item[1] + random.randint(-intensity, intensity), - # item[2] + random.randint(-intensity, intensity), - # item[3], - # ) - # for item in data - # ] - square_size = 3 - width, height = rgba.size - static_image = Image.new('RGBA', (width, height)) - - for x in range(0, width, square_size): - for y in range(0, height, square_size): - static_color = (random.randint(0, 255), random.randint(0, 255), random.randint(0, 255)) - static_image.paste(static_color, (x, y, min(x + square_size, width), min(y + square_size, height))) - - data = Image.blend(rgba, static_image, 255/intensity) - newData = data.getdata() - - case "tstatic": - newData = [ - ( - item[0], - item[1], - item[2], - item[3] - random.randint(0, intensity), - ) - for item in data - ] - - case "shadow": - newData = [ - ( - item[0] + rand(), - item[1] + rand(), # Used fo a tiny bit of static - item[2] + rand(), - item[3] - (random.randint(250,255)-round((item[0]+item[1]+item[2])/3)), - ) - for item in data - ] - - case "light": - newData = [ - ( - item[0] + rand(), - item[1] + rand(), # Used fo a tiny bit of static - item[2] + rand(), - item[3] - (random.randint(250,255)-round(255-(item[0]+item[1]+item[2])/3)), - ) - for item in data - ] - - case "test": # WIP filter method - image = rgba - width, height = image.size - for y in range(height): - for x in range(width): - r, g, b, a = image.getpixel((x, y)) - r+=rand();g+=rand();b+=rand() - if y % 2 == 0: b = 0 - if y % 3 == 0 or x % 3 == 0: a = 0 - if x % 2 != 0: - image.putpixel((x, y), (0,g,b,a)) - else: - image.putpixel((x, y), (r,0,b,a)) - newData = image.getdata() - # rgba.show("owo") - - case "test2": # WIP filter method - image = rgba - width, height = image.size - count = 0 - for y in range(height): - for x in range(width): - r, g, b, a = image.getpixel((x, y)) - r+=rand();g+=rand();b+=rand() - count+=1 - if count == 1: - g,b = 0,0 - elif count == 2: - r,b = 0,0 - elif count == 3: - r,g = 0,0 - else: - r,g,b=0,0,0 - count=0 - - if y % 4 == 0 or x % 4 == 0: a = round((r+g+b)/3) - image.putpixel((x, y), (r,g,b,a)) - newData = image.getdata() - - case "default": # Sets a random pixel - for item in data: newData.append(item) - ran = random.randint(0, len(newData)) - newData[ran]=(random.randint(0,item[0]),random.randint(0,item[1]),random.randint(0,item[2]), item[3]) - - case _: # Default to random pixel - print('INVALID METHOD SET, DEFAULTING TO RANDOM COLOR (default) METHOD') - for item in data: newData.append(item) - ran = random.randint(0, len(newData)) - newData[ran]=(random.randint(0,item[0]),random.randint(0,item[1]),random.randint(0,item[2]), item[3]) + newData = do_method(METHOD,intensity,rgba) rgba.putdata(newData) diff --git a/methods.py b/methods.py new file mode 100644 index 0000000..24d46e7 --- /dev/null +++ b/methods.py @@ -0,0 +1,128 @@ + +from PIL import Image +import random + +def setupRand(intensity): + def randy(): + return random.randint(-intensity,intensity) + return randy + +#TODO: think about moving each method into a function to clean up +def do_method(METHOD:str,intensity:int,rgba): # sourcery skip: extract-duplicate-method, low-code-quality, use-itertools-product + newData = [] + rand = setupRand(intensity) + match METHOD.lower(): + case "alpha": + newData = [ + ( + item[0] + rand(), + item[1] + rand(), # Used fo a tiny bit of static so that you can use this more than once + item[2] + rand(), + 255-a + ) for item in data + ] + + case "static": # WIP new method + # newData = [ + # ( + # item[0] + random.randint(-intensity, intensity), + # item[1] + random.randint(-intensity, intensity), + # item[2] + random.randint(-intensity, intensity), + # item[3], + # ) + # for item in data + # ] + square_size = 3 + width, height = rgba.size + static_image = Image.new('RGBA', (width, height)) + + for x in range(0, width, square_size): + for y in range(0, height, square_size): + static_color = (random.randint(0, 255), random.randint(0, 255), random.randint(0, 255)) + static_image.paste(static_color, (x, y, min(x + square_size, width), min(y + square_size, height))) + + data = Image.blend(rgba, static_image, 255/intensity) + newData = data.getdata() + + case "tstatic": + newData = [ + ( + item[0], + item[1], + item[2], + item[3] - random.randint(0, intensity), + ) + for item in data + ] + + case "shadow": + newData = [ + ( + item[0] + rand(), + item[1] + rand(), # Used fo a tiny bit of static + item[2] + rand(), + item[3] - (random.randint(250,255)-round((item[0]+item[1]+item[2])/3)), + ) + for item in data + ] + + case "light": + newData = [ + ( + item[0] + rand(), + item[1] + rand(), # Used fo a tiny bit of static + item[2] + rand(), + item[3] - (random.randint(250,255)-round(255-(item[0]+item[1]+item[2])/3)), + ) + for item in data + ] + + case "test": # WIP filter method + image = rgba + width, height = image.size + for y in range(height): + for x in range(width): + r, g, b, a = image.getpixel((x, y)) + r+=rand();g+=rand();b+=rand() + if y % 2 == 0: b = 0 + if y % 3 == 0 or x % 3 == 0: a = 0 + if x % 2 != 0: + image.putpixel((x, y), (0,g,b,a)) + else: + image.putpixel((x, y), (r,0,b,a)) + newData = image.getdata() + + case "test2": # WIP filter method + image = rgba + width, height = image.size + count = 0 + for y in range(height): + for x in range(width): + r, g, b, a = image.getpixel((x, y)) + r+=rand();g+=rand();b+=rand() + count+=1 + if count == 1: + g,b = 0,0 + elif count == 2: + r,b = 0,0 + elif count == 3: + r,g = 0,0 + else: + r,g,b=0,0,0 + count=0 + + if y % 4 == 0 or x % 4 == 0: a = round((r+g+b)/3) + image.putpixel((x, y), (r,g,b,a)) + newData = image.getdata() + + case "default": # Sets a random pixel + for item in data: newData.append(item) + ran = random.randint(0, len(newData)) + newData[ran]=(random.randint(0,item[0]),random.randint(0,item[1]),random.randint(0,item[2]), item[3]) + + case _: # Default to random pixel + print('INVALID METHOD SET, DEFAULTING TO RANDOM COLOR (default) METHOD') + for item in data: newData.append(item) + ran = random.randint(0, len(newData)) + newData[ran]=(random.randint(0,item[0]),random.randint(0,item[1]),random.randint(0,item[2]), item[3]) + return newData \ No newline at end of file