I'm working on the implementation of a cantor set on a 2-dimensional plane. It looks like this. Honestly, There is the obvious algorithm for the cantor set, but it includes a recursive method call. Unfortunately, My environment(Houdini vex) does not support recursive function calls, so I have to design the algorithm without using recursion.
- Is it possible to represent a cantor set without recursion?
- How can I represent the recursive thing in the algorithm without recursion?
int size=ch("size"); //size=27
int can[]={0};
int offset=0;
int col=size;
append(can,size);
int index=0;
int step=1;
int temp[]={};
int firstentry=0;
function void line(int x1; int x2)
{
//this function gets x1(startpoint), x2(endpoint) and color entries in
int step= x2-x1;
if (step==0)
{
//color the single sqaure
setprimgroup(0,"cantor",x1,1,"set");
}
else{
//setprimgroup do the role of coloring the squre.
for(int i=x1; i<=step+x1; i++)
{
setprimgroup(0,"cantor",i,1,"set");
}
}
}
while(size>=1)
{
//first step 0~26
if(index<size)
{
//first line is set.
setprimgroup(0,"cantor",index,1,"set");
index+=1;
//first entry indicates the first entry of the row.
}
///
else{
//split by 1/3
//first entry indicates the first entry of the row.
firstentry+=col;
size=size/3;
step=step*2;
//done only for subdivision ex 1,2,4...
for(int i=0; i<step; i++)
{
offset = size*2;
int start=index;
int end= start+size-1;
line(start,end);
printf("start %g end %g \n",start,end);
index+=offset;
//
}
index=firstentry+col;
//for recursive step, multiply by 2.
}
}
this language resembles C, I don't want you to do coding for me. Please present just an idea for correcting the gap calculation.