Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- width = 200
- height = 200
- passes = 10
- sample_diameter = 6
- import operator
- from datetime import datetime
- from PIL import Image, ImageDraw
- from math import sin, cos, hypot
- image = Image.new('RGB', (width, height), (0, 0, 0, 255))
- draw = ImageDraw.Draw(image, 'RGBA')
- for x in range(width * 300):
- y = int(round(sin(float(x)/20.0)*height/4.0+height/2.0))
- draw.point((x, y), fill=(255, int(round(255*cos(float(y)/50))), int(round(255*sin(float(x)/100))), 255))
- draw.line((0, height / 4, width, height / 2+1))
- draw.line((0, height / 4*3, width, height / 2+2))
- draw.line((0, height / 5*4, width, height / 2+3))
- def blur():
- tmp_image = Image.new('RGBA', (width, height), (0, 0, 0, 0))
- tmp_draw = ImageDraw.Draw(tmp_image, 'RGBA')
- for x in range(width):
- for y in range(height):
- pixel = image.getpixel((x, y))
- if pixel != (0, 0, 0):
- continue
- number_of_samples = 0
- sample_sum = (0, 0, 0)
- sample_radius = float(sample_diameter)/2.0
- xmin = max(0, int(round(x - sample_radius)))
- xmax = min(width, int(round(x + sample_radius)))
- ymin = max(0, int(round(y - sample_radius)))
- ymax = min(height, int(round(y + sample_radius)))
- smallest_value = (255, 255, 255)
- for sample_x in range(xmin, xmax):
- for sample_y in range(ymin, ymax):
- if hypot(sample_x-x, sample_y-y) > sample_radius:
- continue
- number_of_samples += 1
- sample_pixel = image.getpixel((sample_x, sample_y))
- if sum(sample_pixel) > 0 and sum(smallest_value) > sum(sample_pixel):
- smallest_value = sample_pixel
- sample_sum = tuple(map(operator.add, sample_sum, sample_pixel))
- if sample_sum != (0, 0, 0):
- c = (int(round(sample_sum[0] / float(number_of_samples) + float(smallest_value[0])/5)),
- int(round(sample_sum[1] / float(number_of_samples) + float(smallest_value[1])/5)),
- int(round(sample_sum[2] / float(number_of_samples) + float(smallest_value[2])/5)))
- tmp_draw.point( (x, y), fill=(c[0], c[1], c[2], 255) )
- image.paste(tmp_image, (0,0), tmp_image)
- print 'Started at ' + datetime.now().strftime("%Y-%m-%d %H:%M:%S")
- for i in range(passes):
- blur()
- image.show()
- image.save(datetime.now().strftime("glow_%Y-%m-%d_%H.%M.%S") + '.bmp')
- print 'Finished at ' + datetime.now().strftime("%Y-%m-%d %H:%M:%S")
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement