Advertisement
Guest User

Hide flags in other flags using gamma

a guest
Feb 23rd, 2021
62
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Python 1.40 KB | None | 0 0
  1. import functools
  2. import numpy as np
  3. from scipy.optimize import root_scalar
  4. from PIL import Image
  5.  
  6. trans_flag = [[91, 206, 250],[245, 169, 184],[255, 255, 255],[245, 169, 184],[91, 206, 250]]
  7.  
  8. def parse_flag(s):
  9.     r=[]
  10.     for w in s.split():
  11.         c=[]
  12.         for i in range(3):
  13.             c.append(int(w[i*2:i*2+2],16))
  14.         r.append(c)
  15.     return r
  16.  
  17. demigirl_flag = parse_flag('7f7f7f c3c3c3 ffaec9 ffffff ffaec9 c3c3c3 7f7f7f')
  18.  
  19. @functools.lru_cache()
  20. def solve_color(y, z, i):
  21.     sy = y / 255
  22.     sz = z / 255
  23.     x = root_scalar((lambda x:x**2.2+(2*sy-x)**2.2-2*sz), x0=0.5, x1=0.7)
  24.     x = int(round(255*min(1,max(0,x.root))))
  25.     if i:
  26.         x = max(0,min(255,2*y-x))
  27.     return x
  28.  
  29. def gamma_flag(lx, ly, fp, stripes_y, stripes_z, desat_y, desat_z):
  30.     stripes_y = np.array(list(map(list, stripes_y)))
  31.     stripes_z = np.array(list(map(list, stripes_z)))
  32.     stripes_y = np.array(stripes_y+(127-stripes_y)*desat_y,np.uint8)
  33.     ztg=255*(np.mean(stripes_y)/255)**2.2
  34.     stripes_z = np.array(stripes_z+(ztg-stripes_z)*desat_z,np.uint8)
  35.     ny = stripes_y.shape[0]
  36.     nz = stripes_z.shape[0]
  37.     pix = np.zeros((ly, lx, 3), dtype=np.uint8)
  38.     for y in range(ly):
  39.         sy = stripes_y[y*ny//ly]
  40.         sz = stripes_z[y*nz//ly]
  41.         for x in range(lx):
  42.             f = (x+y)&1
  43.             for j in range(3):
  44.                 pix[y][x][j] = solve_color(sy[j], sz[j], f)
  45.     im = Image.fromarray(pix)
  46.     im.save(fp)
  47.  
  48. gamma_flag(1536, 1024, 'gamma_trans_demigirl.png', trans_flag, demigirl_flag, 0.93,0.86)
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement