Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

initial #3

Open
wants to merge 3 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Binary file added 1.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
60 changes: 19 additions & 41 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,52 +1,30 @@
# 스포카 코드 챌린지 2019
$ python main.py

안녕하세요. 스포카 코드 챌린지 2019 에 참여해주셔서 감사합니다. 스포카 코드 챌린지 2019는 주식회사 스포카에서 [파이콘 행사][0]를 맞아 파이썬 개발자 여러분을 위해 준비한 이벤트입니다.

## 주제

### `CONNECT THE PYTHONISTAS` 라는 문구가 담긴 결과물
* `CONNECT THE PYTHONISTAS` 라는 문구가 들어간 결과물을 만들어주세요.
```

![image](https://user-images.githubusercontent.com/22957868/61261228-18023980-a7bc-11e9-8c61-3fb684179e2d.png)
* 게임, 랜덤 이미지, 웹, 앱 등등 위 문구가 표시되면 어떤 결과물도 상관없습니다.

## 규칙
... ... ...
.=%##%#: -%%#%#- *@#. *@.=@#. +@.=@%###=.+%##%*.*#%@%#+
=@= .=:-@+ .*@:*@#%:*@.+@#%:+@:=@*===.+@- .=: =@-
=@= .+=-@+ .*@:*@.+@%@.+@:=@#@:=@+---.+@- .*- =@-
.=%##%#. =%%#%#- *@. -@@.=@: :%@.=@%###=.+%##%*. =@-
... ... ...

* 파이썬 3.x 이상에서 동작하는 파이썬 프로그래밍 (단, 버전을 명시해주세요)
* 화면에 표현하는 방법은 자유 (웹 / 앱/ PyQt 등등)
* 위에 적힌 사항들은 최소 조건이며, 어떠한 방식으로 구현, 표현하셔도 괜찮습니다. 여러분의 창의력을 환영합니다!
* 제출 기한은 8월 18일 오후 5시까지입니다.
:-----::-. :-..-----:
==#@*=-+@- *@:=@*===:
+@- +@%##@@:=@%###.
+@- +@- *@:=@=....
-*: =*: =*.-*****=

## 참여 방법

* 이 저장소를 포크(Fork)해서 자유롭게 구현해주세요.
* 구현이 다 끝나셨으면 다시 이 저장소로 풀 리퀘스트(Pull Request)를 제출해주시면 됩니다.
* 포크, 풀 리퀘스트 등의 개념에 익숙하지 않으시다면 [이 글][1] 을 참고해보세요.
* 상품 전달을 위해 연락 받으실 이메일 또는 연락처, 참여하신 Pull Request 링크를 [email protected]로 제출해주세요.
.****+:-*= -*=******:*+ .*= .=*#*+. :*+. :*::*- -*#*+:-*****+ :*+. :+##*-
:@+.:#@.=@++@+.::@@::.@%..:@#.#%-.:*@:-@@#.-@-:@+.@#::++.:-@*::.%#@+ %@-.=*.
:@%##%= -@@- %% @@***@#.@* -@+-@=*%+@-:@+ -+*%%*. :@* .*@-*@- :+*#@#.
:@+ %% %% @% .@# +@+-=%%.-@-.+@@-:@+-@*--#%. :@* =@+++#@:%#--*@-
.-: -- -- -- .-: .-==:. .-. :-..-: .-==-. .-:.-- .-:.-==-.

## 채점 기준

* 최대한 독창적이고 화려한 결과물이 나오도록 구현해 주세요.
* 얼마나 독창적이고 화려한 결과물인가가 주된 평가 기준입니다.
* 파이썬 언어에 대한 이해도 또한 주요 평가 기준입니다.
* 따라서 채점은 전적으로 평가자의 주관적인 판단에 근거합니다. 자세한 평가 기준은 수상작 발표 때 공개하도록 하겠습니다.
* Pull request에 달린 리액션 수 또한 평가에 반영됩니다.


## 상품 안내 및 수상작 발표

### 참여상

* 모든 참여자에게는 참여상이 있을 예정입니다.
* 참여하신 분들은 스포카 부스로 찾아와서 참여하신 GitHub ID를 말씀해주세요!

### 우수상

* 수상작 목록은 2019년 8월 30일 [스포카 기술 블로그][2]에서 공개됩니다.
* 총 수상자는 2명입니다.
* 수상자에게는 상품이 증정될 예정입니다.
* 행사 참여는 누구나 가능하지만 수상자는 PyCon 2019 참가자로 제한합니다.

[0]: https://www.pycon.kr/
[1]: https://help.github.com/articles/using-pull-requests/
[2]: https://spoqa.github.io/
```
101 changes: 101 additions & 0 deletions main.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,101 @@
# Python code to convert an image to ASCII image.
import sys, random, argparse
import numpy as np
import math

from PIL import Image


# ref. https://www.geeksforgeeks.org/converting-image-ascii-image-python/

gscale = '@%#*+=-:. '

def getAverageL(image):
"""
Given PIL Image, return average value of grayscale value
"""
# get image as numpy array
im = np.array(image)

# get shape
w,h = im.shape

# get average
return np.average(im.reshape(w*h))


def covertImageToAscii(fileName, cols, scale):
"""
Given Image and dims (rows, cols) returns an m*n list of Images
"""

# open image and convert to grayscale
image = Image.open(fileName).convert('L')

# store dimensions
W, H = image.size[0], image.size[1]

# compute width of tile
w = W/cols

# compute tile height based on aspect ratio and scale
h = w/scale

# compute number of rows
rows = int(H/h)

# ascii image is a list of character strings
aimg = []
# generate list of dimensions
for j in range(rows):
y1 = int(j*h)
y2 = int((j+1)*h)

# correct last tile
if j == rows-1:
y2 = H

# append an empty string
aimg.append("")

for i in range(cols):

# crop image to tile
x1 = int(i*w)
x2 = int((i+1)*w)

# correct last tile
if i == cols-1:
x2 = W

# crop image to extract tile
img = image.crop((x1, y1, x2, y2))

# get average luminance
avg = int(getAverageL(img))

# look up ascii char
gsval = gscale[int((avg*9)/255)]

# append ascii char to string
aimg[j] += gsval

# return txt image
return aimg


def main():
imgFile = "1.png"
scale = 0.5
cols = 80

aimg = covertImageToAscii(imgFile, cols, scale)

for row in aimg:
print(row)

# call main
if __name__ == '__main__':
main()


4 changes: 4 additions & 0 deletions requirements.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
numpy==1.17.0
Pillow==6.1.0
pyspark==2.3.0
wheel==0.26.0