+ Rispondi alla Discussione
Risultati da 1 a 1 di 1

Discussione: Codice Per di Linux Pro 112

  1. #1
    Data Registrazione
    Feb 07
    Messaggi
    110

    Predefinito Codice Per di Linux Pro 112

    Ciao a tutti, ecco i due file che vi servono per seguire l'articolo dedicato a Perl su Linux Pro 112.

    File pictures_data

    Codice:
    images/castelsantangelo.JPG	Castel S. Angelo	400
    images/chiesaminerva.JPG	S. Maria s. Minerva	250
    images/pantheon.JPG	Pantheon	600
    images/piazzanavona.JPG	Piazza Navona	700
    images/piazzatrilussa.JPG	Piazza Trilussa	300
    images/sanclemente.jpg	San Clemente	250
    images/sangiovanni.jpg	San Giovanni	300
    images/sanpaolo.JPG	San Paolo	150
    File myboardgame.pl

    Codice:
    #!/usr/bin/perl
    use strict;
    use Image::Magick;
    
    # auxiliary variables
    my $I = 0;                #loop index
    my @ORDERED_SQUARES;
    my $ROTATION = 180;
    my $PIC_NAME;my $CAPTION; my $PRICE;
    #initial coordinates
    my $X = 100; my $Y = 100;
    
    #Width and Height of each box, squares per side
    my $BOX_WIDTH        = 300; my $BOX_HEIGHT = $BOX_WIDTH;
    my $SQUARE_DIST      = 100 + $BOX_WIDTH;
    my $SQUARES_PER_SIDE = 4;
    
    my %SPECIAL_SQUARES = (          #first field is the position
    '0',  "NO\tGo\tGood Luck",       # in the square sequence
    '3',  "NO\tChance\ttake yours",
    '6',  "NO\tFree Parking\t",
    '9', "NO\tJail\ttoo bad!"
    );
    
    # Create and prepare the big, white background image
    my $BOARD_SIZE = ($BOX_WIDTH + $SQUARE_DIST)*$SQUARES_PER_SIDE;
    my ($image, $x) = Image::Magick->new;
    $image -> Set(size=>"${BOARD_SIZE}x$BOARD_SIZE");
    $image -> ReadImage("xc:white");
    
    # Read picture names, captions and other info from the data files,
    # inserting the special squares in the right places
    open(PICS_LIST, "< pictures_data.txt") || die "Cannot open pictures data file!\n";
    while (<PICS_LIST>) {
      if (defined ($SPECIAL_SQUARES{$I})) {
          push @ORDERED_SQUARES, $SPECIAL_SQUARES{$I} ;
          $I++;
      }
      chomp;
      push @ORDERED_SQUARES, $_;
      $I++;
    }
    close PICS_LIST;
    
    # now add all the squares to the board
    for ($I = 0; $I<= $#ORDERED_SQUARES; $I++) {
    
      ($PIC_NAME, $CAPTION, $PRICE) = split "\t",  $ORDERED_SQUARES[$I];
    
      # draw a box, add the captions in it and save it in /tmp/tmp_image.jpg
    
      &DRAW_BORDER_ADD_CAPTIONS($BOX_WIDTH, $BOX_HEIGHT, $CAPTION, $PRICE);
    
      # if there is a current picture, resize it and put it
      # at the center of the temporary image
      &INSERT_PICTURE($PIC_NAME, $BOX_WIDTH - 40, $BOX_HEIGHT - 120) unless $PIC_NAME =~ m/^NO$/;
    
      my $tmp_image;
      $tmp_image = Image::Magick->new;
      $tmp_image -> ReadImage("/tmp/tmp_image.jpg");
      $tmp_image -> Rotate ( degrees => $ROTATION) if ($ROTATION > 0);
      # place the current square at the right position on the board
      $image-> Composite (image=>$tmp_image, compose=> 'over', geometry=>"+$Y+$X");
      undef $tmp_image;
    
      #calculate new rotation value and origin of the next square;
      # if index is a multiple of $SQUARES_PER_SIDE
      # we've reached a corner of the board, let's increase image rotation
      $ROTATION += 90 if (($I > 0 ) && ( $I % ( $SQUARES_PER_SIDE - 1) == 0));
      $ROTATION -= 360 if ($ROTATION >= 360);
    
      if($ROTATION == 180) {
        $Y = $Y  + $SQUARE_DIST ;
        } elsif ($ROTATION == 270) {
        $X = $X  + $SQUARE_DIST; 
        } elsif ($ROTATION == 0) {
        $Y = $Y  - $SQUARE_DIST;
        } elsif ($ROTATION == 90) {
        $X = $X  - $SQUARE_DIST;
        } else { die "wrong Rotation value: $ROTATION\n"}
    
    }
    
    # add central slogan and save
    $image -> Annotate( text => 'Linux Pro rules!', stroke =>"red", pointsize=> 90,
          rotate=> 215, x => int($BOARD_SIZE*0.4), y => int($BOARD_SIZE*0.4));
    $image -> write ("jpg:board.jpg");
    
    exit;
    
    ############################################################################################
    sub DRAW_BORDER_ADD_CAPTIONS  {
    my $BW; my $BH;
    my $BC; my $BP;
    ($BW, $BH, $BC, $BP) = ($_[0], $_[1],$_[2], $_[3]);
    
    my $tmp_image;
      $tmp_image = Image::Magick->new;
      $tmp_image -> Set(size=>"${BW}x$BH");
      $tmp_image -> ReadImage("xc:white");
    
    my $X_LINE_START = 10;
    my $Y_LINE_START = 10;
    my $X_LINE_END   = 10;
    my $Y_LINE_END   = $BW -10;
    
      $tmp_image -> Draw ( stroke => "red", primitive => "line",
              points => "$Y_LINE_START,$X_LINE_START $Y_LINE_END,$X_LINE_END");
    
    my $X_LINE_START = 10;
    my $Y_LINE_START = $BW -10;
    my $X_LINE_END   = $BH - 10;
    my $Y_LINE_END   = $BW - 10;
    
    $tmp_image -> Draw ( stroke => "blue", primitive => "line",
              points => "$Y_LINE_START,$X_LINE_START $Y_LINE_END,$X_LINE_END");
    
    my $X_LINE_START = $BH - 10;
    my $Y_LINE_START = $BW - 10;
    my $X_LINE_END   = $BH - 10;
    my $Y_LINE_END   = 10;
    $tmp_image -> Draw ( stroke => "green", primitive => "line",
              points => "$Y_LINE_START,$X_LINE_START $Y_LINE_END,$X_LINE_END");
    
    my $Y_LINE_START   = 10;
    my $X_LINE_START   = $BH - 10;
    my $X_LINE_END     = 10;
    my $Y_LINE_END     = 10;
    $tmp_image -> Draw ( stroke => "red", primitive => "line",
    	      points => "$Y_LINE_START,$X_LINE_START $Y_LINE_END,$X_LINE_END");
      #add Caption and price to temporary image
      $tmp_image -> Annotate( text => $CAPTION, stroke =>"blue", pointsize=> 24, x => 20, y => 10 + int($BH * 0.75 + 20));
      $tmp_image -> Annotate( text => $PRICE,   stroke =>"red",  pointsize=> 16, x => 40, y => 10 + int($BH * 0.75 + 40));
      $tmp_image -> write ("jpg:/tmp/tmp_image.jpg");
      undef $tmp_image;
    }
    #####################################################################################
    sub INSERT_PICTURE {
      my $PIC  = $_[0];
      my $TH_W = $_[1];
      my $TH_H = $_[2];
      my $current_pic = Image::Magick->new;
      $current_pic   -> ReadImage($PIC);
      $current_pic->Resize(width=>$TH_W, height=>$TH_H);
      my $tmp_image;
      $tmp_image = Image::Magick->new;
      $tmp_image   -> ReadImage("/tmp/tmp_image.jpg");
    
      #put the current picture at the center of the temporary image
      $tmp_image-> Composite (image=>$current_pic, compose=> 'over', geometry=>"+20+20");
      $tmp_image -> write ("jpg:/tmp/tmp_image.jpg");
      undef $current_pic;
      undef $tmp_image;
    }
    Ultima modifica di ninjak; 04-01-12 alle 16:10

+ Rispondi alla Discussione

Discussioni Simili

  1. PayPal: codice carta
    Di il mito dei miti nel forum Varie
    Risposte: 6
    Ultimo Messaggio: 07-08-09, 12:32
  2. codice perso
    Di marino castellana nel forum Software
    Risposte: 5
    Ultimo Messaggio: 13-09-08, 07:50
  3. codice di attivazione p2p
    Di nathan61 nel forum Sicurezza
    Risposte: 2
    Ultimo Messaggio: 28-06-08, 18:33
  4. Mi son perso il codice...
    Di spada01 nel forum La nostra rivista
    Risposte: 1
    Ultimo Messaggio: 04-01-08, 15:34
  5. Codice Attivazione Windows Vista
    Di Glacius nel forum Software
    Risposte: 22
    Ultimo Messaggio: 02-09-07, 16:14

Segnalibri

Permessi di Scrittura

  • Tu non puoi inviare nuove discussioni
  • Tu non puoi inviare risposte
  • Tu non puoi inviare allegati
  • Tu non puoi modificare i tuoi messaggi
  • Il codice BB è Attivato
  • Le faccine sono Attivato
  • Il codice [IMG] è Attivato
  • Il codice HTML è Disattivato