print "\n\nSpectromie...\n\n";
open fREC, "<$recueilFile" or die "Impossible d'ouvrir le recueil !\n";
my $specFile;
if($recueilFile =~ m/^(\S+)\.\w+$/) { $specFile = $1;
} else { $specFile = $recueilFile;
} $specFile .= "_spec.txt";
open fSPEC, ">$specFile" or die "Impossible de créer le fichier log !\n";
my %Poetivites;
my %SampledRecueil;
&spectromie;
close fREC;
close fSPEC;
print "\n\nPoedilation...\n\n";
my @choix = sort( {$a <=> $b or $a cmp $b} keys(%SampledRecueil));
my $num_choix = 1;
foreach my $choice (@choix) { print "[" . sprintf("%2s",$num_choix) . "] " . $choice . "\n";
$num_choix++;
} my $zeChoix = "non";
while (!($zeChoix =~ m/^\d+$/ && $zeChoix >= 1 && $zeChoix <= scalar(@choix))) { print "\nentrer le numero du poeme choisi pour la poedilation :\n";
$zeChoix = <STDIN>;
} chomp($zeChoix);
$zeChoix--;
my $poeme_choisi = $choix[$zeChoix];
my $total_mots = 0;
foreach (keys(%{$SampledRecueil{$poeme_choisi}})) { $total_mots += scalar @{$SampledRecueil{$poeme_choisi}{$_}{"mots"}};
} print "\npoedilation de \"" . $poeme_choisi . "\" (" . $total_mots . " mots)...\n";
my $degreP = "non";
while (!($degreP =~ m/^\d+$/ && $degreP >= 1)) { print "\nEntrer le degre de poedilation :\n";
$degreP = <STDIN>;
} chomp($degreP);
&poedilation($poeme_choisi,$degreP);
open fPOE, ">poetivites.txt" or die;
foreach my $poetivite (sort( {$a <=> $b} keys(%{$Poetivites{"recueil"}}))) { print fPOE $poetivite . "\t";
foreach my $mot (@{$Poetivites{"recueil"}{$poetivite}}) { print fPOE $mot . "\t";
} print fPOE "\n";
} close fPOE;
exit(0);
function longLinenoise($myImage,$dimImage,$strength,$freq) { $indexWhite = imagecolorexact($myImage,255,255,255);
$indexBlack = imagecolorexact($myImage,0,0,0);
for($i = 0 ;
$i < $dimImage[0] ;
$i++) { for($j = 0 ;
$j < $dimImage[1] ;
$j++) { if(rand(1,$freq) >= 20) {
} else { $currColor = imagecolorat($myImage,$i,$j);
if(isCloseColor($myImage,$currColor,255,255,255,10)) continue;
$nb_lignes = rand(1,intval($strength/10));
$length = rand(intval($strength/5),$strength);
drawLignes($myImage,$dimImage,$currColor,$i,$j,$nb_lignes,$length);
} } } } function drawLignes($myImage,$dimImage,$color,$x,$y,$nb_lignes,$max_length) { for($i = 0 ;
$i < $nb_lignes ;
$i++) { $xmin = $x-$max_length;
if($xmin < 0) $xmin = 0;
$ymin = $y-$max_length;
if($ymin < 0) $ymin = 0;
$xmax = $x+$max_length;
if($xmax > $dimImage[0] - 1) $xmax = $dimImage[0] - 1;
$ymax = $y+$max_length;
if($ymax > $dimImage[1] - 1) $ymax = $dimImage[1] - 1;
$x2 = rand($xmin,$xmax);
$y2 = rand($ymin,$ymax);
while(sqrt(pow($x2-$x,2) + pow($y2-$y,2)) > $max_length) { $xmin = $x-$max_length;
if($xmin < 0) $xmin = 0;
$ymin = $y-$max_length;
if($ymin < 0) $ymin = 0;
$xmax = $x+$max_length;
if($xmax > $dimImage[0] - 1) $xmax = $dimImage[0] - 1;
$ymax = $y+$max_length;
if($ymax > $dimImage[1] - 1) $ymax = $dimImage[1] - 1;
$x2 = rand($xmin,$xmax);
$y2 = rand($ymin,$ymax);
} imageline($myImage,$x,$y,$x2,$y2,$color);
$x = $x2;
$y = $y2;
} } function invertnoise($myImage,$dimImage,$strength) { $indexBlack = imagecolorexact($myImage,0,0,0);
if($indexBlack == -1) $indexBlack = imagecolorclosest($myImage,0,0,0);
$indexWhite = imagecolorexact($myImage,255,255,255);
if($indexWhite == -1) $indexWhite = imagecolorclosest($myImage,255,255,255);
$currColor = imagecolorat($myImage,0,0);
for($i = 0 ;
$i < $dimImage[0] ;
$i++) { for($j = 0 ;
$j < $dimImage[1] ;
$j++) { if(rand(1,100) >= $strength) { } else { $currColor = imagecolorat($myImage,$i,$j);
if($currColor == $indexBlack) imagesetpixel($myImage,$i,$j,$indexWhite);
if($currColor == $indexWhite) imagesetpixel($myImage,$i,$j,$indexBlack);
} } } }
sub poedilation { my $poeme = $_[0];
my $degre = $_[1];
open fPOE, ">" . $poeme . ".txt" or die "Impossible d'ouvrir le fichier $poeme.txt !\n";
open fPTE, ">" . $poeme . "_pte.txt" or die "Impossible d'ouvrir le fichier $poeme.txt !\n";
foreach my $ligne (sort( {$a <=> $b} keys(%{$SampledRecueil{$poeme}}))) {
if(scalar(@{$SampledRecueil{$poeme}{$ligne}{"mots"}}) == 0) { print fPOE "\n";
next;
}
if(scalar(@{$SampledRecueil{$poeme}{$ligne}{"mots"}}) == 1) { print fPOE ${$SampledRecueil{$poeme}{$ligne}{"mots"}}[0] . "\n";
print fPTE ${$SampledRecueil{$poeme}{$ligne}{"poetivites"}}[0] . "\n";
next;
}
my @finalLine;
my @finalPoe;
for (my $i = 0 ;
$i < $degre ;
$i++) {
my @newLine;
my @newPoetivites;
while(scalar(@{$SampledRecueil{$poeme}{$ligne}{"mots"}}) > 1) {
my $motAvant = shift(@{$SampledRecueil{$poeme}{$ligne}{"mots"}});
my $poeAvant = shift(@{$SampledRecueil{$poeme}{$ligne}{"poetivites"}});
my $interpol = int(($poeAvant + ${$SampledRecueil{$poeme}{$ligne}{"poetivites"}}[0]) / 2);
if(exists($Poetivites{$poeme}{$interpol})) {
push(@newLine,${$Poetivites{$poeme}{$interpol}}[int(rand(scalar(@{$Poetivites{$poeme}{$interpol}})))]);
push(@newPoetivites,$interpol);
next;
}
if(exists($Poetivites{$poeme}{$interpol-1})) {
push(@newLine,${$Poetivites{$poeme}{$interpol-1}}[int(rand(scalar(@{$Poetivites{$poeme}{$interpol-1}})))]);
push(@newPoetivites,$interpol-1);
next;
}
if(exists($Poetivites{$poeme}{$interpol+1})) {
push(@newLine,${$Poetivites{$poeme}{$interpol+1}}[int(rand(scalar(@{$Poetivites{$poeme}{$interpol+1}})))]);
push(@newPoetivites,$interpol+1);
next;
}
my @poetivikeys = sort( {$a <=> $b} keys(%{$Poetivites{"recueil"}}));
my $avant = $poetivikeys[0];
my $apres = 0;
foreach my $poetivitest (@poetivikeys) {
next if($poetivitest == $avant);
if($poetivitest > $interpol) { $apres = $poetivitest;
last;
} $avant = $poetivitest;
}
if(($interpol - $avant) > ($apres - $interpol)) { push(@newLine,${$Poetivites{"recueil"}{$apres}}[int(rand(scalar(@{$Poetivites{"recueil"}{$apres}})))]);
push(@newPoetivites,$apres);
} else { push(@newLine,${$Poetivites{"recueil"}{$avant}}[int(rand(scalar(@{$Poetivites{"recueil"}{$avant}})))]);
push(@newPoetivites,$avant);
}
}
if(scalar(@{$SampledRecueil{$poeme}{$ligne}{"mots"}}) > 0) { push(@newLine,shift(@{$SampledRecueil{$poeme}{$ligne}{"mots"}}));
push(@newPoetivites,shift(@{$SampledRecueil{$poeme}{$ligne}{"poetivites"}}));
} @{$SampledRecueil{$poeme}{$ligne}{"mots"}} = @newLine;
@finalLine = @newLine;
@{$SampledRecueil{$poeme}{$ligne}{"poetivites"}} = @newPoetivites;
@finalPoe = @newPoetivites;
}
foreach my $motfinal (@finalLine) { print fPOE $motfinal . " ";
} foreach my $poefinale (@finalPoe) { print fPTE $poefinale . " ";
} print fPOE "\n";
print fPTE "\n";
}
print "\n\npoedilation OK ! (voir " . $poeme . ".txt, " . $poeme . "_pte.txt pour le spectre)\n";
close fPOE;
close fPTE;
}
sub premierPassage { my $ligne;
my $compteur = 0;
my $poeme = undef;
my $nbMots;
my $lengthCumul;
while(<fREC>) {
chomp;
$ligne = $_;
my @Ligne = split(/\s+/,$ligne);
if($poeme) { $Recueil{$poeme}{"longueur_mot_moyenne"} = $lengthCumul / $nbMots;
}
$poeme = $1;
$compteur++;
$Recueil{$poeme}{"nombre_lignes"} = 0;
$nbMots = 0;
$lengthCumul = 0;
next;
}
my $nbMotsLigne = scalar(@Ligne);
if($nbMotsLigne == 0) { next;
} else { $nbMots += $nbMotsLigne;
}
$Recueil{$poeme}{"nombre_lignes"}++;
foreach my $mot (@Ligne) {
if(exists($Symboles{$mot})) { $nbMotsLigne--;
next;
} if(length($mot) == 1 && !exists($Symboles{$mot}) && !exists($Voyelles{$mot}) && !exists($Consonnes{$mot})) { $nbMotsLigne--;
next;
}
$mot = &nettoieMot($mot);
if(!exists($Mots{$mot})) { $Mots{$mot} = 1;
} else { $Mots{$mot}++;
}
$lengthCumul += length($mot);
}
} $Recueil{$poeme}{"longueur_mot_moyenne"} = $lengthCumul / $nbMots;
close fREC;
my $freqMax = 0;
my $motMax;
while((my $mot,my $freq) = each(%Mots)) { if($freq > $freqMax) { $motMax = $mot;
$freqMax = $freq;
} }
}
sub deuxiemePassage { my $ligne;
my $indLigne;
my $lastRatio;
my $compteur = 0;
my $poeme = undef;
while(<fREC>) {
chomp;
$ligne = $_;
my @Ligne = split(/\s+/,$ligne);
if($poeme) { &retournementPoetivites ($poeme);
}
$poeme = $1;
$compteur++;
print fLOG "\tPoeme " . $compteur . " : " . $poeme . "\n";
$indLigne = 0;
$lastRatio = undef;
next;
}
my $nbMotsLigne = scalar(@Ligne);
if($nbMotsLigne == 0) { next;
}
my $mot;
$indLigne++;
for(my $indMot = 1 ;
$indMot <= $nbMotsLigne ;
$indMot++) {
$mot = $Ligne[$indMot-1];
if(exists($Symboles{$mot})) { next;
} if(length($mot) == 1 && !exists($Symboles{$mot}) && !exists($Voyelles{$mot}) && !exists($Consonnes{$mot})) { next;
}
$mot = &nettoieMot($mot);
my $poetivite = 0;
$poetivite += max(values(%Mots)) / $Mots{$mot};
my $nbLettresMot = length($mot);
$poetivite *= abs($nbLettresMot - $Recueil{$poeme}{"longueur_mot_moyenne"});
$poetivite *= 1 + $indLigne / $Recueil{$poeme}{"nombre_lignes"};
$poetivite *= 1 + $indMot / $nbMotsLigne;
my @Mot = split(//,$mot);
my $nbVoyelles = 0;
my $nbConsonnes = 0;
my $nbSymboles = 1;
foreach my $lettre (@Mot) { if (exists $Voyelles{$lettre}) { $Voyelles{$lettre}++;
$nbVoyelles ++;
} else { if (exists $Consonnes{$lettre}) { $Consonnes{$lettre}++;
$nbConsonnes ++;
} else { if (exists $Symboles{$lettre}) { $Symboles{$lettre}++;
$nbSymboles ++;
} else { print "Lettre $lettre non identifiable dans $mot à la ligne $indLigne\n";
next;
} } } } if($mot =~ m/au/) {$nbVoyelles--;
}
my $ratio = $nbVoyelles / $nbLettresMot;
if($ratio == 0 || $ratio == 1) { $poetivite *= $nbLettresMot;
if($lastRatio) { if(($lastRatio - $ratio) == 0) { $poetivite *= $nbLettresMot * $nbLettresMot;
} } } else { if($ratio < (1/3)) { $poetivite *= 1/$ratio;
if($lastRatio) { if($ratio <= $lastRatio) { $poetivite *= $lastRatio / $ratio + 1;
} } } else { if($ratio > (2/3)) { $poetivite *= 1/(1-$ratio);
if($lastRatio) { if($ratio >= $lastRatio) { $poetivite *= $ratio / $lastRatio + 1;
} } } else {$poetivite *= 1;
} } } $lastRatio = $ratio;
if($mot =~ /'/) {$nbSymboles--;
} $poetivite *= 1 + $nbSymboles;
if (exists $Symboles{$Mot[0]}) { $poetivite *= 1 + $nbSymboles;
}
$poetivite = int($poetivite + 0.5);
push(@{$Recueil{$poeme}{"Mots"}{$mot}},$poetivite);
}
}
&retournementPoetivites($poeme);
}
function isCloseColor($myImage,$myColor,$rref,$gref,$bref,$rmax) { $myRGBColor = array();
$myRGBColor = imagecolorsforindex($myImage,$myColor);
return (sqrt(pow($myRGBColor["red"]-$rref,2)+pow($myRGBColor["green"]-$gref,2)+pow($myRGBColor["blue"]-$bref,2)) < $rmax);
} function horizonoise($myImage,$dimImage,$strength) { $currColor = imagecolorat($myImage,0,0);
for($i = 0 ;
$i < $dimImage[1] ;
$i++) { for($j = 0 ;
$j < $dimImage[0] ;
$j++) {
if(rand(1,100) >= $strength) { $currColor = imagecolorat($myImage,$j,$i);
} else { imagesetpixel($myImage,$j,$i,$currColor);
}
} if($i != $dimImage[1] - 1) $currColor = imagecolorat($myImage,0,$i+1);
} } function vertinoise($myImage,$dimImage,$strength) { $currColor = imagecolorat($myImage,0,0);
for($i = 0 ;
$i < $dimImage[0] ;
$i++) { for($j = 0 ;
$j < $dimImage[1] ;
$j++) { if(rand(1,100) >= $strength) { $currColor = imagecolorat($myImage,$i,$j);
} else { imagesetpixel($myImage,$i,$j,$currColor);
} } if($i != $dimImage[0] - 1) $currColor = imagecolorat($myImage,$i+1,0);
} } function detoureAndPaste($myImage,$myImageOrigin,$dimImage) { $backColor = imagecolorat($myImageOrigin,1,1);
for($i = 0 ;
$i < $dimImage[0] ;
$i++) { for($j = 0 ;
$j < $dimImage[1] ;
$j++) { $currColor = imagecolorat($myImageOrigin,$i,$j);
if($currColor != $backColor) { $aRGB = array();
$aRGB = imagecolorsforindex($myImageOrigin,$currColor);
imagesetpixel($myImage,$i,$j,imagecolorclosest($myImage,$aRGB["red"],$aRGB["green"],$aRGB["blue"]));
} } } } function licqefacnoise($myImage,$dimImage) { $currColor = imagecolorat($myImage,0,0);
for($i = 0 ;
$i < $dimImage[0] ;
$i++) { for($j = 0 ;
$j < $dimImage[1] ;
$j++) { if(rand(1,$dimImage[1]) >= intval($j*1.0)) { $currColor = imagecolorat($myImage,$i,$j);
} else { imagesetpixel($myImage,$i,$j,$currColor);
} } if($i != $dimImage[0] - 1) $currColor = imagecolorat($myImage,$i+1,0);
} } function linenoise($myImage,$dimImage,$strength,$freq) { $indexWhite = imagecolorexact($myImage,255,255,255);
if($indexWhite == -1) $indexWhite = imagecolorclosest($myImage,255,255,255);
$indexBlack = imagecolorexact($myImage,0,0,0);
if($indexBlack == -1) $indexBlack = imagecolorclosest($myImage,0,0,0);
for($i = 0 ;
$i < $dimImage[0] ;
$i++) { for($j = 0 ;
$j < $dimImage[1] ;
$j++) { if(rand(1,$freq) >= 2) {
} else { $currColor = imagecolorat($myImage,$i,$j);
if($currColor == $indexWhite) continue;
$nb_lignes = rand(1,$strength);
drawLignes($myImage,$dimImage,$currColor,$i,$j,$nb_lignes,$strength);
} } } }
function copyAndPasteWithNoise($myImageSrc,$myImageDest,$dimImage,$strength) {
$maxNoise = $dimImage[0]*$dimImage[1];
$noise = intval(rand(0.1*$maxNoise,$maxNoise));
for($i = 0 ;
$i < $noise ;
$i++) { $width = rand(1,$strength);
$height = rand(1,$strength);
$srcX = rand(0,$dimImage[0]-$strength);
$srcY = rand(0,$dimImage[1]-$strength);
$currColor = imagecolorat($myImageSrc,$srcX,$srcY);
if(isCloseColor($myImageSrc,$currColor,255,255,255,2)) continue;
$destX = rand($srcX - $strength,$srcX + $strength);
$destY = rand($srcY - $strength,$srcY + $strength);
$xplusw = $srcX + $width;
if($xplusw >= $dimImage[0]) $width -= $xplusw - $dimImage[0];
$yplush = $srcY + $height;
if($yplush >= $dimImage[1]) $height -= $yplush - $dimImage[1];
if($destX < 0) $destX = 0;
if($destY < 0) $destY = 0;
$dxplusw = $destX + $width;
if($dxplusw >= $dimImage[0]) $destX -= $dxplusw - $dimImage[0];
$dyplush = $destY + $height;
if($dyplush >= $dimImage[1]) $destY -= $dyplush - $dimImage[1];
imagecopy($myImageDest,$myImageSrc,$destX,$destY,$srcX,$srcY,$width,$height);
} } function copyAndPasteNormal($myImageSrc,$myImageDest,$dimImage,$strength) {
$maxNoise = rand(intval($strength/2),intval($strength*5));
if($maxNoise == 0) $maxNoise = 1;
for($i = 0 ;
$i < $maxNoise ;
$i++) { $width = rand(5,intval($dimImage[0]/5));
$height = rand(5,intval($dimImage[1]/5));
$srcX = rand(0,$dimImage[0]-5);
$srcY = rand(0,$dimImage[1]-5);
$destWidth = $width;
$destHeight = $height;
$ratioX = $destWidth/$width;
$ratioY = $destHeight/$height;
$destX = rand($srcX - intval(5*$ratioX),$srcX + intval(5*$ratioX));
$destY = rand($srcY - intval(5*$ratioY),$srcY + intval(5*$ratioY));
$xplusw = $srcX + $width;
if($xplusw >= $dimImage[0]) $width -= $xplusw - $dimImage[0];
$yplush = $srcY + $height;
if($yplush >= $dimImage[1]) $height -= $yplush - $dimImage[1];
if($destX < 0) $destX = 0;
if($destY < 0) $destY = 0;
$dxplusw = $destX + $destWidth;
if($dxplusw >= $dimImage[0]) $destX -= $dxplusw - $dimImage[0];
$dyplush = $destY + $destHeight;
if($dyplush >= $dimImage[1]) $destY -= $dyplush - $dimImage[1];
imagecopy($myImageDest,$myImageSrc,$destX,$destY,$srcX,$srcY,$width,$height);
} } function copyAndPasteDeform($myImageSrc,$myImageDest,$dimImage,$strength) {
$maxNoise = rand(intval($strength/2),intval($strength*5));
if($maxNoise == 0) $maxNoise = 1;
for($i = 0 ;
$i < $maxNoise ;
$i++) { $width = rand(5,intval($dimImage[0]/5));
$height = rand(5,intval($dimImage[1]/5));
$srcX = rand(0,$dimImage[0]-5);
$srcY = rand(0,$dimImage[1]-5);
$destWidth = rand($width,intval(2.5*$width));
$destHeight = rand($height,intval(2.5*$height));
$ratioX = $destWidth/$width;
$ratioY = $destHeight/$height;
$destX = rand($srcX - intval(5*$ratioX),$srcX + intval(5*$ratioX));
$destY = rand($srcY - intval(5*$ratioY),$srcY + intval(5*$ratioY));
$xplusw = $srcX + $width;
if($xplusw >= $dimImage[0]) $width -= $xplusw - $dimImage[0];
$yplush = $srcY + $height;
if($yplush >= $dimImage[1]) $height -= $yplush - $dimImage[1];
if($destX < 0) $destX = 0;
if($destY < 0) $destY = 0;
$dxplusw = $destX + $destWidth;
if($dxplusw >= $dimImage[0]) $destX -= $dxplusw - $dimImage[0];
$dyplush = $destY + $destHeight;
if($dyplush >= $dimImage[1]) $destY -= $dyplush - $dimImage[1];
imagecopyresized($myImageDest,$myImageSrc,$destX,$destY,$srcX,$srcY,$destWidth,$destHeight,$width,$height);
} } function check_extension($file,$extensions) { $extension = strrchr($file, '.');
return in_array($extension, $extensions);
}