-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathlyapunov.py
52 lines (40 loc) · 1.12 KB
/
lyapunov.py
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
from PIL import Image
import math
rez = 2000
im = Image.new(mode="RGB", size=(88, rez))
maxIter = 10**2
aRange = [2,4]
bRange = [2,4]
def lyExp(a,b):
global maxIter
r = a
total = 0
xn = .5
for x in range(1, maxIter):
if xn != .5:
total += math.log(abs(r*(1-(2*xn))))
xn = r*xn*(1-xn)
if r == a:
r = b
else:
r = a
return (1/maxIter)*total
def getColor(n):
if n == 0:
return (0,0,0)
if n < 0:
return (int((n*150+255)), int((n*150+255)), 0)
elif n > 0:
return (0, 0, int((n*150+255)))
pixles = im.load()
count = 1
for i in range(1,im.size[1]+1):
for j in range(1,im.size[0]+1):
a = (i/im.size[0])*(aRange[1]-aRange[0])+aRange[0]
b = (j/im.size[1])*(bRange[1]-bRange[0])+bRange[0]
xp = lyExp(a,b)
print((count/(im.size[0]*im.size[1]))*100)
pixles[i-1, im.size[0]+1 - j-1] = getColor(xp)
count += 1
im.save("lyapunov[" + str(aRange[0]) + "," + str(aRange[1]) + "]x[" + str(bRange[0]) + "," + str(bRange[1]) + "]_resolution" + str(rez) + ".png")
im.show()