回文章列表
作者mczincent.bbs@redbbs.cc.tit.edu.tw (♀≧♂?), 信區: asciiart
標題Re: 那個轉ascii圖的程式
時間臺北科技大學紅樓資訊站 (Wed Jun 18 19:29:41 1997)
轉信站: GIBBS!news.iie.ncku!ccnews.NCTU!news.nctu!news.ee.ntit!redbbs
Origin: @redbbs.cc.tit.edu.tw



?
【 在 nthuccc.bbs@bbs.ee.nthu. (回家調養.....) 的大作中提到: 】
: 這篇是從tin上轉回來的
: 我也不知道能不能用
: 不會用所以也沒試過
: This is my third attempt at posting this in as many days - not
: a sign of the other two attempts on the normally fast server
: here, so I'm trying again!
: This program will intelligently rotate90,180,270, flip, mirror, and
: doublesize ASCII art.  Give it a whirl.
: --Adam.
: /*************************************************************
: asctrans.c - An ASCII art transformation filter.
:              Copyright (C) 1995 Adam D. Moss
: Author:
:       Adam Moss, mossap@essex.ac.uk (preferred) or
:                  aspirin@catnip.cfs.purdue.edu
: To compile:
:       cc asctrans.c -o asctrans
: Portability:
:       Unlikely to compile under DOS because of my 1 Mb static
:         array.  :)
: Notes:
:       Geared towards ASCII art, does not work well on text.
:       Inspired by Alex Butcher.
:       Dedicated to Mike Jittlov - wizard, filmmaker, and ASCII
:         artist!
: Usage:
:       For usage instructions, invoke program with no
:         parameters.
: Revision history:
:       v1.01: 95.02.28:
:         Initial release.
: License:
:       Copyright (C) 1995 Adam D. Moss
:       This program is free software; you can redistribute it
:       and/or modify it under the terms of the GNU General
:       Public License as published by the Free Software
:       Foundation; either version 2 of the License, or (at
:       your option) any later version.
:       This program is distributed in the hope that it will
:       be useful, but WITHOUT ANY WARRANTY; without even the
:       implied warranty of MERCHANTABILITY or FITNESS FOR A
:       PARTICULAR PURPOSE.  See the GNU General Public
:       License for more details.  A copy of the GNU General
:       Public License may be obtained from the Free Software
:       Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139,
:       USA.
: Have fun!  :)
: *************************************************************/
: #include <stdlib.h>
: #include <stdio.h>
: char line[1000][1000];  /*  This sucks.  :)  */
: int linecount,linewid,eof,x,c,y;
: int optype,filter,doublesize;
: char dou[5];
: /* operations */
: #define NONE 0
: #define VERTFLIP 1
: #define HORIZFLIP 2
: #define ROT90 3
: #define ROT180 4
: #define ROT270 5
: #define TRUE 1
: #define FALSE 0
: void printusage(char *argv[])
: {
:   puts("  /| //  // || ||             version 1.01: 2/95");
:   puts(" //| \\\\ <<  || || T R A N S   (C) 1995 Adam Moss");
:   puts("// | //  \\\\ || ||             mossap@essex.ac.uk\n");
:   puts("Usage:");
:   printf("    %s [v|h|1|2|3][n][d]\n",argv[0]);
:   puts("Example:");
:   printf("    %s 1d <~/.signature\n",argv[0]);
:   puts("Options:");
:   puts("    v: Vertical flip");
:   puts("    h: Horizontal flip");
:   puts("    1: 1/4 rotation clockwise");
:   puts("    2: 2/4 rotation clockwise");
:   puts("    3: 3/4 rotation clockwise");
:   puts("    n: No character changes");
:   puts("    d: Doublesize image\n");
:   exit(-1);
: }
: void doargs(int argc,char *argv[])
: {
:   int i;
:   doublesize = FALSE;
:   optype = NONE;
:   filter = TRUE;
:   if (argc!=2) printusage(argv);
:   for (i=0;i<strlen(argv[1]);i++)
:     {
:       switch(argv[1][i])
:       {
:       case 'v':
:       case 'V': optype=VERTFLIP; break;
:       case 'h':
:       case 'H': optype=HORIZFLIP; break;
:       case '1': optype=ROT90; break;
:       case '2': optype=ROT180; break;
:       case '3': optype=ROT270; break;
:       case 'd':
:       case 'D': doublesize=TRUE; break;
:       case 'n':
:       case 'N': filter=FALSE; break;
:       default:
:         {
:           printf("Unknown switch.\n\n");
:           printusage(argv);
:         }
:       }
:     }
: }
: void finddouble(char c)
: {
:   switch(c)
:     {
:     case '<': strcpy(dou," /\\ ");break;
:     case '>': strcpy(dou,"\\  /");break;
:     case '^': strcpy(dou,"/\\  ");break;
:     case 'v': strcpy(dou,"  \\/");break;
:     case 'V': strcpy(dou,"||\\/");break;
:     case '/': strcpy(dou," // ");break;
:     case '\\': strcpy(dou,"\\  \\");break;
:     case '_': strcpy(dou,"  __");break;
:     case '-': strcpy(dou,"__  ");break;
:     case '~': strcpy(dou,"~~  ");break;
:     case ',': strcpy(dou,"  / ");break;
:     case '`': strcpy(dou,"\\   ");break;
:     case '\'': strcpy(dou," /  ");break;
:     case '"': strcpy(dou,"||  ");break;
:     case '.': strcpy(dou,"  . ");break;
:     case 'o': strcpy(dou,"  ()");break;
:     case 'O': strcpy(dou,"/\\\\/");break;
:     case 'X': strcpy(dou,"\\//\\");break;
:     case 'x': strcpy(dou,"  ><");break;
:     case '(': strcpy(dou," ( (");break;
:     case ')': strcpy(dou,") ) ");break;
:     case ':': strcpy(dou,": : ");break;
:     case ';': strcpy(dou,": ; ");break;
:     case '|': strcpy(dou,"| | ");break;
:     case '+': strcpy(dou,"|_| ");break;
:     case '=': strcpy(dou,"----");break;
:     case '%': strcpy(dou,"o//o");break;
:     case '!': strcpy(dou,"| . ");break;
:     case '{': strcpy(dou," { {");break;
:     case '}': strcpy(dou,"} } ");break;
:     case '[': strcpy(dou," [ [");break;
:     case ']': strcpy(dou,"] ] ");break;
:     case 'U': strcpy(dou,"|L|J");break;
:     case 'L': strcpy(dou,"| L_");break;
:     case 'C': strcpy(dou,"(~(_");break;
:     case 'c': strcpy(dou," _(_");break;
:     case 'n': strcpy(dou,"__||");break;
:     case 'd': strcpy(dou,"_|L_");break;
:     case 'D': strcpy(dou,"~|L|");break;
:     case 'i': strcpy(dou,": | ");break;
:     case 'I': strcpy(dou,"I I ");break;
:     case '0': strcpy(dou,"/\\\\/");break;
:     case 'Z': strcpy(dou,"_//_");break;
:     case 'N': strcpy(dou,"|\\||");break;
:     case '8': strcpy(dou,"()()");break;
:     case 'r': strcpy(dou,"/-| ");break;
:     case 'm': strcpy(dou,"  nn");break;
:     case 'w': strcpy(dou,"  uu");break;
:     case 'W': strcpy(dou,"||VV");break;
:     case 'M': strcpy(dou,"^^||");break;
:     case 'l': strcpy(dou,"l l ");break;
:     case 'P': strcpy(dou,"|\\|~");break;
:     case 'u': strcpy(dou,"||  ");break;
:     default: dou[0]=dou[1]=dou[2]=dou[3]=c;
:     }
: }
: void doubleup(void)
: {
:   linewid*=2;
:   linecount*=2;
:   if (filter==FALSE) for (y=linecount-1;y>=0;y--)
:     for (x=linewid-1;x>=0;x--)
:       {
:       line[x*2][y*2]=line[x][y];
:       line[1+x*2][y*2]=line[x][y];
:       line[x*2][1+y*2]=line[x][y];
:       line[1+x*2][1+y*2]=line[x][y];
:       }
:   else for (y=linecount-1;y>=0;y--)
:     for (x=linewid-1;x>=0;x--)
:       {
:       finddouble(line[x][y]);
:       line[x*2][y*2]=dou[0];;
:       line[1+x*2][y*2]=dou[1];
:       line[x*2][1+y*2]=dou[2];
:       line[1+x*2][1+y*2]=dou[3];
:       }
: }
: char mirror(char c)
: {
:   switch (c)
:   {
:   case '(': return(')');
:   case ')': return('(');
:   case '[': return(']');
:   case ']': return('[');
:   case '/': return('\\');
:   case '\\': return('/');
:   case '{': return('}');
:   case '}': return('{');
:   case '\'': return('`');
:   case '`': return('\'');
:   case 'd': return('b');
:   case 'b': return('d');
:   case 'Q': return('O');
:   case ',': return('.');
:   case ';': return(':');
:   case '<': return('>');
:   case '>': return('<');
:   case 'p': return('q');
:   case 'q': return('p');
:   case '2': return('S');
:   case 'S': return('2');
:   default: return(c);
:   }
: }
: char flip(char c)
: {
:   switch (c)
:   {
:   case '_': return('~');
:   case '~': return('_');
:   case ',': return('`');
:   case '`': return(',');
:   case '/': return('\\');
:   case '\\': return('/');
:   case '\'': return('.');
:   case '"': return(',');
:   case 'P': return('b');
:   case 'b': return('p');
:   case 'p': return('b');
:   case 'v': return('^');
:   case '^': return('v');
:   case 'q': return('d');
:   case 'd': return('q');
:   case '.': return('\'');
:   case 'U': return('n');
:   case 'n': return('u');
:   case 'u': return('n');
:   case 'Q': return('O');
:   case 'W': return('M');
:   case 'M': return('W');
:   case 'w': return('m');
:   case 'm': return('w');
:   case 'A': return('V');
:   case 'V': return('A');
:   case '?': return('j');
:   case 'j': return('?');
:   case ';': return(':');
:   case '2': return('5');
:   case '5': return('2');
:   default: return(c);
:   }
: }
: char rot90(char c)
: {
:   switch (c)
:   {
:   case '_': return('|');
:   case '~': return('|');
:   case '-': return('|');
:   case '|': return('-');
:   case '/': return('\\');
:   case '\\': return('/');
:   case '(': return('-');
:   case ')': return('-');
:   case '!': return('-');
:   case '<': return('^');
:   case '^': return('>');
:   case '>': return('V');
:   case '=': return('H');
:   case 'H': return('=');
:   case 'Q': return('O');
:   case ':': return('-');
:   case ';': return('-');
:   case '{': return('-');
:   case '}': return('-');
:   case '3': return('W');
:   case 'W': return('E');
:   case 'E': return('M');
:   case 'M': return('3');
:   case 'A': return('>');
:   case 'V': return('<');
:   case 'v': return('<');
:   case 'c': return('n');
:   case 'u': return('c');
:   case '"': return(':');
:   case 'Z': return('N');
:   case 'N': return('Z');
:   case ',': return('`');
:   case '`': return('\'');
:   case '\'': return('.');
:   case '.': return(',');
:   case 'i': return('-');
:   case '1': return('-');
:   case 'l': return('-');
:   default: return(c);
:   }
: }
: char rot180(char c)
: {
: /* Just an approximation for now */
:   return(flip(mirror(c)));
: }
: char rot270(char c)
: {
: /* Another approximation, even worse :) */
:   return(rot90(rot180(c)));
: }
: void main(int argc,char *argv[])
: {
:   doargs(argc,argv);
:   linecount=0; linewid=1; x=0;
:   while (1)
:   {
:     c=getchar();
:     if ((c=='\n')||(c==EOF))
:     {
:       if (x>linewid) linewid=x;
:       for (;x<1000;x++) line[x][linecount]=' ';
:       linecount++;
:       if (c==EOF) break;
:       x=0;
:     }
:     else
:     {
:       line[x++][linecount]=(char)c;
:     }
:   }
:   if (doublesize==TRUE) doubleup();
:   if (filter==TRUE)
:     {
:       for (y=0;y<linecount;y++)
:       {
:         for (x=0;x<linewid;x++)
:           {
:             switch (optype)
:               {
:               case VERTFLIP:  line[x][y]=flip(line[x][y]);   break;
:               case HORIZFLIP: line[x][y]=mirror(line[x][y]); break;
:               case ROT90:     line[x][y]=rot90(line[x][y]);  break;
:               case ROT180:    line[x][y]=rot180(line[x][y]); break;
:               case ROT270:    line[x][y]=rot270(line[x][y]); break;
:               }
:           }
:       }
:     }
:   switch (optype)
:     {
:     case NONE:
:       for (y=0;y<linecount;y++)
:       {
:         for (x=0;x<linewid;x++)
:           {
:             putchar(line[x][y]);
:           }
:         putchar('\n');
:       };break;
:     case VERTFLIP:
:       for (y=linecount-1;y>=0;y--)
:       {
:         for (x=0;x<linewid;x++)
:           {
:             putchar(line[x][y]);
:           }
:         putchar('\n');
:       };break;
:     case HORIZFLIP:
:       for (y=0;y<linecount;y++)
:       {
:         for (x=linewid-1;x>=0;x--)
:           {
:             putchar(line[x][y]);
:           }
:         putchar('\n');
:       };break;
:     case ROT90:
:       for (x=0;x<linewid;x++)
:       {
:         for (y=linecount-1;y>=0;y--)
:           {
:             putchar(line[x][y]);
:           }
:         putchar('\n');
:       };break;
:     case ROT180:
:       for (y=linecount-1;y>=0;y--)
:       {
:         for (x=linewid-1;x>=0;x--)
:           {
:             putchar(line[x][y]);
:           }
:         putchar('\n');
:       };break;
:     case ROT270:
:       for (x=linewid-1;x>=0;x--)
:       {
:         for (y=0;y<linecount;y++)
:           {
:             putchar(line[x][y]);
:           }
:         putchar('\n');
:       };break;
:     }
: }


--
※ 來源:‧臺北科技大學紅樓資訊站 redbbs.cc.tit.edu.tw‧[FROM: sun]
文章選讀←離開[主題上]主題下(k)上篇(j)下篇S/a搜尋 G串列 TAB精華 ↑↓捲 Pg/Space翻