We closed this forum 18 June 2010. It has served us well since 2005 as the ALPHA forum did before it from 2002 to 2005. New discussions are ongoing at the new URL http://forum.processing.org. You'll need to sign up and get a new user account. We're sorry about that inconvenience, but we think it's better in the long run. The content on this forum will remain online.
IndexDiscussionExhibition › hairball
Page Index Toggle Pages: 1
hairball (Read 2373 times)
hairball
Dec 11th, 2006, 6:21am
 
Hey all,

I've played with processing for a while, but don't usually upload my sketches. I quite like this one however, so here it is:

http://www.wxs.ca/applets/hairball/

Note that they're a little different every time, so click a few times until you get a nice one.

Also, if anyone has any tips on how to speed up my (terribly documented) code, it would be appreciated, as at the moment very dense hairballs slow execution way down. (If this behaviour annoys you, press 'c' to clear and start again).
Re: hairball
Reply #1 - Dec 11th, 2006, 5:57pm
 
Nice.

wxs wrote on Dec 11th, 2006, 6:21am:
tips on how to speed up


Just a couple simple ideas, I don't see anything major wrong.  First, the stuff you probably DON'T want to do, but would improve performance:  reduce size, turn off smoothing.

See if you can reduce calls to smooth, colorMode, ellipseMode, noStroke, etc.  If you never change them, then you call them once in setup() instead of every frame in draw().

You could potentially store your angles as int instead of float, where your int angle is a direct lookup into your trig tables.  You'd then avoid a LOT of divisions of the form "floor(angle2/LUTstep)".  So your angles would run from 0..628 (using current lut resolution) instead of 0..TWO_PI.

Try using an ArrayList instead of a Vector.  Vector's are synchronized so can be slower, but testing would be in order to confirm for any particular usage.
Re: hairball
Reply #2 - Dec 12th, 2006, 7:17pm
 
Thanks for the tips, I implemented a bunch of 'em (notably the ArrayList and the integer angles).
I tried to do a side-by-side comparison of the two with one on the old code and one on the new (and the randomness removed so it always made the densest hairballs) but got too bored waiting for the old code to finish (the new code took an average of 4 seconds per hairball).
It's been uploaded now if you want to play around (note though, it still will slow down a bit on super-dense hairballs).
Re: hairball
Reply #3 - Feb 25th, 2007, 10:56pm
 
the densest hairball i generated out of about 20 hairballs only took roughly 6 seconds to draw.. not bad, really.

as for suggestions.. all i can think of w/o browsing the code is this: why not have the hairballs continue when they venture beyond the applet window? any hairball i started that would intersect with the window boundary would simply stop drawing when it hit the window (rather than continuing when it would have returned to the viewable area).

Edited:

as far as i can tell, processing will allow you to "draw" beyond the outlet window, it just won't show up. or, you could use an if statement to check to see if the point about to be drawn is on screen.. if not, don't print it, but continue your hairball loop. just a suggestion..
Re: hairball
Reply #4 - Feb 26th, 2007, 5:49pm
 
haliphax wrote on Feb 25th, 2007, 10:56pm:
as for suggestions.. all i can think of w/o browsing the code is this: why not have the hairballs continue when they venture beyond the applet window any hairball i started that would intersect with the window boundary would simply stop drawing when it hit the window (rather than continuing when it would have returned to the viewable area).

I actually originally had it keep drawing outside of the viewing window. The reason I changed was that from time to time it would start generating really dense hairballs that were off-screen. It was irritating (to me) to have the program slowing down despite the fact that you couldn't see anything. I guess I could add an option to switch it on and off though.
Re: hairball
Reply #5 - Feb 26th, 2007, 7:52pm
 
wxs wrote on Feb 26th, 2007, 5:49pm:
I actually originally had it keep drawing outside of the viewing window.


Hope you won't mind me posting this:
http://www.davebollinger.com/works/p5/hairball/
(credit given to original, of course!)

When I was playing with your sketch I added something similar: a small "margin" around the edges before death set in to help cope with the rough edges, (i do the same thing with my "cubicles" sketch), but without letting them wander around forever invisible offscreen.

Feel free to borrow back the idea, it's your sketch after all! Smiley
Re: hairball
Reply #6 - Feb 26th, 2007, 11:51pm
 
davbol wrote on Feb 26th, 2007, 7:52pm:
Hope you won't mind me posting this:
http://www.davebollinger.com/works/p5/hairball/
(credit given to original, of course!)

No worries, if I minded I wouldn't have included the source. I like the bezel effect. I didn't notice the margin thing you mentioned, but I guess that's just because I kept hitting the walls at too oblique an angle.
Page Index Toggle Pages: 1