All pastes #49062 Raw Edit

Ahroun

public text v1 · immutable
#49062 ·published 2006-04-11 20:08 UTC
rendered paste body
<?php

    $sides = 7;
    $rotation = 0.0;
    $pixels = 500;
    $current = array( $pixels/2, $pixels/2);

    $image = imagecreatetruecolor($pixels, $pixels);

    // Generate the shape points
    for($i = 0; $i < $sides; $i++)
    {
        $points[$i*2]     = round((sin($rotation) * ($pixels / 2)) + ($pixels / 2), 1);
        $points[$i*2 + 1] = round((cos($rotation) * ($pixels / 2)) + ($pixels / 2), 1);
        $rotation         = fmod(($rotation + (2 * M_PI) / $sides), (2 * M_PI));
    }

    $black = imagecolorallocate($image, 0x00, 0x00, 0x00);
    $white = imagecolorallocate($image, 0xFF, 0xFF, 0xFF);
    
    // White background.
    imagefill( $image, 0, 0, $white );

    // Generate the polygon
    imagepolygon($image, $points, $sides, $black);
    imagesetpixel($image, $current[0], $current[1], $black); // initial point.

    // Generate the shape now.
    while( TRUE ) // infinite loop intentional.
    {
        for( $i = 0; $i < 100000; $i++ )
        {
            $randnum = rand() % $sides;
            $current[0] = round(($current[0] + $points[$randnum*2    ] )/2, 1);
            $current[1] = round(($current[1] + $points[$randnum*2 + 1] )/2, 1);
            imagesetpixel($image, $current[0], $current[1], $black);
        }

        if( file_exists("stop") )
            break;
    }

    $image = imagerotate( $image, 180, $white);
    imagegif($image, "serp.gif");
?>