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 › Snowflake generator
Page Index Toggle Pages: 1
Snowflake generator (Read 1755 times)
Snowflake generator
Dec 7th, 2009, 1:48am
 
Hi Guys,

I've made a little snowflake generator as a Christmas card project.

http://www.art-tek-ltd.co.uk/snowflake/

It is based on Shiffmans recursive branching tree demo and uses PhiLHo's image save class.

You can see the source at the bottom of the page

I've used a
Quote:
  if (focused) {}


inside the draw loop so that when users have focus on another window it doesn't take 20% of their CPU redrawing. If this a bad thing to do?


Is starting a new thread for each image save a good idea?
Quote:
void startsave(){
  if (!saving){
    ImageSaver saver = new ImageSaver();
    saver.start();
  }
  else{
    println("wait");
    pleasewait = true;
    pleasewaitcount = 0;
  }
}




I have tried to quit the new thread with
Quote:
    running = false;  // Setting running to false ends the loop in run()
    interrupt(); // in case the thread is waiting. . .



But I have noticed that after saving a few times the memory the applet takes grows by 2-3mb each time and does not ever drop back down.
Re: Snowflake generator
Reply #1 - Dec 7th, 2009, 4:12am
 
am all for not chewing up the processor when the image isn't moving. but wouldn't it be easier and more efficient to only redraw if the mouse is moving inside the window?

try setting your image saver to null when you've finished with it to allow the garbage collector to free up the memory.

also, snowflakes have 6-fold symmetry. not 5, not 7, not 12. 6. personal bugbear 8)
Re: Snowflake generator
Reply #2 - Dec 7th, 2009, 5:07am
 
Thanks for your comments Koogy

Less redraw-
So would that work by putting the draw animation in a mouseMoved() function or by enclosing the draw in something that checks last mousex/mousey sort of thing. Is that the right logic?

Garbage collector -
using
Quote:
    ImageSaver saver = null;
    System.gc();


Seemed to work perfectly thank you Smiley


And "snowflakes" with other than 6 sides are just because they look pretty and it is nearly Christmas!

Edit: Plus you can get 12 and 3 sided flakes!
http://www.newscientist.com/gallery/dn16170-snowflakes/10
Re: Snowflake generator
Reply #3 - Dec 7th, 2009, 6:05am
 
i can't remember how i did mine. i think i made it noLoop and then just had a mouseMoved method with a redraw() in it.

yes:

void mouseMoved() {
 // restrict this to 4 times a second
 float now = millis();
 if (now > then + 250) {
   then = now;
   redraw();
 } else {
   //println("Too Soon");
 }
}

oh, that has a restriction in it so that it doesn't draw *every* time the mouse as moved because my draw() was actually quite slow.

"Such snowflakes are quite rare." 8)

i wrote a little something to generate snowflake wrapping paper for last christmas. chose deliberately simple flakes. turned out nice.

...

http://www.flickr.com/photos/31962137@N00/3112302023/
Re: Snowflake generator
Reply #4 - Dec 9th, 2009, 7:22am
 
Thanks very much - it is much smoother now, just added redraw to mouseMoved and keyPressed

I love your snowflake wallpaper, both how it looks and the code for how it works!
Page Index Toggle Pages: 1