Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- # pip install numpy Pillow
- import numpy as np
- from PIL import Image
- def ss(edge0, edge1, x):
- x = (x - edge0) / (edge1 - edge0)
- if x < 0:
- x = 0
- if x > 1:
- x = 1
- return x * x * (3 - 2 * x)
- def mmap(x, x0, x1):
- return x * (x1 - x0) + x0
- def f(x, y):
- xp = x / width
- yp = y / height
- l = ((0.5 - xp)**2 + (0.5 - yp)**2)**0.5
- l *= 2
- x = l
- res = 0
- # torch
- c0 = 0.15
- c1 = 0.45
- c2 = 0.45
- x0 = 0.9
- x1 = 0.5
- x2 = 0.2
- # flashlight
- c0 = 0.15
- c1 = 0.55
- c2 = 0.35
- x0 = 0.9
- x1 = 0.5
- x2 = 0.25
- res += mmap(ss(x0, 0, x), 0, c0)
- res += mmap(ss(x1, 0, x), 0, c1)
- res += mmap(ss(x2, 0, x), 0, c2)
- return int(255 * res), int(255 * res), int(255 * res)
- width, height = 256, 256
- image = Image.new("RGB", (width, height))
- pixels = []
- for y in range(height):
- for x in range(width):
- r, g, b = f(x, y)
- pixels.append((r, g, b))
- image.putdata(pixels)
- image.save("output_image.png")
- print("Image saved as output_image.png")
Advertisement
Add Comment
Please, Sign In to add comment