Verzeichnisstruktur phpBB-3.1.0


Veröffentlicht
27.10.2014

So funktioniert es


Auf das letzte Element klicken. Dies geht jeweils ein Schritt zurück

Auf das Icon klicken, dies öffnet das Verzeichnis. Nochmal klicken schließt das Verzeichnis.
Auf den Verzeichnisnamen klicken, dies zeigt nur das Verzeichnis mit Inhalt an

      (Beispiel Datei-Icons)

Auf das Icon klicken um den Quellcode anzuzeigen

char_cube3d.php

Zuletzt modifiziert: 09.10.2024, 12:51 - Dateigröße: 7.29 KiB


 001  <?php
 002  /**
 003  *
 004  * This file is part of the phpBB Forum Software package.
 005  *
 006  * @copyright (c) phpBB Limited <https://www.phpbb.com>
 007  * @license GNU General Public License, version 2 (GPL-2.0)
 008  *
 009  * For full copyright and license information, please see
 010  * the docs/CREDITS.txt file.
 011  *
 012  */
 013   
 014  namespace phpbb\captcha;
 015   
 016  class char_cube3d
 017  {
 018      var $bitmap;
 019      var $bitmap_width;
 020      var $bitmap_height;
 021   
 022      var $basis_matrix = array(array(1, 0, 0), array(0, 1, 0), array(0, 0, 1));
 023      var $abs_x = array(1, 0);
 024      var $abs_y = array(0, 1);
 025      var $x = 0;
 026      var $y = 1;
 027      var $z = 2;
 028      var $letter = '';
 029   
 030      /**
 031      */
 032      function __construct(&$bitmaps, $letter)
 033      {
 034          $this->bitmap            = $bitmaps['data'][$letter];
 035          $this->bitmap_width        = $bitmaps['width'];
 036          $this->bitmap_height    = $bitmaps['height'];
 037   
 038          $this->basis_matrix[0][0] = mt_rand(-600, 600);
 039          $this->basis_matrix[0][1] = mt_rand(-600, 600);
 040          $this->basis_matrix[0][2] = (mt_rand(0, 1) * 2000) - 1000;
 041          $this->basis_matrix[1][0] = mt_rand(-1000, 1000);
 042          $this->basis_matrix[1][1] = mt_rand(-1000, 1000);
 043          $this->basis_matrix[1][2] = mt_rand(-1000, 1000);
 044   
 045          $this->normalize($this->basis_matrix[0]);
 046          $this->normalize($this->basis_matrix[1]);
 047          $this->basis_matrix[2] = $this->cross_product($this->basis_matrix[0], $this->basis_matrix[1]);
 048          $this->normalize($this->basis_matrix[2]);
 049   
 050          // $this->basis_matrix[1] might not be (probably isn't) orthogonal to $basis_matrix[0]
 051          $this->basis_matrix[1] = $this->cross_product($this->basis_matrix[0], $this->basis_matrix[2]);
 052          $this->normalize($this->basis_matrix[1]);
 053   
 054          // Make sure our cube is facing into the canvas (assuming +z == in)
 055          for ($i = 0; $i < 3; ++$i)
 056          {
 057              if ($this->basis_matrix[$i][2] < 0)
 058              {
 059                  $this->basis_matrix[$i][0] *= -1;
 060                  $this->basis_matrix[$i][1] *= -1;
 061                  $this->basis_matrix[$i][2] *= -1;
 062              }
 063          }
 064   
 065          // Force our "z" basis vector to be the one with greatest absolute z value
 066          $this->x = 0;
 067          $this->y = 1;
 068          $this->z = 2;
 069   
 070          // Swap "y" with "z"
 071          if ($this->basis_matrix[1][2] > $this->basis_matrix[2][2])
 072          {
 073              $this->z = 1;
 074              $this->y = 2;
 075          }
 076   
 077          // Swap "x" with "z"
 078          if ($this->basis_matrix[0][2] > $this->basis_matrix[$this->z][2])
 079          {
 080              $this->x = $this->z;
 081              $this->z = 0;
 082          }
 083   
 084          // Still need to determine which of $x,$y are which.
 085          // wrong orientation if y's y-component is less than it's x-component
 086          // likewise if x's x-component is less than it's y-component
 087          // if they disagree, go with the one with the greater weight difference.
 088          // rotate if positive
 089          $weight = (abs($this->basis_matrix[$this->x][1]) - abs($this->basis_matrix[$this->x][0])) + (abs($this->basis_matrix[$this->y][0]) - abs($this->basis_matrix[$this->y][1]));
 090   
 091          // Swap "x" with "y"
 092          if ($weight > 0)
 093          {
 094              list($this->x, $this->y) = array($this->y, $this->x);
 095          }
 096   
 097          $this->abs_x = array($this->basis_matrix[$this->x][0], $this->basis_matrix[$this->x][1]);
 098          $this->abs_y = array($this->basis_matrix[$this->y][0], $this->basis_matrix[$this->y][1]);
 099   
 100          if ($this->abs_x[0] < 0)
 101          {
 102              $this->abs_x[0] *= -1;
 103              $this->abs_x[1] *= -1;
 104          }
 105   
 106          if ($this->abs_y[1] > 0)
 107          {
 108              $this->abs_y[0] *= -1;
 109              $this->abs_y[1] *= -1;
 110          }
 111   
 112          $this->letter = $letter;
 113      }
 114   
 115      /**
 116      * Draw a character
 117      */
 118      function drawchar($scale, $xoff, $yoff, $img, $background, $colours)
 119      {
 120          $width    = $this->bitmap_width;
 121          $height    = $this->bitmap_height;
 122          $bitmap    = $this->bitmap;
 123   
 124          $colour1 = $colours[array_rand($colours)];
 125          $colour2 = $colours[array_rand($colours)];
 126   
 127          $swapx = ($this->basis_matrix[$this->x][0] > 0);
 128          $swapy = ($this->basis_matrix[$this->y][1] < 0);
 129   
 130          for ($y = 0; $y < $height; ++$y)
 131          {
 132              for ($x = 0; $x < $width; ++$x)
 133              {
 134                  $xp = ($swapx) ? ($width - $x - 1) : $x;
 135                  $yp = ($swapy) ? ($height - $y - 1) : $y;
 136   
 137                  if ($bitmap[$height - $yp - 1][$xp])
 138                  {
 139                      $dx = $this->scale($this->abs_x, ($xp - ($swapx ? ($width / 2) : ($width / 2) - 1)) * $scale);
 140                      $dy = $this->scale($this->abs_y, ($yp - ($swapy ? ($height / 2) : ($height / 2) - 1)) * $scale);
 141                      $xo = $xoff + $dx[0] + $dy[0];
 142                      $yo = $yoff + $dx[1] + $dy[1];
 143   
 144                      $origin = array(0, 0, 0);
 145                      $xvec = $this->scale($this->basis_matrix[$this->x], $scale);
 146                      $yvec = $this->scale($this->basis_matrix[$this->y], $scale);
 147                      $face_corner = $this->sum2($xvec, $yvec);
 148   
 149                      $zvec = $this->scale($this->basis_matrix[$this->z], $scale);
 150                      $x_corner = $this->sum2($xvec, $zvec);
 151                      $y_corner = $this->sum2($yvec, $zvec);
 152   
 153                      imagefilledpolygon($img, $this->gen_poly($xo, $yo, $origin, $xvec, $x_corner,$zvec), 4, $colour1);
 154                      imagefilledpolygon($img, $this->gen_poly($xo, $yo, $origin, $yvec, $y_corner,$zvec), 4, $colour2);
 155   
 156                      $face = $this->gen_poly($xo, $yo, $origin, $xvec, $face_corner, $yvec);
 157   
 158                      imagefilledpolygon($img, $face, 4, $background);
 159                      imagepolygon($img, $face, 4, $colour1);
 160                  }
 161              }
 162          }
 163      }
 164   
 165      /*
 166      * return a roughly acceptable range of sizes for rendering with this texttype
 167      */
 168      function range()
 169      {
 170          return array(3, 4);
 171      }
 172   
 173      /**
 174      * Vector length
 175      */
 176      function vectorlen($vector)
 177      {
 178          return sqrt(pow($vector[0], 2) + pow($vector[1], 2) + pow($vector[2], 2));
 179      }
 180   
 181      /**
 182      * Normalize
 183      */
 184      function normalize(&$vector, $length = 1)
 185      {
 186          $length = (( $length < 1) ? 1 : $length);
 187          $length /= $this->vectorlen($vector);
 188          $vector[0] *= $length;
 189          $vector[1] *= $length;
 190          $vector[2] *= $length;
 191      }
 192   
 193      /**
 194      */
 195      function cross_product($vector1, $vector2)
 196      {
 197          $retval = array(0, 0, 0);
 198          $retval[0] =  (($vector1[1] * $vector2[2]) - ($vector1[2] * $vector2[1]));
 199          $retval[1] = -(($vector1[0] * $vector2[2]) - ($vector1[2] * $vector2[0]));
 200          $retval[2] =  (($vector1[0] * $vector2[1]) - ($vector1[1] * $vector2[0]));
 201   
 202          return $retval;
 203      }
 204   
 205      /**
 206      */
 207      function sum($vector1, $vector2)
 208      {
 209          return array($vector1[0] + $vector2[0], $vector1[1] + $vector2[1], $vector1[2] + $vector2[2]);
 210      }
 211   
 212      /**
 213      */
 214      function sum2($vector1, $vector2)
 215      {
 216          return array($vector1[0] + $vector2[0], $vector1[1] + $vector2[1]);
 217      }
 218   
 219      /**
 220      */
 221      function scale($vector, $length)
 222      {
 223          if (sizeof($vector) == 2)
 224          {
 225              return array($vector[0] * $length, $vector[1] * $length);
 226          }
 227   
 228          return array($vector[0] * $length, $vector[1] * $length, $vector[2] * $length);
 229      }
 230   
 231      /**
 232      */
 233      function gen_poly($xoff, $yoff, &$vec1, &$vec2, &$vec3, &$vec4)
 234      {
 235          $poly = array();
 236          $poly[0] = $xoff + $vec1[0];
 237          $poly[1] = $yoff + $vec1[1];
 238          $poly[2] = $xoff + $vec2[0];
 239          $poly[3] = $yoff + $vec2[1];
 240          $poly[4] = $xoff + $vec3[0];
 241          $poly[5] = $yoff + $vec3[1];
 242          $poly[6] = $xoff + $vec4[0];
 243          $poly[7] = $yoff + $vec4[1];
 244   
 245          return $poly;
 246      }
 247   
 248      /**
 249      * dimensions
 250      */
 251      function dimensions($size)
 252      {
 253          $xn = $this->scale($this->basis_matrix[$this->x], -($this->bitmap_width / 2) * $size);
 254          $xp = $this->scale($this->basis_matrix[$this->x], ($this->bitmap_width / 2) * $size);
 255          $yn = $this->scale($this->basis_matrix[$this->y], -($this->bitmap_height / 2) * $size);
 256          $yp = $this->scale($this->basis_matrix[$this->y], ($this->bitmap_height / 2) * $size);
 257   
 258          $p = array();
 259          $p[0] = $this->sum2($xn, $yn);
 260          $p[1] = $this->sum2($xp, $yn);
 261          $p[2] = $this->sum2($xp, $yp);
 262          $p[3] = $this->sum2($xn, $yp);
 263   
 264          $min_x = $max_x = $p[0][0];
 265          $min_y = $max_y = $p[0][1];
 266   
 267          for ($i = 1; $i < 4; ++$i)
 268          {
 269              $min_x = ($min_x > $p[$i][0]) ? $p[$i][0] : $min_x;
 270              $min_y = ($min_y > $p[$i][1]) ? $p[$i][1] : $min_y;
 271              $max_x = ($max_x < $p[$i][0]) ? $p[$i][0] : $max_x;
 272              $max_y = ($max_y < $p[$i][1]) ? $p[$i][1] : $max_y;
 273          }
 274   
 275          return array($min_x, $min_y, $max_x, $max_y);
 276      }
 277  }
 278