You are here: Re: line drawing? « All PHP « IT news, forums, messages
Re: line drawing?

Posted by Norman Peelman on 11/24/06 20:49

"marko" <marko@nullepart.eu> wrote in message
news:4566f0b7$0$17493$426a74cc@news.free.fr...
> Hi everyone,
> I'm looking for a way to draw a line that will zig-zag its way thru an
> image randomly, crisscrossing itself many times, based on random numbers
> _and_ php.
>
> To give you an idea of what I'd like to do, here's a link to a gif :
> http://www.chaosmos.net/chaosmoseng/chaosmos7.htm
>
> I've spent a lot of time googling about how to draw that kind of line
> with php but I only came across how to draw texts, charts and pies.
>
> Is there a way to do that or am I barking up the wrong tree?
>
> Thanks for your answers
>
> marko


You need to use the GD image functions:

0) pick number (random?) of iterations for entire image
1) pick a random start point ($startX, $startY)
2) pick a random direction to move in ($directionX, $directionY), could
be -1, 0, or 1 for each
3) pick a random number of moves ($move)
4) loop $move times placing pixels in the image
5) loop back to 2

basic code snippet (uses no 'real' math), you'll need to read up on some
geometric math to do fancier.
---

// create image here

$directions = array(-1,0,1);

$startX = rand(0, $imageW); // image width
$startY = rand(0, $imageH); // image height
$iterations = rand(5000,15000); // 10000 iterations
for ($main_loop = 0; $main_loop <= $iterations, $main_loop++)
{
$tmp = rand(0,2);
$directionX = $directions[$tmp];
$tmp = rand(0,2);
$directionY = $directions[$tmp];

$moves = rand(5,100);

for ($draw_loop = 0, $draw_loop <= $moves, $draw_loop++)
{
if ((($startX + $directionX) >= 0) AND (($startX + $directionX) <=
$imageW)))
{
$startX += $directionX;
}
if ((($startY + $directionY) >= 0) AND (($startY + $directionY) <=
$imageH)))
{
$startY += $directionY;
}
// place pixel draw function here using $startX, and $startY as the
coords
}
}
// output image here
---

Can probably be done with less code, but this is just off the top of my head
to get you started...

Norm

 

Navigation:

[Reply to this message]


Удаленная работа для программистов  •  Как заработать на Google AdSense  •  England, UK  •  статьи на английском  •  PHP MySQL CMS Apache Oscommerce  •  Online Business Knowledge Base  •  DVD MP3 AVI MP4 players codecs conversion help
Home  •  Search  •  Site Map  •  Set as Homepage  •  Add to Favourites

Copyright © 2005-2006 Powered by Custom PHP Programming

Сайт изготовлен в Студии Валентина Петручека
изготовление и поддержка веб-сайтов, разработка программного обеспечения, поисковая оптимизация