FB II Compiler







Disk I/O














Made with FB


Increase displaying speed

I have a program that draws say 300 overlaping filled circles (representing a cluster of atoms) in a window. I first use the PICTURE ON and PICTURE OFF to recored the graphics and later display the picture in a refresh event. When displaying the picture, many of the filled circles are drawn over by other filled circles and hence wastes time, since roughly half of the circles are not seen in the final image (they are in the back of the cluster). To speed things up I would like to draw the picture once and then display the final image on the screen without redrawing all the filled circles again with the PICTURE statement. Can anyone point me in the right direction to do this.

Eric Parks

Just a suggestion

I suppose you're using circles, say stored as a point and a radius (there may be other info, color etc but that's irrelevant) I suppose also that you may have a Z coordinate (if your atoms are represented 3D, or spatially, which your mail would seem to imply, else you'd be needing an algorythm to space them out according to 2D conventions of chemical(?) bonds).

Now how to progress...
If you draw from back to front you'd have to check thru all your records to see if one was in front, slow at first but getting faster as you approach the front. Unless you just went for absolute speed and didn't bother checking.
If you draw from front to back then you could eliminate totally hidden atoms but not partial ones, and you'd have to mask the front ones for drawing partial ones behind... not fast.

Have not one but two offscreen GWorlds.
Gworld 1 is color and will eventually be copied to screen
Gworld 2 is B/W and serves as a clip rgn& for GWorld1

And draw you atoms from the front to back.

Before drawing in GWorld 1 use toolbox Quickdraw calls (as tedd has already pointed out on other occasions they're optimised pretty fast) to see if the atom you want to draw would be completely hidden by the clip rgn& in GWorld2 (INTERSECTRGN, off of my head) - if it is, then just move on to next atom. If not then draw in Gworld1 but using the clipRgn& from GWorld2 to stop covering atoms in front. Then also draw, in black, your atom in Gworld2, adding it to the clipRgn&. Proceed through all your atoms.

It may even optimise things (I'm presuming you keep your atoms in a record here) to copy the atoms' record and then sort it _very_quickly_ on the Z coordinate before starting the drawing part.

If the atoms are very bundled then the above may be quicker than drawing them from back to front, regardless of whether they're hidden or not, but if they're very 'spaced out' then just drawing from back to front in an offscreen GWorld is probably quickest.

Of course if you wanted to be completely overkill you could implement _both_ drawing techniques and then quickly look at the spatial distribution to decide which one to use!

have fun!