line drawing?

Collapse
This topic is closed.
X
X
 
  • Time
  • Show
Clear All
new posts
  • marko

    #1

    line drawing?

    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 :


    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
  • J.O. Aho

    #2
    Re: line drawing?

    marko wrote:
    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 :

    >
    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
    I guess javascript or even java would be a better option, what I can think of
    you can do with php, would be place out one pixel large images by somewhat
    controlled random (has to have one side connected to another black dot) with
    the help of div-tags (html).


    //Aho

    Comment

    • Bart op de grote markt

      #3
      Re: line drawing?


      J.O. Aho schreef:
      >
      I guess javascript or even java would be a better option, what I can think of
      you can do with php, would be place out one pixel large images by somewhat
      controlled random (has to have one side connected to another black dot) with
      the help of div-tags (html).
      >
      >
      //Aho
      Hmm, I wouldn't do that... I guess there's some overhead then...

      Why not use the image library from php? (http://be.php.net/gd)
      I don't know about it much, but I use it to dynamically create captchas
      and buttons on my site.

      Greets,

      Bart

      Comment

      • Richard Brooks

        #4
        Re: line drawing?

        Bart op de grote markt said the following on 24/11/06 14:32:
        J.O. Aho schreef:
        >
        >I guess javascript or even java would be a better option, what I can think of
        >you can do with php, would be place out one pixel large images by somewhat
        >controlled random (has to have one side connected to another black dot) with
        >the help of div-tags (html).
        >>
        >>
        > //Aho
        >
        Hmm, I wouldn't do that... I guess there's some overhead then...
        >
        Why not use the image library from php? (http://be.php.net/gd)
        I don't know about it much, but I use it to dynamically create captchas
        and buttons on my site.
        >
        Greets,
        >
        Bart
        I think you're on the right track as this little number is in there.

        <http://be.php.net/manual/en/function.imagel ine.php>

        The OP only needs short lines, the end coordinates of the first line
        then become the start coordinates of the next line, the end coordinates
        being part of a random routine all in a short loop.


        Richard.


        --
        "Naturally the common people don't want war, but they can always be
        brought to the bidding of the leaders. Tell them they are being
        attacked and denounce the pacifists for lack of patriotism and
        endangering the country. It works the same in every country."
        Reichsmarshall Herman Goering, Nuremberg, 1946

        Comment

        • Norman Peelman

          #5
          Re: line drawing?

          "marko" <marko@nullepar t.euwrote 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 :

          >
          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


          Comment

          • marko

            #6
            Re: line drawing?

            Norman Peelman a écrit :
            <snip code>
            Can probably be done with less code, but this is just off the top of my head
            to get you started...
            thank you very much, this is really interesting.
            I'll try to add in some curves by looking up at some math.

            thank you!

            m

            Comment

            Working...