[Lugge] Re: domanda OT

  • From: "Roberto J. Vichi" <roberto.vichi@xxxxxxxxxxxxxxx>
  • To: LUGGe <lugge@xxxxxxxxx>
  • Date: Fri, 19 Sep 2003 11:35:26 +0200

Andrea C wrote:

Vi volevo chiedere se sapete dove reperire un programma per fare disegni in ASCII ?

Purtroppo non ricordo esattamente la fonte, ma se cerchi con Google circa ascii art o cose simili trovi parecchio.
Il sorgente in allegato richiede la libreria Allegro.


Allego anche un esempio di elaborazione (non vogliatemene), tanto per far vedere cosa genera.

personale nel settore informatico, sapete sono in cerca di lavoro, molti di voi si incazz..... perchè diranno che questa lista nn è un ufficio di collocamento (perdonatemi).

A parer mio, non c'è niente di male, ma per una voce autorevole, senti i gestori della lista. ;)
--
J5 -=(aka Roberto)=- [http://www.rossomaltese.it/]


-----BEGIN GEEK CODE BLOCK-----
Version: 3.12
GCS/IT/O d++(-) s:+>: a34 C++$ ULAVH*++$>++++ P+ L+>++++ E--- W++(-) N(++)
o? K-? w(---) !O M@ V@ PS+@ PE- Y? PGP->++ t+++ 5? X++ R tv+ b+ DI(+)
D++(---) G(-)>-- e>++++ h---() r++ y+++*
------END GEEK CODE BLOCK------
/*

ascii art conversion utility
Copyright 2001 Damian Yerrick

Permission is hereby granted, free of charge, to any person obtaining
a copy of this software and associated documentation files (the
"Software"), to deal in the Software without restriction, including

without limitation the rights to use, copy, modify, merge, publish,
distribute, sublicense, and/or sell copies of the Software, and to
permit persons to whom the Software is furnished to do so, subject to
the following conditions:

The above copyright notice and this permission notice shall be
included in all copies or substantial portions of the Software.

THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES
OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS
BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN
AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF
OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS
IN THE SOFTWARE.

*/
/*

ascii.c converts a bitmap (in .bmp or .pcx format) to ASCII art.
It treats the least significant bitplane as a monochrome image,
making 0 dark and 1 light.  Each character sent to stdout represents
a 2x2 cell in the bitmap.

It uses the Allegro library to read the bitmap.  Allegro is a
multimedia library that has been ported to POSIX+X11, DOS, Windows,
BeOS, and Mac OS.  There are library extensions that allow Allegro
to handle other file formats such as PNG.
  http://alleg.sourceforge.net/allegro/

Because of the simple design of the program, it is also extremely
easy to port to other imaging APIs.

Compilation on DOS:
  gcc -Wall -O ascii.c -lalleg -o ascii.exe
Compilation on Linux:
  gcc -Wall -O ascii.c `allegro-config --libs` -o ascii

*/

#include <allegro.h>
#include <stdio.h>
#include <stdlib.h>

/* the following characters' glyphs represent 2x2 pixel tiles */
const char tiles[16] =
{
  'M', 'P', 'V', '"',
  'b', ')', '\\','\'',
  'd', '/', '(', '`',
  'a', '.', ',', '"'
};

int main(int argc, char **argv)
{
  BITMAP *bmp;
  int y;

  install_allegro(SYSTEM_NONE, &errno, atexit);

  if(argc != 2)
  {
    allegro_message("usage: ascii foo.bmp\n");
    return EXIT_FAILURE;
  }

  /* if you've installed Allegro library extensions for
     other bitmap formats, register their functions here */

  bmp = load_bitmap(argv[1], NULL);
  if(bmp == NULL)
  {
    allegro_exit();


    fprintf(stderr, "ascii Error: could not load bitmap `%s'\n", argv[1]);
    return EXIT_FAILURE;
  }

  for(y = 0; y < bmp->h; y += 2)
  {
    int x;
    for(x = 0; x < bmp->w; x += 2)
    {
      int c = 0;
      if(getpixel(bmp, x,   y  ) & 1)
        c |= 8;
      if(getpixel(bmp, x+1, y  ) & 1)
        c |= 4;
      if(getpixel(bmp, x,   y+1) & 1)
        c |= 2;
      if(getpixel(bmp, x+1, y+1) & 1)
        c |= 1;
      putchar(tiles[c]);
    }
    putchar('\n');
  }
  destroy_bitmap(bmp);

  return EXIT_SUCCESS;
}
/* Allegro uses this to translate main() into a WinMain() for some ports */
//END_OF_MAIN();

Windows bitmap

'''`","'\`,`)P`"'`"'`"'`""``"`""``"`""``"`""``"`""``"`""`"',.''("
"',``",,"".".('.,`"'/"'..'..'`"'..\`"'..'/"'..'/"'..'/"'`"'.".'P.
'"",'`'"'("'"'".a".'"","."".,`"'""",""".',."".',."".',""`"',"",'"
)'""`"'.\``,"\,'`,.'`"'".``"'".,)."".'".""'.".""'.".,"'``"'"..'.'
'".''`.","`"."""'""`"'\`"""/,`"'`""""``"\/,,`"\/,"`"""/"`","",','
\".......,,,,,..,"d,,"...,,.,"a"',."""PMaaM"M),aV,..,..,,",..."\.
)'.)`a`.(\`.b`.\'VaV`/,/.\(,'"'""dM."`'("/a'"/b/.\`.b`.b//a`/.\d)
PPMPMdVVb)V/P/P\VMMM"/bVP)"""""",MMb"""""'`V(/bPPbM/bbPbMPMMP/MM)
M/PbMPMMVMMdV/bMdMMVVbP)'"""""""MMMM)"""""""`d\MVMVMMbdMbMMPPMPP)
bMMPMPMVPbbbMMV\bbbPM('"""""a."(MMMMM"","""""'(bMdMVPbPbMdbMMdMM)
\\(dMV/////a\/)Pa//`''""""dMM""MMMMMM.",Ma""""`.a\(\/\d((a\(.)a`.
'''V''``````"'```,`/""""(MMMP",MMVdMMb""MMM."""`.''''','','\``'""
'""")"..",""."'"'"/""""dMMMM'"MMMMMMMM."(MMMb"""`."`"'"""","","`"
"""""""""""""""""`""",MMMMM)"(MMMM,MMMM""MMMMb.""""""""""""""""""
"".","',".,`",".,""",MMMMMM'"dMMMM"MMMM)"(MMMMM.""`'".".".."..".'
M/`PPbPddPPM(V(`""",MMMMMM)"(MMMMM"MMMMb"`MMMMMb."",\VdPPbV),'PP.
/a/ad`d/dd/dba\P"""dMMMMMM""MMMMMP"MMMMM)"VMMMMMb"""`\b(/db/(M,/.
VaVa\\'V///d//)'""(MMMMMMb",MMMMM)"MMMMMb"`MMMMMM.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MMMPM"`"`VMMM)"`MM)"",b(\b"/bPP/'
""dVaM(,)bdda/.""VMb""MMMMMMMMMMMMMP""""""`MMb""VM'""aVPa/\"/dPV'
""``))/b/"/d`(\"""MP"(MMMMMMMMMMMP'""".,.""`MM""dP"""d((`V"/","`'
\,\\,`\,b``".bV.""()"(MMMMMMMMMM""""abMMM.""VM."("""()''..`".'`a"
`"'"`"","\'\V/\'"""""dMMMMMMMMM""""dMMdMMM"""()"""""M(P`,"''"a'"'
/,",,\,,.".\"'a`.""""MMMMMMMMP"""(MMMMMMMP/""`)""""d`.(/,`,'"P,("
"'.)"d.\,"\``),"V""""MMMMMMMP"""MMMMMMMMMMda""("""(\".P"/d,'V,,'"
/"/"'.`b,\,\V``.`V.",MMMMMM/"",dMMMMMMMMMMMM"""""`M')"'"""''\'\/'
`""'"."(/P,\.b(,,"."(MMMMM'""(PMMMMMMMMMMMM)V""""V''(,`."""V/'\)"
".`,\"``'",'`(`'',""ddMMP""",MMMMMMMMMMMMM"""."""(""'"(.)),\/`"."
'\,'"\'"./\`'.,',(""dMMM'",b"MMMMMMMMMMM"""""""""`"./"'")'/`"\\a"
'``\'.'.),''\..`a"""MMP"""bP"`""P"P""""""""""b)"""'.`"/`.''//.'""
`'.'"'"`,""/".`..""`MM'""b"""""""""""""""",dM`M)"")"'//'/,/,/"`."
\'(',`./...''"\`"'",M'""\MM,""""""""""",,bM"'",M""'/a//\"")'")`'"
",'(,,'`"",.\/).V'"(""",P/V"VdMa",",ddaV"'.``./`""'````)````'"'`"
`a,,(""/".'.`.,(,'"""",M"("P"'"PPVV""\'`("/)\"/`P"('."`"\'''/')/.
`.'/'"/,("(,."."'""""dP'),d,'/'/d`\,\.,')"V"/""\`.\.")'.`d`."/`."
'"'((`''"'/).`,\("""/Pd"/'/b/"""."'`."'`,"""""`"`P(/``,"/.'(..)`"
"''\.\'(,`a,,a\'d"""MV,/'"".)/"'.\`","",,,")\"/.d(,(a"\`",\\\'./.
`",",""")'"`b")\b",d","a`"/`./((("'",\',."d`/.",,,M\a,.`",",d\\\.
.`/"...'d`,'"/((P,d"'(,`/\"..'".,`/\,"".a(`""(`)\a`""'".`\.'.'P..
/.'\".\/,"""'""".aP),,,\`'``./.``///'a'")"".\"/.'.d\")"d"'a'/,',"
/.\'``,V'.".)'/,bP/,b"P`"`.,'d(,`"//'.`/`a,`.'/`"',""..."''a','/"
',\`"\\'""`,""/"PP,","'`,,'."."`(`,`"P.'.,."./"`.b",'`,"`("(`,,M"
,,,/`'.,'."a'`a'/,``./`,")'"/,/,"")a',,`.."`//"b//").,,,."),''""'

Other related posts: