FazBrowse GitHub Viewer
|
Trending
|
URL:
|
Home
Tools:
[Download Repo ZIP]
[View Raw Code]
[Original HTTPS Page]
python/pythonchallenge/33.py at master · bjd1111/python · GitHub
bjd1111
python
Repository navigation
Code
Issues
Pull requests
Actions
Projects
Security and quality
Insights
Expand file tree
Breadcrumbs
python
/
pythonchallenge
/
33.py
Copy path
More file actions
More file actions
Latest commit
History
History
History
26 lines (24 loc) · 986 Bytes
Breadcrumbs
python
/
pythonchallenge
/
33.py
Copy path
File metadata and controls
26 lines (24 loc) · 986 Bytes
Raw
Copy raw file
Download raw file
Open symbols panel
Edit and raw actions
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
# -*- coding: UTF-8 -*-
import
Image
import
math
beer
=
Image
.
open
(
'beer2.png'
)
#获取颜色信息
colors
=
beer
.
getcolors
()
colors_len
=
len
(
colors
)
data
=
list
(
beer
.
getdata
())
colors_index
=
colors_len
-
1
while
colors_index
>
0
:
#创建一幅新的图片,以像素数总数的开平方数为长宽值
dim
=
math
.
sqrt
(
len
(
data
))
new_img
=
Image
.
new
(
'1'
, (
int
(
dim
),
int
(
dim
)))
#把所有以最大颜色值为颜色参数的像素点标记为‘亮’,其余像素点标记为‘暗’
output
=
[
item
==
colors
[
colors_index
][
1
]
for
item
in
data
]
new_img
.
putdata
(
output
)
new_img
.
save
(
'level33_%d.png'
%
(
colors_index
/
2
))
#抛弃颜色值最大的一组颜色,并且抛弃使用这些颜色的像素
eli_color_a
=
colors
.
pop
(
colors_index
)[
1
]
eli_color_b
=
colors
.
pop
(
colors_index
-
1
)[
1
]
for
k
in
xrange
(
len
(
data
)
-
1
,
-
1
,
-
1
):
if
data
[
k
]
==
eli_color_a
or
data
[
k
]
==
eli_color_b
:
data
.
pop
(
k
)
colors_index
-=
2
Back
|
FazBrowse Home
|
New Git URL