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.
IndexProgramming Questions & HelpPrograms › recursive subdividion triangles
Page Index Toggle Pages: 1
recursive subdividion triangles? (Read 1543 times)
recursive subdividion triangles?
Feb 1st, 2010, 5:35am
 
hi, i saw this image in flickr http://www.flickr.com/photos/andyclymer/3256728817/sizes/o/ and wanted to try out something similar. i am thinkning about a whole screen wih different sized triangles. using a perlin noise field as source instead of a picture.

So i thought about the right way to do this. i already have a flow field, and i have a matrix of objects that scale corresponding to the noise field. I guess so good so far. but now, instead of the scaling rects i need a trangle that divides itself x times depending on the value of the flow field, right? would that work?

i guess the only thing i cant think of is, how would such a triangle function looks like. a fuction where i pass a value between 0,1(noise) and that divides itself between 0 and 4 times for example. must this be some kind of rekursive function? i have never done anything like that before.

Thank you, Jazz
Re: recursive subdividion triangles?
Reply #1 - Feb 2nd, 2010, 11:23am
 
By "divides itself x times," do you mean the triangle starts to resemble a Sierpinski triangle

I would say, as a method of thinking about it, start by subdividing a line.  The triangle could be easily created later by using the correlating subdivision points of three lines as end points.  I would personally use a Vector or ArrayList of PVector objects or similar, so that you have a flexible quantity of points to work with.

http://en.wikipedia.org/wiki/Sierpinski_triangle
Re: recursive subdividion triangles?
Reply #2 - Feb 2nd, 2010, 2:27pm
 
Hi benhem thanks for your answer. No not like a sierpinsky triangle.
more like something like that
http://img163.imageshack.us/img163/8414/rekursive.jpg

hope it makes sense. it starts with one suare, or in this case 6 squares. from then every square can be subdivided into 2 triangles, now every triangle can be subdivided into 2 triangles again, and so one.
Re: recursive subdividion triangles?
Reply #3 - Feb 3rd, 2010, 3:14pm
 
Ah, ok.  Well -- the basic form of a recursive function is something like this:

void subdivideSquare(float x1, float y1, float y1, float y2){
 [perform the subdivision, and draw the diagonal line as needed, then find the corners of the new square to subdivide]
  subdivideSquare(newx1, newy1, newx2, newy2);
}

This is infinitely recursive, so it needs some kind of break point -- for example, an int that is set to 0 when it starts, and increments for each subdivision.  So:

if (counter is not exceeding bounds) subdivideSquare(newx1, newy1, newx2, newy2);

^ this will break the infinite recursion.
Re: recursive subdividion triangles?
Reply #4 - Feb 3rd, 2010, 5:08pm
 
yes i got that. i used size as variable. and if size is smaler than x, it stops subdividing. this works fine using random. so i say. if random(1)>0.5 divide... and i get patterns like the one in the image.
But i want it to be some kind of animated.
and i thought why not use some kind of perlin noise instead of the random. but thats what makes me such problems.
how do add the perlin noise to get some smooth animations...
Re: recursive subdividion triangles?
Reply #5 - Feb 4th, 2010, 6:37pm
 
if you have a noisefield of floats between 0 and 1, you could try using those values instead of your .5 as the chance for a subdivision.  That would make for fluxuating pockets of increased divisions...

Not sure what you mean about smooth animation, though -- can you describe what you want to see?
Re: recursive subdividion triangles?
Reply #6 - Feb 4th, 2010, 7:05pm
 
Hey benHem thank you for coming back to me.
While searching for other triangleSubdivision images on flickr, i came across this great video http://vimeo.com/6017151
i guess this is exactly what i was planing to do, he was just faster Smiley great execution of  this idea though. But he made this with openframeworks. he is talking about it in his blogpost here : http://www.julapy.com/blog/2009/09/09/triangle-field/ but sadly doesnt tell how he did it. He just mentioned the perlin noise.
I tried to understand the logic behind it, but i just cant.

Cry
Re: recursive subdividion triangles?
Reply #7 - Feb 4th, 2010, 8:33pm
 
If I understand what you want, from looking at that video:

As you move through the noisefield "area", you have a grid of values that are fluxuating.  It sounds like you have already tried hooking that up to the size of cells arranged in a grid, and seen the effects.  Another traditional way to envision it is using brightness or color, as in the Perlin Noise P5 example.

So all you need to do at this point is use your subdivision routine (which currently has a random chance of subdividing to a certain point) and hook its number of subdivisions up to the value of the noisefield at that point....then move through the noisefield as you did with your first sketch (with the size fluxuations).  Instead of changing the size based on the value of the noisefield at that point, though, you'll be changing the number of subdivisions rendered at that cell.
Re: recursive subdividion triangles?
Reply #8 - Feb 5th, 2010, 1:47am
 
i know that this would be the logical way to do it. I already mentioned that in my first post. But instead of having a statig grid, where i can easily get the x and y noise value and scale it to the value. When using subdivision 2 triangles, can become 4, 8, 16 etc and than have different values, i cant get. also because my only attempt to do subdivision that almost worked included translate.
cause i believe when i do it like you mentioned, i will only get my basic squares that are divided n times, in every of its subdivided parts. but it is not decided if a subdivision should be done for every single new part.
I believe the results differ in this way :

http://img215.imageshack.us/img215/8181/subdiv.jpg

what do you think ?

but like i said, i allready have a problem creating a subdivided triangle, that looks like the one in the lower left corner by random. maybe i have problems on two sides and thats another reason why i just cant make it work Sad
Re: recursive subdividion triangles?
Reply #9 - Feb 10th, 2010, 12:38am
 
Hmm.  That picture makes the problem clearer.  It looks like you need to randomize which triangles within a square get subdivided, or just give each subdivision a random chance to "fail" and leave that triangle alone.

One problem you might run into as you use a randomizer to decide which portions get subdivided: random() in Processing will give you different results frame to frame...
Java's Random class has helped me do similar things.  It will let you keep a random value by setting it with setSeed().  So if the seed is the cell's position, the pattern will stay "stable" (randomized portions will be subdivided, but it won't be flickering wildly each frame).

http://java.sun.com/j2se/1.4.2/docs/api/java/util/Random.html
Page Index Toggle Pages: 1