Advertisement
Guest User

Untitled

a guest
May 21st, 2020
435
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. #!/usr/bin/python3
  2.  
  3. from PIL import Image
  4. import blec
  5. import random
  6.  
  7. WHITE = (255, 255, 255, 255)
  8. BLUE = (0, 0, 255, 255)
  9. RED = (255, 0, 0, 255)
  10.  
  11. def to_1(color):
  12.     return tuple(x / 255 for x in color)
  13.  
  14. def to_255(color):
  15.     return tuple(int(round(x * 255)) for x in color)
  16.  
  17. def raw_color(name, color):
  18.     img = Image.new('RGB', (255, 100), color)
  19.     img.save(f'raw-color-{name}.png')
  20.  
  21. def blend_gradient(name, gamma):
  22.     img = Image.new('RGB', (255, 100), 'black')
  23.     pixels = img.load()
  24.     for i in range(255):
  25.         blue = (BLUE[0], BLUE[1], BLUE[2], i)
  26.         color = to_255(blec.blend(gamma, to_1(RED), to_1(blue)))
  27.         for j in range(100):
  28.             pixels[i, j] = color
  29.  
  30.     img.save(f'gamma-{name}.png')
  31.  
  32. def blend_gradient_white_blue(gamma):
  33.     img = Image.new('RGB', (255, 100), 'black')
  34.     pixels = img.load()
  35.     for i in range(255):
  36.         blue = (BLUE[0], BLUE[1], BLUE[2], i)
  37.         color = to_255(blec.blend(gamma, to_1(WHITE), to_1(blue)))
  38.         for j in range(100):
  39.             pixels[i, j] = color
  40.  
  41.     img.save(f'gradient-white-blue.png')
  42.  
  43. def blend_gradient_dithering():
  44.     img = Image.new('RGB', (255, 100), 'black')
  45.     pixels = img.load()
  46.     for i in range(255):
  47.         for j in range(100):
  48.             color = RED if i < random.randint(0, 255) else BLUE
  49.             pixels[i, j] = to_255(color)
  50.  
  51.     img.save(f'gradient-dithering.png')
  52.  
  53. def blend_two_colors(name, gamma):
  54.     half_blue = to_1(BLUE[:3]) + (0.5,)
  55.     color = blec.blend(gamma, to_1(RED), half_blue)
  56.     color = to_255(color)
  57.     img = Image.new('RGB', (100, 100), color)
  58.     img.save(f'two-colors-gamma-{name}.png')
  59.  
  60. def blend_two_colors_dithering():
  61.     img = Image.new('RGB', (100, 100), 'black')
  62.     pixels = img.load()
  63.     for i in range(100):
  64.         for j in range(100):
  65.             color = RED if 0.5 < random.uniform(0, 1) else BLUE
  66.             pixels[i, j] = to_255(color)
  67.  
  68.     img.save(f'two-colors-dithering.png')
  69.  
  70. raw_color('red', RED)
  71. raw_color('blue', BLUE)
  72. blend_gradient_white_blue(blec.PowerLaw(2.2))
  73. blend_gradient('srgb', blec.Srgb())
  74. blend_gradient('1', blec.PowerLaw(1))
  75. blend_gradient('1.4', blec.PowerLaw(1.4))
  76. blend_gradient('2.2', blec.PowerLaw(2.2))
  77. blend_gradient_dithering()
  78. blend_two_colors('1', blec.PowerLaw(1))
  79. blend_two_colors('2.2', blec.PowerLaw(2.2))
  80. blend_two_colors_dithering()
Advertisement
RAW Paste Data Copied
Advertisement