یک الگوریتم جالب! (حتما ببینید!)

my friend

Member
الان داشتم تو کدهام میگشتم ، اینو پیدا کردم:D
کلی خاطره برام زنده کرد:)

دیدم الگوریتم جالبی داره ، گفتم بزارم اینجا تا شما هم باهاش حال کنید:D

PHP:
<?php

//canvas size
$width = 1600;
$height = 1200;

//create and paint the canvas, generate colors to draw the fern
$canvas = imagecreatetruecolor($width,$height);
$white = imagecolorallocate($canvas,255,255,255);
imagefill($canvas,0,0,$white);
for ($n=1;$n<255;$n++) {
    $green[$n] = imagecolorallocatealpha($canvas,0,$n,0,105);
}

//basic fern settings
$max = 80000;
$p1 = 79;
$p2 = 89;
$p3 = 98;
$x = 0;
$y = 0;

for ($n=0;$n<$max;$n++) {

    $p = rand(0,100);
    $xt = $x;
    
    if ($p < $p1) {
        $x = (0.85*$x)+(0.04*$y)+0.075;
        $y = (-0.04*$xt)+(0.85*$y)+0.18;
    } elseif($p < $p2) {
        $x = (0.20*$x)-(0.26*$y)+0.4;
        $y = (0.23*$xt)+(0.22*$y)+0.045;
    } elseif($p < $p3) {
        $x = (-0.15*$x)+(0.28*$y)+0.575;
        $y = (0.26*$xt)+(0.24*$y)-0.086;
    } else {
        $x = 0.5;
        $y = 0.16*$y;
    }
    
    //paint the pixels onto the canvas
    $diameter = rand(1,15);
    imagefilledellipse($canvas, $width-($width*$x), $height-($height*$y), $diameter, $diameter, $green[(100*$y)+(155*$x)]);

}

//Antialias the image sort of .. scale down the big version.
$i = imagecreatetruecolor($width/2, $height/2);
imagecopyresampled($i, $canvas, 0, 0, 0, 0, ($width/2), ($height/2), $width, $height);

header("Content-type: image/png");
imagepng($i);

?>
شما هم اگه از اینجور چیزا دارید دریغ نکنید:)
 

my friend

Member
PHP:
<?php

$image = imagecreatetruecolor(1600,1600);
$white = imagecolorallocate($image,255,255,255);
$black = imagecolorallocate($image,0,0,0);
imagefill($image,0,0,$white);

//User settings
$cog_a=-1;
$cog_b=2;
$i=250;

//Other stuff
$xoffset = 800;
$yoffset = 800;
$ra=$i;
$rb=800-$i;
$xi=$x1=(($ra*cos($cog_a))+($rb*cos($cog_b)));
$yi=$y1=(($ra*sin($cog_a))+($rb*sin($cog_b)));
$ta=$cog_a;
$tb=$cog_b;

do {

    $c++;

    $x2=$x1;
    $y2=$y1;
    $cog_a+=$ta;
    $cog_b+=$tb;
    $x1=(($ra*cos($cog_a))+($rb*cos($cog_b)));
    $y1=(($ra*sin($cog_a))+($rb*sin($cog_b)));

    imageline($image,$x1+$xoffset,$y1+$yoffset,$x2+$xoffset,$y2+$yoffset,$black);

} while (!((abs($x1-$xi)<2)&&(abs($yi-$y1)<2)));

$out = imagecreatetruecolor(800,800);
imagecopyresampled($out,$image,0,0,0,0,800,800,1600,1600);

header("Content-type: image/png");
imagepng($out);
  
imagedestroy($image);
imagedestroy($out);

?>
 

my friend

Member
اولی یک برگ میکشه میکنه که واقعا جالبه.
دومی هم یدونه از این شکل ها که نمیدونم اسمش چیه میکشه! (کوچیک که بودم یه خط کشش رو گرفته بودم که کارم ور رفتن باهاش بود!)
 

جدیدترین ارسال ها

بالا