From 1c67f83acb538440856f600e7108b363c730cf80 Mon Sep 17 00:00:00 2001 From: dooglus Date: Sat, 8 Sep 2007 23:35:18 +0000 Subject: [PATCH] Spread the sprouts out evenly along each bline. Previously they appeared at both ends of each bline segment, resulting in double sprouts at each internal blinepoint. Added a few comments. Tidied up a little. Oh, and apply the 'random_factor' parameter when calculating 'stunt_growth', too. Setting random_factor to 0 will unstunt all growth. git-svn-id: http://svn.voria.com/code@640 1f10aa63-cdf2-0310-b900-c93c546f37ac --- .../trunk/src/modules/mod_particle/plant.cpp | 39 +++++++++------------- 1 file changed, 16 insertions(+), 23 deletions(-) diff --git a/synfig-core/trunk/src/modules/mod_particle/plant.cpp b/synfig-core/trunk/src/modules/mod_particle/plant.cpp index 1e7a948..7efd215 100644 --- a/synfig-core/trunk/src/modules/mod_particle/plant.cpp +++ b/synfig-core/trunk/src/modules/mod_particle/plant.cpp @@ -198,11 +198,10 @@ Plant::sync()const next=bline.begin(); - if(bline_loop) - iter=--bline.end(); - else - iter=next++; + if(bline_loop) iter=--bline.end(); // iter is the last bline in the list; next is the first bline in the list + else iter=next++; // iter is the first bline in the list; next is the second bline in the list + // loop through the bline; seg counts the blines as we do so; stop before iter is the last bline in the list for(;next!=bline.end();iter=next++,seg++) { curve.p1()=iter->get_vertex(); @@ -213,35 +212,29 @@ Plant::sync()const etl::derivative > deriv(curve); Real f; - int i(0), b(round_to_int((1.0/step)/(float)sprouts-1)); - if(b<=0)b=1; + + int i=0, branch_count = 0, steps = round_to_int(1.0/step); for(f=0.0;f<1.0;f+=step,i++) { Point point(curve(f)); - particle_list.push_back(Particle( - point, - gradient(0) - )); - + particle_list.push_back(Particle(point, gradient(0))); bounding_rect.expand(point); - Real stunt_growth(random(Random::SMOOTH_COSINE,i,f+seg,0.0f,0.0f)/2.0+0.5); + Real stunt_growth(random_factor * random(Random::SMOOTH_COSINE,i,f+seg,0.0f,0.0f)/2.0+0.5); stunt_growth*=stunt_growth; Vector branch_velocity(deriv(f).norm()*velocity); - branch_velocity[0]+=random_factor*random(Random::SMOOTH_COSINE,1,f*splits,0.0f,0.0f); - branch_velocity[1]+=random_factor*random(Random::SMOOTH_COSINE,2,f*splits,0.0f,0.0f); - - if(i%b==0) - branch( - i, - 0, - 0, // time - stunt_growth, // stunt growth - point,branch_velocity - ); + branch_velocity[0] += random_factor * random(Random::SMOOTH_COSINE, 1, f*splits, 0.0f, 0.0f); + branch_velocity[1] += random_factor * random(Random::SMOOTH_COSINE, 2, f*splits, 0.0f, 0.0f); + + if((((i+1)*sprouts + steps/2) / steps) > branch_count) { + branch_count++; + branch(i, 0, 0, // time + stunt_growth, // stunt growth + point, branch_velocity); + } } } -- 2.7.4