[Perl] ASCII Art 0.1

Iniciado por BigBear, Octubre 02, 2012, 08:19:06 PM

Tema anterior - Siguiente tema

0 Miembros y 1 Visitante están viendo este tema.

Sin mucho que decir dejo este simple script para hacer ascii art desde una palabra.

El codigo

Código: perl

#!usr/bin/perl
#ASCII Art 0.1
#Coded By Doddy H

use List::Util "max";
use Time::HiRes "usleep";

my %letras = (

    a => "         
   @   
   @   
  @ @ 
  @ @ 
@   @
@   @
@@@@@
@     @
@     @
",

    b => "
@@@@
@   @
@   @
@   @
@@@@
@   @
@   @
@   @
@@@@
",

    c => "
  @@@@
@    @
@     
@     
@     
@     
@     
@    @
  @@@@
",

    d => "
@@@@ 
@   @
@    @
@    @
@    @
@    @
@    @
@   @
@@@@ 
",

    e => "
@@@@@
@   
@   
@   
@@@@
@   
@   
@   
@@@@@
",
    f => "
@@@@@
@   
@   
@   
@@@@
@   
@   
@   
@   
",
    g => "
  @@@@
@    @
@     
@     
@  @@@
@    @
@    @
@   @@
  @@@ @
",
    h => "
@    @
@    @
@    @
@    @
@@@@@@
@    @
@    @
@    @
@    @
",
    i => "
@
@
@
@
@
@
@
@
@
",
    j => "
   @
   @
   @
   @
   @
   @
@  @
@  @
@@
",
    k => "
@   @
@  @ 
@ @   
@@   
@@   
@ @   
@  @ 
@   @
@    @
",
    l => "
@   
@   
@   
@   
@   
@   
@   
@   
@@@@@
",
    m => "
@     @
@     @
@@   @@
@@   @@
@ @ @ @
@ @ @ @
@  @  @
@  @  @
@     @
",
    n => "
@    @
@@   @
@@   @
@ @  @
@ @  @
@  @ @
@   @@
@   @@
@    @
",
    o => "
  @@@@
@    @
@    @
@    @
@    @
@    @
@    @
@    @
  @@@@
",
    p => "
@@@@@
@    @
@    @
@    @
@@@@@
@     
@     
@     
@     
",
    q => "
  @@@@
@    @
@    @
@    @
@    @
@    @
@  @ @
@   @@
  @@@@
      @
",
    r => "
@@@@@
@    @
@    @
@    @
@@@@@
@    @
@    @
@    @
@    @
",
    s => "
  @@@
@   @
@   
@   
  @@@
     @
     @
@   @
  @@@
",
    t => "
@@@@@
   @ 
   @ 
   @ 
   @ 
   @ 
   @ 
   @ 
   @ 
",
    u => "
@    @
@    @
@    @
@    @
@    @
@    @
@    @
@    @
  @@@@
",
    v => "
@     @
@     @
@   @
@   @
@   @
  @ @ 
  @ @ 
   @   
   @   
",
    W => "
@         @
@         @
@   @   @
@   @   @
@   @   @
  @ @ @ @ 
  @ @ @ @ 
   @   @   
   @   @   
",
    x => "
@     @
@     @
@   @
  @ @ 
   @   
  @ @ 
@   @
@     @
@     @
",
    y => "
@     @
@     @
@   @
  @ @ 
   @   
   @   
   @   
   @   
   @   
",
    z => "
@@@@@@@
      @
     @
    @ 
   @   
  @   
@     
@     
@@@@@@@
"

);

head();

print "\n\n[+] Text : ";
chomp( my $text = <stdin> );

print "\n\n" . artnow($text) . "\n";

copyright();

sub artnow {

    my $target = shift;

    my $fondo   = " ";
    my $espacio = 0;

    my $lugar;
    my @lotengo;

    my $tipox = $letras{"a"};
    my @lineas = split /\n/, $tipox;
    $altura = @lineas + 1;

    $anchura = max map { length $_ } @lineas;

    for ( 1 .. $altura ) {
        push @lotengo, $fondo x ( ( $anchura + $espacio ) * length $target );
    }

    for my $letra ( split //, $target ) {
        my @lineas = split /\n/, $letras{$letra};

        for my $i ( 0 .. $altura - 1 ) {
            ( my $plan = $lineas[$i] ) =~ s/ /$fondo/g;

            $plan = $fondo x $anchura if not $plan;

            substr( $lotengo[$i], $lugar, length $plan ) = $plan;
        }

        $lugar += $anchura + $espacio;
    }

    return ( join "\n", @lotengo );

}

sub head {

    my @logo = (
        "#=============================================#", "\n",
        "#            ASCII Art 0.1                    #", "\n",
        "#---------------------------------------------#", "\n",
        "# Written By Doddy H                          #", "\n",
        "# Email: lepuke[at]hotmail[com]               #", "\n",
        "# Website: doddyhackman.webcindario.com       #", "\n",
        "#---------------------------------------------#", "\n",
        "# Thanks to : reLlene,MARKO,explorer          #", "\n",
        "# The End ?                                   #", "\n",
        "#=============================================#", "\n"
    );

    print "\n";
    marquesina(@logo);

}

sub marquesina {

    #Effect based in the exploits by Jafer Al Zidjali

    my @logo = @_;

    my $car = "|";

    for my $uno (@logo) {
        for my $dos ( split //, $uno ) {

            $|++;

            if ( $car eq "|" ) {
                mostrar( "\b" . $dos . $car, "/" );
            }
            elsif ( $car eq "/" ) {
                mostrar( "\b" . $dos . $car, "-" );
            }
            elsif ( $car eq "-" ) {
                mostrar( "\b" . $dos . $car, "\\" );
            }
            else {
                mostrar( "\b" . $dos . $car, "|" );
            }
            usleep(40_000);
        }
        print "\b ";
    }

    sub mostrar {
        print $_[0];
        $car = $_[1];
    }

}

sub copyright {

    print "\n\n";

    marquesina("-- == (C) Doddy Hackman 2012 == --");

    print "\n\n";

    <stdin>;
    exit(1);
}

#The End ?


Ejemplo de uso

Código: php


r00t ~ # art.pl



#=============================================#
#            ASCII Art 0.1                    #
#---------------------------------------------#
# Written By Doddy H                          #
# Email: lepuke[at]hotmail[com]               #
# Website: doddyhackman.webcindario.com       #
#---------------------------------------------#
# Thanks to : reLlene,MARKO,explorer          #
# The End ?                                   #
#=============================================#


[+] Text : kacked



@   @      @       @@@@    @   @    @@@@@    @@@@
@  @       @      @    @   @  @     @        @   @
@ @       @ @     @        @ @      @        @    @
@@        @ @     @        @@       @        @    @
@@       @   @    @        @@       @@@@     @    @
@ @      @   @    @        @ @      @        @    @
@  @     @@@@@    @        @  @     @        @    @
@   @   @     @   @    @   @   @    @        @   @
@    @  @     @    @@@@    @    @   @@@@@    @@@@



-- == (C) Doddy Hackman 2012 == --