Skip to content

Commit

Permalink
more prettier code
Browse files Browse the repository at this point in the history
  • Loading branch information
judemont committed May 6, 2023
1 parent b263175 commit 3c719a4
Show file tree
Hide file tree
Showing 2 changed files with 77 additions and 61 deletions.
85 changes: 42 additions & 43 deletions .github/workflows/main.yml
Original file line number Diff line number Diff line change
Expand Up @@ -9,51 +9,50 @@ jobs:
build:
runs-on: ubuntu-latest
steps:
- name: Checkout code
uses: actions/checkout@v3
with:
ref: ${{ github.head_ref }} # checkout the correct branch name
fetch-depth: 0 # fetch the whole repo history
- name: Checkout code
uses: actions/checkout@v3
with:
ref: ${{ github.head_ref }} # checkout the correct branch name
fetch-depth: 0 # fetch the whole repo history

- name: Git Version
id: version
uses: codacy/git-version@2.7.1
with:
release-branch: main # default is master
prefix : v

- name: Git Version
id: version
uses: codacy/git-version@2.7.1
with:
release-branch: main # default is master
prefix: v

- name: Set up Python
uses: actions/setup-python@v2
with:
python-version: 3.x
- name: Set up Python
uses: actions/setup-python@v2
with:
python-version: 3.x

- name: Install PyInstaller
run: pip install pyinstaller
- name : requirements
run: pip install pillow image tk tqdm
- name: Build Binary
run: pyinstaller main.py --onefile
- name: Install PyInstaller
run: pip install pyinstaller
- name: requirements
run: pip install pillow image tk tqdm
- name: Build Binary
run: pyinstaller main.py --onefile

- name: Create Release
id: create_release
uses: actions/create-release@v1
env:
GITHUB_TOKEN: ${{ secrets.MY_TOKEN }}
with:
tag_name: ${{ steps.version.outputs.version }} # version tag to create
release_name: Ascii art generator ${{ steps.version.outputs.version }} # name of the release
body: 'New release : fixed bugs, new functionalitys, and more...' # description of the release
draft: false # set to true if you want to create a draft release instead of a published one
prerelease: false # set to true if this is a pre-release
- name: Create Release
id: create_release
uses: actions/create-release@v1
env:
GITHUB_TOKEN: ${{ secrets.MY_TOKEN }}
with:
tag_name: ${{ steps.version.outputs.version }} # version tag to create
release_name: Ascii art generator ${{ steps.version.outputs.version }} # name of the release
body: "New release : fixed bugs, new functionalitys, and more..." # description of the release
draft: false # set to true if you want to create a draft release instead of a published one
prerelease: false # set to true if this is a pre-release

- name: Upload Binary
id: upload-release-assets
uses: actions/upload-release-asset@v1
env:
GITHUB_TOKEN: ${{ secrets.MY_TOKEN }}
with:
upload_url: ${{ steps.create_release.outputs.upload_url }}
asset_path: ./dist/main # path to the binary file
asset_name: ascii-art-generator # name of the binary file in the release
asset_content_type: application/octet-stream # content type of the binary file
- name: Upload Binary
id: upload-release-assets
uses: actions/upload-release-asset@v1
env:
GITHUB_TOKEN: ${{ secrets.MY_TOKEN }}
with:
upload_url: ${{ steps.create_release.outputs.upload_url }}
asset_path: ./dist/main # path to the binary file
asset_name: ascii-art-generator # name of the binary file in the release
asset_content_type: application/octet-stream # content type of the binary file
53 changes: 35 additions & 18 deletions main.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,3 @@

#!/usr/bin/env python3
import argparse
from tkinter import *
Expand All @@ -9,7 +8,6 @@

def reduce_resolution(image_path, new_height):
with Image.open(image_path) as img:

width, height = img.size

reduction_factor = new_height / height
Expand All @@ -22,16 +20,14 @@ def reduce_resolution(image_path, new_height):


def convert2D(liste):

list2d = []

lines = []

ii = 0

for i in liste:

if ii >= im.width-1:
if ii >= im.width - 1:
ii = 0
list2d.append(lines)
lines = []
Expand All @@ -45,11 +41,16 @@ def convert2D(liste):


parser = argparse.ArgumentParser(
description='Transform an image into asciis characters.')
parser.add_argument('-p', '--picture',
help='Picture file to use.', required=True)
description="Transform an image into asciis characters."
)
parser.add_argument("-p", "--picture", help="Picture file to use.", required=True)
parser.add_argument(
'-he', '--height', help='Ascii art result height (In numbers of characters)', required=False, default=500)
"-he",
"--height",
help="Ascii art result height (In numbers of characters)",
required=False,
default=500,
)
args = parser.parse_args()


Expand All @@ -63,20 +64,36 @@ def convert2D(liste):
pixelles = convert2D(list(im.getdata()))


CHARS = ['ㅤㅤㅤ', '+++', '***', '===', '%%%', '###', '@@@', '&&&',
'$$$', 'MMM', 'WWW', '888', '▌▌▌', '▬▬▬', '▒▒▒', '███', '▓▓▓']
CHARS = [
"ㅤㅤㅤ",
"+++",
"***",
"===",
"%%%",
"###",
"@@@",
"&&&",
"$$$",
"MMM",
"WWW",
"888",
"▌▌▌",
"▬▬▬",
"▒▒▒",
"███",
"▓▓▓",
]


result = ""

test = 0

for i in tqdm(range(0, len(pixelles)), desc="Loading..."):

result += "\n"

for ii in range(0, len(pixelles[i])):
result += CHARS[int(pixelles[i][ii]//(256/len(CHARS)))]
result += CHARS[int(pixelles[i][ii] // (256 / len(CHARS)))]


root = Tk()
Expand All @@ -93,18 +110,18 @@ def convert2D(liste):

text = Text(root, height=im.height, wrap=NONE)
text.grid(row=0, column=0, sticky=EW)
text.config(font=('Helvetica bold', 1))
text.config(font=("Helvetica bold", 1))


scrollbarVert = Scrollbar(root, orient='vertical', command=text.yview)
scrollbarVert = Scrollbar(root, orient="vertical", command=text.yview)
scrollbarVert.grid(row=0, column=1, sticky=NS)


scrollbarHor = Scrollbar(root, orient='horizontal', command=text.xview)
scrollbarHor = Scrollbar(root, orient="horizontal", command=text.xview)
scrollbarHor.grid(row=1, column=0, sticky=EW)

text['yscrollcommand'] = scrollbarVert.set
text['xscrollcommand'] = scrollbarHor.set
text["yscrollcommand"] = scrollbarVert.set
text["xscrollcommand"] = scrollbarHor.set


text.insert(1.0, result)
Expand Down

0 comments on commit 3c719a4

Please sign in to comment.