Guest User

Untitled

a guest
Nov 18th, 2024
389
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Python 1.09 KB | None | 0 0
  1. # pip install numpy Pillow
  2.  
  3. import numpy as np
  4. from PIL import Image
  5.  
  6. def ss(edge0, edge1, x):
  7.     x = (x - edge0) / (edge1 - edge0)
  8.     if x < 0:
  9.         x = 0
  10.     if x > 1:
  11.         x = 1
  12.     return x * x * (3 - 2 * x)
  13.  
  14. def mmap(x, x0, x1):
  15.     return x * (x1 - x0) + x0
  16.  
  17. def f(x, y):
  18.     xp = x / width
  19.     yp = y / height
  20.  
  21.     l = ((0.5 - xp)**2 + (0.5 - yp)**2)**0.5
  22.     l *= 2
  23.     x = l
  24.     res = 0
  25.  
  26.     # torch
  27.     c0 = 0.15
  28.     c1 = 0.45
  29.     c2 = 0.45
  30.     x0 = 0.9
  31.     x1 = 0.5
  32.     x2 = 0.2
  33.  
  34.     # flashlight
  35.     c0 = 0.15
  36.     c1 = 0.55
  37.     c2 = 0.35
  38.     x0 = 0.9
  39.     x1 = 0.5
  40.     x2 = 0.25
  41.  
  42.     res += mmap(ss(x0, 0, x), 0, c0)
  43.     res += mmap(ss(x1, 0, x), 0, c1)
  44.     res += mmap(ss(x2, 0, x), 0, c2)
  45.  
  46.     return int(255 * res), int(255 * res), int(255 * res)
  47.  
  48. width, height = 256, 256
  49. image = Image.new("RGB", (width, height))
  50.  
  51. pixels = []
  52. for y in range(height):
  53.     for x in range(width):
  54.         r, g, b = f(x, y)
  55.         pixels.append((r, g, b))
  56.  
  57. image.putdata(pixels)
  58.  
  59. image.save("output_image.png")
  60. print("Image saved as output_image.png")
  61.  
Advertisement
Add Comment
Please, Sign In to add comment