File tree Expand file tree Collapse file tree 2 files changed +106
-0
lines changed Expand file tree Collapse file tree 2 files changed +106
-0
lines changed Original file line number Diff line number Diff line change
1
+ #-*- coding:utf-8 -*-
2
+ '''
3
+ Created on 2017年5月9日
4
+
5
+ @author: huangjiaxin
6
+ '''
7
+ import csv
8
+ from PIL import Image
9
+ import numpy as np
10
+
11
+ def test1 ():
12
+ data = np .genfromtxt ('yankeedoodle.csv' , delimiter = ',' )
13
+ data = data [:, :- 1 ]
14
+ data = data .reshape ((- 1 ,))
15
+ data = data [:- 1 ]
16
+ data = data .reshape ((139 , 53 )).transpose ().reshape ((- 1 ,))
17
+
18
+ im = Image .new ('L' , (139 , 53 ))
19
+ im .putdata (data * 255 )
20
+ im .show ()
21
+
22
+ data = data .reshape ((53 , 139 )).transpose ().reshape ((- 1 ,))
23
+ data_str = ["%.5f" % i for i in data ]
24
+ msg = []
25
+ for i in range (0 , 7365 , 3 ):
26
+ msg .append (chr (int (data_str [i ][5 ] + data_str [i + 1 ][5 ] + data_str [i + 2 ][6 ])))
27
+ print '' .join (msg )
28
+
29
+
30
+ def test2 ():
31
+ tempList = []
32
+ tempSList = []
33
+ with open ('yankeedoodle.csv' , 'rb' ) as f :
34
+ file = csv .reader (f )
35
+ for row in file :
36
+ if row [- 1 ] == '' :
37
+ tempList += [float (x ) for x in row [:- 1 ]]
38
+ tempSList += row [:- 1 ]
39
+ else :
40
+ tempList += [float (x ) for x in row [:]]
41
+ tempSList += row [:]
42
+ tempArray = np .array (tempList ).reshape (139 , 53 )
43
+ im = Image .new ('L' , (53 , 139 ))
44
+ im .putdata (tempArray )
45
+ im .show ()
46
+
47
+ print len (tempSList )
48
+ msg = []
49
+ for i in range (0 , 7365 , 3 ):
50
+ msg .append (chr (int (tempSList [i ][- 2 ] + tempSList [i + 1 ][- 2 ] + tempSList [i + 2 ][- 1 ])))
51
+ print '' .join (msg )
52
+
53
+
54
+ if __name__ == '__main__' :
55
+ test2 ()
Original file line number Diff line number Diff line change
1
+ #-*- coding:utf-8 -*-
2
+ '''
3
+ Created on 2017年5月10日
4
+
5
+ @author: huangjiaxin
6
+ '''
7
+ from PIL import Image
8
+ import numpy as np
9
+
10
+ def mapIdx (c , maxIter = 128 ):
11
+ z = 0
12
+ for k in range (maxIter ):
13
+ z = z * z + c
14
+ if np .abs (z ) > 2 :
15
+ break
16
+ return k
17
+
18
+ def solve ():
19
+ left = 0.34
20
+ bottom = 0.57
21
+ width = 0.036
22
+ height = 0.027
23
+
24
+ im = Image .open ('mandelbrot.gif' )
25
+ imdata = np .array (list (im .getdata ()))
26
+ im_w , im_h = im .size
27
+ dw = width / im_w
28
+ dh = height / im_h
29
+ xx = np .linspace (left , left + width - dw , im_w )
30
+ yy = np .linspace (bottom , bottom + height - dh , im_h )
31
+ yy = yy [::- 1 ]
32
+ xx .shape = (1 , im_w )
33
+ yy .shape = (im_h , 1 )
34
+ grids = xx + 1j * yy
35
+
36
+ for i in range (im_h ):
37
+ for j in range (im_w ):
38
+ grids [i , j ] = mapIdx (grids [i , j ])
39
+
40
+ im .putdata (grids .reshape ((- 1 ,)))
41
+ # im.show()
42
+
43
+ imdata .shape = (480 , 640 )
44
+ diffs = imdata - grids
45
+ msg = diffs [np .where (np .abs (diffs ) == 16 )]
46
+ newIm = Image .new ('1' , [23 , 73 ])
47
+ newIm .putdata ([i < 0 for i in msg ])
48
+ newIm .save ('level31_out.png' )
49
+
50
+ if __name__ == "__main__" :
51
+ solve ()
You can’t perform that action at this time.
0 commit comments