As the title says, I was thinking to contest in which one must detect edges of an ASCII art.
The code should accept a B/W ASCII art as input.
A B/W ASCII art is defined as (by me) an ASCII art with only one kind of non-white-spaces character (in our case: an asteriks *
). And as output produce a standard ASCII art (all ASCII characters are accepted) which should remember the contourn of the first.
The purpose of using more than one character in the output is to make some edges ssmoother. For instance, one could let this input
***
****
******
******
******
******
****
***
could became:
___
_/ )
_/ /
/ |
| /
| \
\ |
`\ |
\___)
The input \n
separated string as input. Each line has a maximum of 80
characters. The number of rows is not specified.
This is my sample Python3 program:
import fileinput as f
import re as r
import copy as c
a,s,p='*',' ','+'
def read(n):
s=[list(' '*n)]
for l in f.input():
if(len(l)>n):l=l[:n]
k=list(r.sub('[^ ^\%c]'%a,'',' '+l+' '))
s.append(k+[' ']*(n-len(k)))
s.append([' ']*n)
return s
def np(s):
s=c.deepcopy(s)
for l in s[1:-1]:
for w in l[1:-1]: print(w,end='')
print()
def grow(i):
o=c.deepcopy(i)
for x in range(1,len(o)-1):
for y in range(1,len(o[x])-1):
if(i[x][y]==a): o[x-1][y-1]=o[x-1][y+1]=o[x-1][y]=o[x+1][y]=o[x+1][y-1]=o[x+1][y+1]=o[x][y+1]=o[x][y-1]=a
return o
def diff(i,o):
c=[]
for x in range(0,len(i)):
l=[]
for y in range(0,len(i[x])):
if(i[x][y]==a and o[x][y]==s): l.append(p)
else: l.append(s)
c.append(l)
return c
I=read(80)
np(diff(grow(I),I))
Input:
Here below I put both input of the programs. It is an 80x70 ASCII ART. It means it has 70 lines of 80 characters, each separated by \n
.
This input file contains only spaces and the asterisk *
, it has a maximum of 80 columns as every ASCII art.
If you find a nicer art let me know!
*************
***** *****
****** ***
*** ****
********* **
*********** **
****** ******* **
***** ******* *** **
**** ******** ***** *
** ********* ***** ***** *
*** ********* ******* ****** **
** ********** ******* ****** **
** ********** ******* ******** *
* *********** ****** ******** *
** ************ ***** ******** *
* ************ *** ******** *
* ************* ****** *
* ************* *** *
** ************* *
* ************** *
** ************* **
* ************* **
** ************* ***
*** ************* ****
** ************ ****
** ************* ****
** ************* ***** ****
** ************* ** ** ** ****
** ************ * * ** ** ****
* ************ ** ** ** ** ****
* ************* ******* ** *** ****
* ************ ***** ******* ****
* ************ *** ***** ****
** * ************* **** *****
** *** ************** *****
* ***** ************* ******
** ******* ************** *******
********** *************** * *********
********** ***************** *** ***********
*********** ******************* **************
*********** ********************** ******************
************ ***************** ** ***********************
************* ****************** **** *******************
************** ****************** ********************
**************** ****************** *******************
*************** ******************* *******************
**************** ****************** ******************
****************** ****************** *******************
******************* ***************** *******************
********************* ****************** ********************
********************************************* *********************
********************************************** ***********************
************************ ***************** ************************
********************** ******************* **************************
********************* *********************************************
********************* **************************** ***************
******************** ************************** ***************
******************** ********************* ***************
******************* ******************** ****************
****************** ***************** ****************
***************** **************** ***************
***************** **************** ***************
***************** ***************** ***************
**************** ***************** ***************
************** ****************** ***************
**************** ****************
************** ***************
**************
************
Possible output:
A possible output could be:
+++++ ++++
++++++ ++++++++++ +++
++ +++++ +++++ +++++
++++++++ +++++ ++++ ++
++++ ++ ++++ ++
++++++ ++ ++ ++
+++++ +++ + +++++ ++ ++
++++ +++++++ ++ ++ ++ ++ ++
++ +++++ ++ + + + +++++++ ++
+++ ++++ ++ + ++ ++ ++ ++ ++
++ ++ ++ ++ + + + ++ ++
++ +++ + + ++ + ++ +++ +
++ ++ ++ + ++ ++ + +++ +
++ +++ ++ + + +++ + + + ++
+ + + + + ++ + ++++ +
++ ++ ++ + ++ ++ ++ + + +
++ ++ + + +++++ ++ ++ + +
++ ++ + + +++ ++ + +
+ + ++ + +++++ + +
++ ++ + + ++ +
+ + + ++ + +
++ ++ ++ + + ++
++ + + ++ + ++
+ + + + + +
+ ++ ++ ++ + +
+ + + + +++++++ + +
+ + + + ++ ++ ++++ + +
+ + + + + +++ + ++ +++ + +
+ + ++ + + ++ ++ + ++ + ++ + +
+ ++ + ++ ++ +++ + + +++ ++ + +
+ + + + + ++ + +++ + + +
+ + + ++ ++ ++ ++ + + +
+ + +++ ++ ++ + +++ +++ + ++ +
+ ++ ++ + ++ +++++ + ++ ++ +
+ ++ ++ + + ++++++ ++ ++
++++ + ++ +++ ++ +
+ + ++ ++ +++ +++ +
+ + ++++ ++ ++ +++ +
++ ++ ++++ + + ++++ +
+ ++ +++++ +++++ +++++ +
++ ++ +++ ++++++ +
++ + +++++ +++++ +
++ + + +++ +++++ +
+++ + ++ ++++++ + +
+ ++ + ++ +
++ + + + +
+++ ++ + ++ ++
++ + + + +
+++ ++ + +++ +
++++++ + ++ ++
++ +++ +
+ ++ +
+++++ ++++++ +
+ ++ ++ + +
+ ++ + ++
+ + + ++ +
+ ++ + ++++ +
+ + + ++++++ ++ +
+ ++ + ++ + +
+ ++ + ++++ + +
+ ++ ++ + + ++
+ + + ++ + +
+ + + + + +
++ + + ++ + +
++ ++ + + + ++
++++++++++++++++ +++ + + +
++ ++ ++ +
++++++++++++++++ ++ +
++ ++
++++++++++++++
This is also the output produced by the script above. Of course it is not the best output and I'm sure one can easily produce a smoother one.
It is a popularity-contest since, I hope votes will be proportional to elegance and quality of outputs! (Also I guess good results acan be obtained combinig aplay
and gimp-cli
)
There are no strict rules on how the output should be..just use your fantasy!