Advertisement
Guest User

mod generator

a guest
Mar 23rd, 2022
73
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Python 1.28 KB | None | 0 0
  1. from PIL import Image
  2. import glob, os
  3.  
  4.  
  5. def color_map(pixel):
  6.     R, G, B = pixel
  7.     brightness = (sum([R, G, B]) / 3) / 255  # 0.0 is dark, 1.0 is bright
  8.     new_pixel = gradient(brightness, (26, 20, 35), (171, 132, 118))
  9.     return new_pixel
  10.  
  11.  
  12. def gradient(factor, start_color, end_color):
  13.     r = start_color[0] + (end_color[0] - start_color[0]) * factor
  14.     g = start_color[1] + (end_color[1] - start_color[1]) * factor
  15.     b = start_color[2] + (end_color[2] - start_color[2]) * factor
  16.     return (int(r), int(g), int(b))
  17.  
  18.  
  19. def load_textures(dir):
  20.     images = []
  21.     for filename in glob.glob(dir):
  22.         im = Image.open(filename).convert('RGB')
  23.         images.append(im)
  24.     return images
  25.  
  26.  
  27. myGradient = ['#1A1423', '#684756', '#AB8476']
  28. root = 'C://Users//User//PycharmProjects//GradientMap'
  29. giga_filenames = os.listdir(root + '//input//giga')
  30. giga_textures = load_textures('input/giga/*.png')
  31.  
  32.  
  33. def main():
  34.     for i in range(0, len(giga_textures)):
  35.         img = giga_textures[i]
  36.         pixels = img.load()
  37.         for x in range(img.size[0]):
  38.             for y in range(img.size[1]):
  39.                 this_pixel = img.getpixel((x, y))
  40.                 pixels[x, y] = color_map(this_pixel)
  41.  
  42.         img.save('output/giga/' +  giga_filenames[i])
  43.  
  44. main()
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement