Color allocation




Thanks to the people who replied to my last message.  I downloaded gtk--,
looked at it, installed it, and am quite happy.  Except....

(There's always an "except" :)

The fractal engine works, sorta.  I figured out the gtk_idle_add and
_remove functions, and even downloaded Jon Trowbridge's Gtk_Canvas widget
and used that as the base class for the FractalCanvas class.  Rewrote my
previous code to fit into C++, compiled, ran, and waited, and waited and
waited...:)

Wondering why the mandelbrot set was taking aver half an hour to render
(should take a few minutes at the very most) I ran top, and behold! X was
taking up 95% of my CPU time.  Hmm...

After some investigation, I found the offending function call.  I have an
idle function, whose sole purpose in life is to calculate one pixel,
display it, and move on to the next pixel, ready for the idle function to
be called again.  It looks something like this:

void FractalCanvas::idle_function () {

  // fs is the FractalState class //

  if (fs->running ()) {

    // Calculate the pixel //

    fs->iterate ();

    // Paint our window //
    // (one line at a time) //

    guint x = fs->x_pixel ();
    guint y = fs->y_pixel ();
    guint w = fs->width ();

    set_foreground (*(fs->color ()));    <== Bad line o' code
    draw_point (x, y);
    if (x == w - 1)
      refresh (0, y, w, 1);

    // Increment to the next pixel //

    fs->increment ();

  }
  else
    terminate_idle_function ();

}

If I comment out the marked line of code X's share of the CPU drops down
to a reasonable 6%.  But nobody likes looking at a one-color fractal (in
this case white), even if it does take 30 seconds or less to render.  :)

I assume that in order to solve this particular problem, I need to set up
a table of colors ahead of time.  I can implement that into the existing
code fine, but I have no idea where to start.  :)  I looked at the
tutorial, code, and even the gtk-list archives.  If anybody has any
pointers, it would help me a lot, as I've been stuck on this problem all
day.  Thanks!


                                      - Dave

-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-
  Name:  David Finton                  | "All free software is in Beta.  If
 Email:  dfinton@d.umn.edu             |  there is a free software package
   Web:  http://www.d.umn.edu/~dfinton |  bearing the version number 1.0 or
                                       |  greater, it is obsolete and must
                                       |  be replaced immediately by a
                                       |  newer, better Beta version."
-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-




[Date Prev][Date Next]   [Thread Prev][Thread Next]   [Thread Index] [Date Index] [Author Index]