Море волнуется раз ..., или Капча 4D
Как то я уже писал топик про каптчу 3D

А вчера решил слегка переделать, добавить рюшечек и еще одно измерение.
Долго сказка пишется, да быстро дело делается, рушил сделал и вот наваялгиперкуб Капчу 4D.
Пара примеров:


Код также прилагается:
Приятного понедельника, хабра товарищи!
PS. Эта капча не предназначено для использования в качестве капчи (ломает пользователям мозг, и забивает канал трафиком)

А вчера решил слегка переделать, добавить рюшечек и еще одно измерение.
Долго сказка пишется, да быстро дело делается, рушил сделал и вот наваял
Пара примеров:


Код также прилагается:
- <pre>
- <?php
- /**
- * @author Andrii Kasian
- */
-
- $captcha = new Captcha4d();
- $captcha->render();
-
-
- class Captcha4d{
- const CHARS = 'WEafRTYIPAGHJKXBNM3479j';
- protected $hypot = 5;
- protected $image = null;
- protected $_sin = array();
- protected $text = '';
-
- public function __construct()
- {
- $this->time = microtime(true);
- $this->generateCode();
-
- }
- protected function generateCode()
- {
- $chars = self::CHARS;
- for($i =; $i<3; $i++){
- $this->text .= $chars{ mt_rand(,22)};
- }
- }
-
- public function getText()
- {
- return $this->text;
- }
- protected function getProection($x, $y, $z)
- {
-
- $xx = 0.70710;
- $xz = ;
- $xy = 0.70710;
-
- $yx = 0.40824;
- $yz = 0.81649;
- $yy = -0.40824;
-
- $cx = $xx*$x + $xy*$y + $xz*$z - 5;
- $cy = $yx*$x + $yy*$y + $yz*$z + 20;
- return array(
- 'x' => $cx * $this->hypot,
- 'y' => $cy * $this->hypot
- );
- }
-
- function zFunction($x,$y){
- $z = imagecolorat($this->image,$y/2,$x/2)>?3:;
- if( $z != ){
- $z += -2+ 2*
- $this->_sin[($x+$this->startX)%30]
- *
- $this->_sin[($y+$this->startY)%30];
- }
- $z += mt_rand(,30)/50;
- return $z;
- }
- public function render()
- {
- $xx = 30;
- $yy = 60;
-
- $animation = new Imagick();
- $animation->setFormat( "gif" );
-
- $cw = new ImagickPixel("white");
- $cb = new ImagickPixel("#000000");
-
- $this->image = imageCreateTrueColor(100, 20);
-
- $whiteColor = imageColorAllocate($this->image,255,255,255);
- imageFilledRectangle($this->image,,,$yy * $this->hypot , $xx * $this->hypot, $whiteColor);
- $textColor = imageColorAllocate($this->image,,,);
- imageString($this->image, 5, 3, , $this->text, $textColor);
-
- $cof = 2*3.141592654/$xx;
- for($x = ; $x < $xx + 1; $x++){
- $this->_sin[$x] = sin($x*$cof);
- }
- $this->startX = mt_rand(,$xx);
- $this->startY = mt_rand(,$yy);
-
- $draw = new ImagickDraw();
- $countFrame = 25;
-
- for ( $i = ; $i < $countFrame; $i++ ) {
- $this->startX += $xx / $countFrame;
-
- $coordinates = array();
- for($x = ; $x < $xx + 1; $x++){
- for($y = ; $y < $yy + 1; $y++){
- $coordinates[$x][$y] = $this->getProection($x,$y,$this->zFunction($x,$y));
- }
- }
-
- $animation->newImage( $yy * $this->hypot , $xx * $this->hypot, $cw);
-
- $im = new ImagickDraw();
- $im->setFillColor($cw);
- $im->setStrokeColor($cb);
- $im->setStrokeAntialias(true);
- for($x = ; $x < $xx; $x++){
- for($y = ; $y < $yy; $y++){
- $coord = array();
- $coord[] = $coordinates[$x][$y];
- $coord[] = $coordinates[$x+1][$y];
- $coord[] = $coordinates[$x+1][$y+1];
- $coord[] = $coordinates[$x][$y+1];
-
- $im->polygon($coord);
- }
- }
- $animation->drawImage($im);
- $animation->setImageDelay( 100/$countFrame );
- }
-
- header( "Content-Type: image/gif" );
- echo $animation->getImagesBlob();die();
- }
- }
Приятного понедельника, хабра товарищи!
PS. Эта капча не предназначено для использования в качестве капчи (ломает пользователям мозг, и забивает канал трафиком)



комментарии (139)