131 lines
No EOL
12 KiB
HTML
131 lines
No EOL
12 KiB
HTML
<!DOCTYPE html>
|
|
<!-- Page generated by OCaml with Ocsigen.
|
|
See http://ocsigen.org/ and http://caml.inria.fr/ for information -->
|
|
<html class="ada2" lang="fr" id="h" xmlns="http://www.w3.org/1999/xhtml"><head><title>mission1.adb</title><meta content="text/html; charset=utf-8" http-equiv="content-type"/><link media="all" href="../../../ystyle.css" rel="stylesheet"/><script src="../../../Scripts/yfold.js"></script></head><body><div class="header" id="header"><h1 id="title">mission1.adb</h1></div><main><code class="page block"><span class="kw">with</span> <span class="ident">Gada.Text_IO</span> ;<span class="eols">
|
|
|
|
</span><span class="kw">procedure</span> <span class="fname">Mission1</span> <span class="kw">is</span><span class="eols">
|
|
|
|
</span> <span class="kw">package</span> <span class="fname">Txt</span> <span class="kw">renames</span> <span class="ident">GAda.Text_IO</span> ;<span class="eols">
|
|
|
|
</span> <span class="kw">procedure</span> <span class="fname">Tracer_Ligne</span> (<span class="ident">Long</span> : <span class="type">Integer</span>) <span class="kw">is</span>
|
|
<span class="kw">begin</span>
|
|
<span class="comment">-- Tracer n fois le caractère # puis passer à la ligne.
|
|
</span> <span class="kw">for</span> <span class="ident">Colonne</span> <span class="kw">in</span> <span class="number">1</span>..<span class="ident">Long</span> <span class="kw">loop</span>
|
|
<span class="ident">Txt.Put</span>(<span class="string">"#"</span>) ;
|
|
<span class="kw">end</span> <span class="kw">loop</span> ;
|
|
<span class="ident">Txt.New_Line</span> ;
|
|
<span class="kw">end</span> <span class="fname">Tracer_Ligne</span> ;<span class="eols">
|
|
|
|
</span> <span class="kw">procedure</span> <span class="fname">Tracer_Rectangle</span> (<span class="ident">Largeur</span> : <span class="type">Integer</span> ; <span class="ident">Hauteur</span> : <span class="type">Integer</span>) <span class="kw">is</span>
|
|
<span class="kw">begin</span>
|
|
<span class="comment">-- Première ligne, pleine
|
|
</span> <span class="ident">Tracer_Ligne</span>(<span class="ident">Largeur</span>) ;<span class="eols">
|
|
|
|
</span> <span class="comment">-- Les lignes suivantes (de 2 à Hauteur-1) ne contiennent que
|
|
</span> <span class="comment">-- le caractère # du début et celui de la fin.
|
|
</span> <span class="kw">for</span> <span class="ident">Ligne</span> <span class="kw">in</span> <span class="number">2</span>..<span class="ident">Hauteur</span> - <span class="number">1</span> <span class="kw">loop</span>
|
|
<span class="ident">Txt.Put</span>(<span class="string">"#"</span>) ;<span class="eols">
|
|
|
|
</span> <span class="comment">-- Des espaces au milieu.
|
|
</span> <span class="kw">for</span> <span class="ident">Col</span> <span class="kw">in</span> <span class="number">2</span>..<span class="ident">Largeur</span> - <span class="number">1</span> <span class="kw">loop</span>
|
|
<span class="ident">Txt.Put</span>(<span class="string">" "</span>) ;
|
|
<span class="kw">end</span> <span class="kw">loop</span> ;<span class="eols">
|
|
|
|
</span> <span class="ident">Txt.Put</span>(<span class="string">"#"</span>) ;
|
|
<span class="ident">Txt.New_Line</span> ;
|
|
<span class="kw">end</span> <span class="kw">loop</span> ;<span class="eols">
|
|
|
|
</span> <span class="comment">-- La dernière ligne est pleine.
|
|
</span> <span class="ident">Tracer_Ligne</span>(<span class="ident">Largeur</span>) ;
|
|
<span class="ident">Txt.New_Line</span> ;
|
|
<span class="kw">end</span> <span class="fname">Tracer_Rectangle</span> ;<span class="eols">
|
|
|
|
</span> <span class="kw">procedure</span> <span class="fname">Tracer_Quadrillage</span> (<span class="ident">Largeur</span> : <span class="type">Integer</span> ; <span class="ident">Hauteur</span> : <span class="type">Integer</span>) <span class="kw">is</span>
|
|
<span class="kw">begin</span>
|
|
<span class="comment">-- On dessine ligne par ligne, colonne par colonne.
|
|
</span> <span class="kw">for</span> <span class="ident">Ligne</span> <span class="kw">in</span> <span class="number">1</span>..<span class="ident">Hauteur</span> <span class="kw">loop</span>
|
|
<span class="kw">for</span> <span class="ident">Col</span> <span class="kw">in</span> <span class="number">1</span>..<span class="ident">Largeur</span> <span class="kw">loop</span>
|
|
<span class="comment">-- Il suffit de tracer les lignes impaires et les colonnes impaires.
|
|
</span> <span class="kw">if</span> (<span class="ident">Ligne</span> <span class="kw">mod</span> <span class="number">2</span> = <span class="number">1</span>) <span class="kw">or</span> (<span class="ident">Col</span> <span class="kw">mod</span> <span class="number">2</span> = <span class="number">1</span>) <span class="kw">then</span>
|
|
<span class="ident">Txt.Put</span>(<span class="string">"#"</span>) ;
|
|
<span class="kw">else</span>
|
|
<span class="ident">Txt.Put</span>(<span class="string">" "</span>) ;
|
|
<span class="kw">end</span> <span class="kw">if</span> ;
|
|
<span class="kw">end</span> <span class="kw">loop</span> ;
|
|
<span class="ident">Txt.New_Line</span> ;
|
|
<span class="kw">end</span> <span class="kw">loop</span> ;
|
|
<span class="ident">Txt.New_Line</span> ;
|
|
<span class="kw">end</span> <span class="fname">Tracer_Quadrillage</span> ;<span class="eols">
|
|
|
|
</span> <span class="kw">procedure</span> <span class="fname">Tracer_Damier</span> (<span class="ident">Largeur</span> : <span class="type">Integer</span> ; <span class="ident">Hauteur</span> : <span class="type">Integer</span>) <span class="kw">is</span>
|
|
<span class="kw">begin</span>
|
|
<span class="comment">-- Même principe que Tester_Quadrillage
|
|
</span> <span class="kw">for</span> <span class="ident">Ligne</span> <span class="kw">in</span> <span class="number">1</span>..<span class="ident">Hauteur</span> <span class="kw">loop</span>
|
|
<span class="kw">for</span> <span class="ident">Col</span> <span class="kw">in</span> <span class="number">1</span>..<span class="ident">Largeur</span> <span class="kw">loop</span>
|
|
<span class="comment">-- Il suffit de tracer les cases telles que x+y est pair.
|
|
</span> <span class="kw">if</span> (<span class="ident">Ligne</span> + <span class="ident">Col</span>) <span class="kw">mod</span> <span class="number">2</span> = <span class="number">0</span> <span class="kw">then</span>
|
|
<span class="ident">Txt.Put</span>(<span class="string">"#"</span>) ;
|
|
<span class="kw">else</span>
|
|
<span class="ident">Txt.Put</span>(<span class="string">" "</span>) ;
|
|
<span class="kw">end</span> <span class="kw">if</span> ;
|
|
<span class="kw">end</span> <span class="kw">loop</span> ;
|
|
<span class="ident">Txt.New_Line</span> ;
|
|
<span class="kw">end</span> <span class="kw">loop</span> ;
|
|
<span class="ident">Txt.New_Line</span> ;
|
|
<span class="kw">end</span> <span class="fname">Tracer_Damier</span> ;<span class="eols">
|
|
|
|
</span> <span class="kw">procedure</span> <span class="fname">Tracer_Gros_Damier</span> (<span class="ident">Largeur</span> : <span class="type">Integer</span> ; <span class="ident">Hauteur</span> : <span class="type">Integer</span>) <span class="kw">is</span>
|
|
<span class="kw">begin</span>
|
|
<span class="comment">-- Même principe, mais en divisant les coordonnées par 2 pour faire des paquets de 2x2.
|
|
</span> <span class="kw">for</span> <span class="ident">Ligne</span> <span class="kw">in</span> <span class="number">1</span>..<span class="ident">Hauteur</span> <span class="kw">loop</span>
|
|
<span class="kw">for</span> <span class="ident">Col</span> <span class="kw">in</span> <span class="number">1</span>..<span class="ident">Largeur</span> <span class="kw">loop</span><span class="eols">
|
|
|
|
</span> <span class="comment">-- On soustrait 1 car sinon le damier commence au milieu d'un paquet de 2x2 et ce n'est pas joli.
|
|
</span> <span class="kw">if</span> ((<span class="ident">Ligne</span>-<span class="number">1</span>)/<span class="number">2</span> + (<span class="ident">Col</span>-<span class="number">1</span>)/<span class="number">2</span>) <span class="kw">mod</span> <span class="number">2</span> = <span class="number">1</span> <span class="kw">then</span>
|
|
<span class="ident">Txt.Put</span>(<span class="string">"#"</span>) ;
|
|
<span class="kw">else</span>
|
|
<span class="ident">Txt.Put</span>(<span class="string">" "</span>) ;
|
|
<span class="kw">end</span> <span class="kw">if</span> ;
|
|
<span class="kw">end</span> <span class="kw">loop</span> ;
|
|
<span class="ident">Txt.New_Line</span> ;
|
|
<span class="kw">end</span> <span class="kw">loop</span> ;
|
|
<span class="ident">Txt.New_Line</span> ;
|
|
<span class="kw">end</span> <span class="fname">Tracer_Gros_Damier</span> ;<span class="eols">
|
|
|
|
</span><span class="kw">begin</span><span class="eols">
|
|
|
|
</span> <span class="ident">Txt.Put_Line</span>(<span class="string">"Test de Tracer_Ligne : "</span>) ;
|
|
<span class="ident">Txt.New_Line</span> ;<span class="eols">
|
|
|
|
</span> <span class="ident">Tracer_Ligne</span>(<span class="number">3</span>) ;
|
|
<span class="ident">Tracer_Ligne</span>(<span class="number">8</span>) ;
|
|
<span class="ident">Tracer_Ligne</span>(<span class="number">20</span>) ;<span class="eols">
|
|
|
|
</span> <span class="ident">Txt.New_Line</span> ;
|
|
<span class="ident">Txt.Put_Line</span>(<span class="string">"Test de Tracer_Rectangle : "</span>) ;
|
|
<span class="ident">Txt.New_Line</span> ;<span class="eols">
|
|
|
|
</span> <span class="ident">Tracer_Rectangle</span>(<span class="number">5</span>, <span class="number">5</span>) ;
|
|
<span class="ident">Tracer_Rectangle</span>(<span class="number">14</span>, <span class="number">2</span>) ;
|
|
<span class="ident">Tracer_Rectangle</span>(<span class="number">4</span>, <span class="number">6</span>) ;<span class="eols">
|
|
|
|
</span> <span class="ident">Txt.New_Line</span> ;
|
|
<span class="ident">Txt.Put_Line</span>(<span class="string">"Test de Tracer_Quadrillage : "</span>) ;
|
|
<span class="ident">Txt.New_Line</span> ;<span class="eols">
|
|
|
|
</span> <span class="ident">Tracer_Quadrillage</span>(<span class="number">19</span>, <span class="number">11</span>) ;<span class="eols">
|
|
|
|
</span> <span class="ident">Txt.New_Line</span> ;
|
|
<span class="ident">Txt.Put_Line</span>(<span class="string">"Test de Tracer_Damier : "</span>) ;
|
|
<span class="ident">Txt.New_Line</span> ;<span class="eols">
|
|
|
|
</span> <span class="ident">Tracer_Damier</span>(<span class="number">18</span>, <span class="number">10</span>) ;<span class="eols">
|
|
|
|
</span> <span class="ident">Txt.New_Line</span> ;
|
|
<span class="ident">Txt.Put_Line</span>(<span class="string">"Test de Tracer_Gros_Damier : "</span>) ;
|
|
<span class="ident">Txt.New_Line</span> ;<span class="eols">
|
|
|
|
</span> <span class="ident">Tracer_Gros_Damier</span>(<span class="number">18</span>, <span class="number">10</span>) ;<span class="eols">
|
|
|
|
</span><span class="kw">end</span> <span class="fname">Mission1</span> ;
|
|
</code></main><footer><small class="pcom"><a class="caml_c" href="../../../yversion.html" data-eliom-c-onclick="GdR46hGdWKzn">Version information</a></small><a target="_blank" href="http://www.insa-toulouse.fr"><img title="INSA Toulouse" style="width:73px;height:28px;" alt="INSA logo" src="../../../Images/logo-insa-light.jpg"/></a><a target="_blank" href="http://jigsaw.w3.org/css-validator/check/referer"><img title="Validate css stylesheet" style="width:28px;height:32px;" alt="CSS3 logo" src="../../../Images/css3.png"/></a><a target="_blank" href="http://validator.w3.org/check/referer"><img title="Validate html5 content" style="width:32px;height:32px;" alt="HTML5 logo" src="../../../Images/html5.png"/></a></footer></body></html> |