-
Notifications
You must be signed in to change notification settings - Fork 3
Expand file tree
/
Copy pathGen_InterferenceImage.py
More file actions
60 lines (52 loc) · 1.65 KB
/
Copy pathGen_InterferenceImage.py
File metadata and controls
60 lines (52 loc) · 1.65 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
# @abrightmoore
from math import sqrt, tan, sin, cos, pi, ceil, floor, acos, atan, asin, degrees, radians, log, atan2
import os
import time
from random import randint, random, Random
import io
from io import BytesIO
import sys
from PIL import Image, ImageDraw
from Colours import *
def draw(img):
makeInterferenceImage(img)
return img
def makeInterferenceImage(img):
width = img.size[0]
height = img.size[1]
P = []
numPoints = randint(1,17)
theRange = (width+height) ** 2
for i in xrange(0,numPoints):
scale = randint(8,1280)
P.append((random()*pi*2.0,randint(0,theRange),random(),random()*scale))
if random() < 0.2:
P.append((random()*pi*2.0,randint(0,width>>2),random(),random()*scale))
# C = getComplementaryColours(randint(3,128))
C = []
chance = randint(1,10)
if chance == 1:
C = getRandomAnalogousColours()
elif chance == 2:
C = getRandomComplementaryColours()
else:
C = getColoursBrownian(randint(16,64),randint(4,16))
# render the image
pixels = img.load()
for x in xrange(0,width):
for y in xrange(0,height):
contribution = 0.0
for (ang,dist,amp,wavelength) in P:
ox = dist*cos(ang)
oy = dist*sin(ang)
dx = ox - x
dy = oy - y
d = sqrt(dx**2+dy**2)
contribution = contribution + amp*cos(d/wavelength)
size = contribution*float(len(C))
#print size
(r1,g1,b1) = C[int(abs(float(size)))%len(C)]
(r2,g2,b2,a) = pixels[x,y]
# print r1,g1,b1,r2,g2,b2,a
pixels[x,y] = ((r1+r2)>>1,(g1+g2)>>1,(b1+b2)>>1,a)
#print pixels[x,y]