Create Fibonacci sequence attribute using attributewrangle

   1284   2   0
User Avatar
Member
98 posts
Joined: July 2005
Offline
Fibonacci sequence success!!
Using just an attributewrangle sop.
It took me hours of poking and swearing.
If only there were more examples of attributewrangle vex code blocks available
it would have been easier.
I got a "fib" point attribute added to a line geometry node.
Here is confirmation.


int numpoints = npoints(geoself());
printf("numpoints=%d\n",numpoints);
int tn1;
int tn2;
int sum;
tn1 = 0;
tn2 = 1;
for(int i = 0; i < numpoints; ++i)
{
    printf("point=%d fib=%d\n", i, tn1);
    setpointattrib(geoself(),"fib",i, tn1);
    sum = tn1 + tn2;
    tn1 = tn2;
    tn2 = sum;
}

Attachments:
fibonacci_attributewrangle.JPG (109.2 KB)

User Avatar
Member
670 posts
Joined: Sept. 2013
Online
You can also try this, if you like:

https://procegen.konstantinmagnus.de/fibonacci-spiral [procegen.konstantinmagnus.de]
https://procegen.konstantinmagnus.de/ [procegen.konstantinmagnus.de]
User Avatar
Member
98 posts
Joined: July 2005
Offline
Thanks Konstantin,

I will definitely give your vex code snippet a try.
Yours is far more mathematically recondite.
Using golden ratio and trigonometric representation of spirals.
Mine is based on the simple premise of the serial Fibonacci sequence.
Both exemplify the beauty of mathematics when they attempt to replicate natural phenomenon.

int num = chi('points');

float ratio = (sqrt(5) + 1) / 2.0;
float angle = 360 / (ratio * ratio);

for(int i = 2; i < num; i++){
    float radius = sqrt(i);
    float theta = angle * i;
    float pos_x = radius * cos(theta);
    float pos_z = radius * sin(theta);
    vector pos = set(pos_x, 0.0, pos_z);
    int pt_add = addpoint(0, pos);
}
  • Quick Links