[php] Horloge - enfants

Bonjour,

Je cherche a réaliser un petit programme pour les enfants qui commence a apprendre l'heure, en leurs générant des heures "JUSTE" et en les intérogants. Mais j'ai un problème je n'arrive pas à afficher sur la même page et l'horloge et le formulaire.

pourriez-vous m'aidée?

Merci

Caroline

horloge

<?php
//session_start();
mt_srand((float) microtime()*1000000);
$a = mt_rand(0, 12);
$b = 0;

/* Clock & Date Image v1
By Richard James Kendall
Bugs to richard@richardjameskendall.com
Free to use, please acknowledge me

Edit the default variables (if you want).
It is ready to go!
*/

// the only setting is the default clock width, this is used if no
// width is specified by the requesting party
$clock_width = 50;
$show_date = false;

if (isset($_GET["width"])) {
$clock_width = $_GET["width"];
}
if (isset($_GET["date"])) {
$show_date = $_GET["date"];
}

$clock_origin = (17 + ($clock_width / 2));

function calcrad($u, $t) {
$u -= ($t / 4);
if ($u < 0) {
$u += $t;
}
return deg2rad(abs((360 / $t)) * $u);
}

$im = imagecreate(($clock_width + 110), ($clock_width + 40));
$white = imagecolorallocate($im, 255, 255, 255);
$clock_b_col = imagecolorallocate($im, 0, 0, 0);
$clock_hh_col = imagecolorallocate($im, 130, 130, 130);
$clock_mh_col = imagecolorallocate($im, 200, 200, 200);
$clock_sh_col = imagecolorallocate($im, 144, 192, 232);
//imagearc($im, $clock_origin, $clock_origin, $clock_width, $clock_width, 0, 360, $clock_b_col);
imagerectangle($im, 0, 0, ($clock_width + 110) - 1, ($clock_width + 40) - 1, $clock_b_col);
$hour = $a;
$minute =$b;
//$second = date("s");

$h_angle = calcrad($hour, 12);
$m_angle = calcrad($minute, 60);
//$s_angle = calcrad($second, 60);

$h_adjust = deg2rad(((360 / 12) / 60) * $minute);

$hour_x = (($clock_width / 2) - (0.2 * $clock_width)) * cos($h_angle + $h_adjust) + $clock_origin;
$hour_y = (($clock_width / 2) - (0.2 * $clock_width)) * sin($h_angle + $h_adjust) + $clock_origin;

$minute_x = (($clock_width / 2) - (0.05 * $clock_width)) * cos($m_angle) + $clock_origin;
$minute_y = (($clock_width / 2) - (0.05 * $clock_width)) * sin($m_angle) + $clock_origin;

//$second_x = (($clock_width / 2) - (0.05 * $clock_width)) * cos($s_angle) + $clock_origin;
//$second_y = (($clock_width / 2) - (0.05 * $clock_width)) * sin($s_angle) + $clock_origin;

imageline($im, $clock_origin, $clock_origin, $hour_x, $hour_y, $clock_hh_col);
imageline($im, $clock_origin, $clock_origin, $minute_x, $minute_y, $clock_mh_col);
$line_style = array($clock_sh_col, $clock_sh_col, $clock_sh_col, $clock_sh_col, $clock_sh_col, $white, $white, $white, $white, $white);
imagesetstyle($im, $line_style);
//imageline($im, $clock_origin, $clock_origin, $second_x, $second_y, IMG_COLOR_STYLED);

for($i = 1;$i <= 12;$i++) {
$n_angle = calcrad($i, 12);
$num_x = (($clock_width / 2) + 5) * cos($n_angle) + $clock_origin;
$num_y = (($clock_width / 2) + 5) * sin($n_angle) + $clock_origin;
imagestring($im, 1, $num_x, $num_y, $i, $clock_b_col);
}

if ($show_date) {
$d_angle = calcrad(3, 12);
$date_x = (($clock_width / 2) + 20) * cos($d_angle) + $clock_origin;
$date_y = ($clock_width / 2) * sin($d_angle) + $clock_origin;
imagestring($im, 2, $date_x, $date_y - 4, date("d/m/Y"), $clock_b_col);
}

header("Content-type: image/png");
imagepng($im);
imagedestroy($im);
?>

Formulaire que j'aimerai intégrer

<html><body>
<form action="rep.php" method="post">
<input type="text" name="reponse" />
<input type="submit" VALUE=" Vérifie ta réponse... "/>
</form></div>
<p> </p>
<p> </p>
<p> </p>
</BODY>
</HTML>

3 réponses

  1. Juste pour dire : je suis en train de faire le tout, patience :) . J'espère que ce sera suffisant .
    1. Bon voilà :).
      Les problèmes sont :
      - on détermine assez mal les minutes .
      -les réponses doivent se faire entre 0 et 12, pas de 21 heures mais 9 heures :-( .

      Sinon ça devrait aller .... Je corrigerai peut-être ( sûrement en fait ) dans le week-end, sauf si une bonne âme s'y attèle avant moi.

      Donc, dans le fichier nommé horloge_appel.php ( le nom doit être respecté :-( ) on a :
      <?
      $a = $_GET['a'] ;
      if (empty($a))
      {
      $a = mt_rand(0,12);
      $b = mt_rand(0,60);
      }
      else
      {
      $a = $_GET['a'] ;
      $b = $_GET['b'] ;
      }
      $action = $_POST['action'];
      if ($action != "yes" )
      {
      echo "<form method=\"post\" action=\"horloge_appel.php?a=$a&b=$b\"><input name=\"heure\" value=\"Entre l'heure\" onFocus=\"
      if (this.value=='Entre l\'heure') {this.value=''}\">
      <input name=\"minutes\" value=\"Entre les minutes\" onFocus=\"
      if (this.value=='Entre les minutes') {this.value=''}\"><br\><input type=\"hidden\" name=\"action\" value=\"yes\"><input type=\"submit\" value=\"Verifie la réponse\"></form>";
      echo "<br\><br\><img src=\"horloge.php?a=$a&b=$b\">" ;
      }
      else
      {
      echo "Tu as répondu $heure:$minutes<br\>La réponse est";
      if ($a == $heure && $b == $minutes )
      {
      echo "<span style=\"color:#33ff33;font-weight:bold;\"> juste</span>";
      }
      else
      {
      echo "<span style=\"color:#ff3333;font-weight:bold;\"> faux car la réponse était $a:$b</span>";
      }
      echo "<br\><br\><img src=\"horloge.php?a=$a&b=$b\">";
      }
      ?>

      Et dans le fichier horloge.php on a :

      <?
      header("Content-type: image/png");
      $a = $_GET['a'] ;
      $b = $_GET['b'] ;
      $clock_width = 500;
      $show_date = false;
      if (isset($_GET["width"])) {
      $clock_width = $_GET["width"];
      }
      if (isset($_GET["date"])) {
      $show_date = $_GET["date"];
      }
      $clock_origin = (17 + ($clock_width / 2));
      function calcrad($u, $t) {
      $u -= ($t / 4);
      if ($u < 0) {
      $u += $t;
      }
      return deg2rad(abs((360 / $t)) * $u);
      }
      $im = imagecreate(($clock_width + 110), ($clock_width + 40));
      $white = imagecolorallocate($im, 255, 255, 255);
      $clock_b_col = imagecolorallocate($im, 0, 0, 0);
      $clock_h_col = imagecolorallocate($im,255,50,50) ;
      $clock_hh_col = imagecolorallocate($im, 130, 130, 130);
      $clock_mh_col = imagecolorallocate($im, 200, 200, 200);
      $clock_sh_col = imagecolorallocate($im, 144, 192, 232);
      imagearc($im, $clock_origin, $clock_origin, $clock_width, $clock_width, 0, 360, $clock_b_col);
      imagerectangle($im, 0, 0, ($clock_width + 110) - 1, ($clock_width + 40) - 1, $clock_b_col);
      $hour = $a;
      $minute =$b;
      $h_angle = calcrad($hour, 12);
      $m_angle = calcrad($minute, 60);
      $s_angle = calcrad($second, 60);
      $h_adjust = deg2rad(((360 / 12) / 60) * $minute);
      $hour_x = (($clock_width / 2) - (0.2 * $clock_width)) * cos($h_angle + $h_adjust) + $clock_origin;
      $hour_y = (($clock_width / 2) - (0.2 * $clock_width)) * sin($h_angle + $h_adjust) + $clock_origin;
      $minute_x = (($clock_width / 2) - (0.05 * $clock_width)) * cos($m_angle) + $clock_origin;
      $minute_y = (($clock_width / 2) - (0.05 * $clock_width)) * sin($m_angle) + $clock_origin;
      imageline($im, $clock_origin, $clock_origin, $hour_x, $hour_y, $clock_hh_col);
      imageline($im, $clock_origin, $clock_origin, $minute_x, $minute_y, $clock_mh_col);
      $line_style = array($clock_sh_col, $clock_sh_col, $clock_sh_col, $clock_sh_col, $clock_sh_col, $white, $white, $white, $white, $white);
      imagesetstyle($im, $line_style);
      for($i = 1;$i <= 12;$i++) {
      $n_angle = calcrad($i, 12);
      $num_x = (($clock_width / 2) + 5) * cos($n_angle) + $clock_origin;
      $num_y = (($clock_width / 2) + 5) * sin($n_angle) + $clock_origin;
      imagestring($im, 4, $num_x, $num_y, $i, $clock_h_col);
      }
      if ($show_date) {
      $d_angle = calcrad(3, 12);
      $date_x = (($clock_width / 2) + 20) * cos($d_angle) + $clock_origin;
      $date_y = ($clock_width / 2) * sin($d_angle) + $clock_origin;
      imagestring($im, 2, $date_x, $date_y - 4, date("d/m/Y"), $clock_b_col);
      }
      imagepng($im);
      ?>

      :-) .

      Je l'ai hosté sur mon site pour le tester, donc c'est là :
      http://alexlink.free.fr/horloge_appel.php .

      alexlink2@wanadoo.fr si tu as besoin de précisions caroline.
      1. Merci,

        Je décortiquerai cela bientôt car ca ma l'air assez compliqué, et il me faudra un peu de temps.

        merci alexlink.