We are about to switch to a new forum software. Until then we have removed the registration on this forum.
Hello, I have a small error. I think I am in the right direction, but need some guidance. I know this question has been asked, but I can't find an answer that pertains to fractals. I can get it to work with images, but not with recursion. I am trying to get each depth of the fractal to display sequential and delete the previous iteration as it progresses. Hopefully fading as well, but I'm stuck. Thank you in advance.
//VicsekRecursion
int num = 5;
int totalSize = 750;
color c = 33;
color first = 255;
int shape = 0;
int count = 1;
int t = 0;
void setup() {
size(800, 800);
rectMode(CENTER);
noStroke();
}
////////////////////////////////////////////
//here is where the error is
void draw() {
if (shape < 6) {
fill(lerpColor(first, c, count/60.0f));
vicsek(width/2, height/2, totalSize, num, c, first);
}
if (count++ % 60 == 0) {
shape++;
count = 0;
} else if (t < 100) {
shape = 0;
count = 1;
t = 0;
}
}
//here is where the error ends
///////////////////////////////////////////////
void vicsek(float x, float y, float size, int num, color c, color first) {
rect(x + size/3, y - size/3, size/3, size/3);
rect(x - size/3, y - size/3, size/3, size/3);
rect(x - size/3, y + size/3, size/3, size/3);
rect(x + size/3, y + size/3, size/3, size/3);
if (num-- > 1) {
vicsek(x, y, size/3, num, color(32), color(255)); //center
vicsek(x, y-size/3, size/3, num, c, first);
vicsek(x+size/3, y, size/3, num, c, first);
vicsek(x-size/3, y, size/3, num, c, first);
vicsek(x, y+size/3, size/3, num, c, first);
}
}
Answers
well t (whatever that stands for) is always < 100 (it's 0), so count doesn't grow (line 28 does always apply?)
num (the name is pretty bad) is the depth of the recursion; to get different results, change num in line 21.
Also, lerpcolor needs the smaller amount
c
first and then the larger amount which you namedfirst
(and then amt being the 3rd) I guess or was this intentionally?You don't use the colors in the function vicsek.
Precalculate all the lines, store them in a list. Then draw the list a bit at a time.
edit: having run chrisir's code, do that instead 8)
Sequential Fractal Display confusion
Vicsek fractal
From Wikipedia, the free encyclopedia
In mathematics the Vicsek fractal, also known as Vicsek snowflake or box fractal, is a fractal arising from a construction similar to that of the Sierpinski carpet, proposed by Tamás Vicsek. It has applications including as compact antennas, particularly in cellular phones.
https://en.wikipedia.org/wiki/Vicsek_fractal
small 3D spin off (non optimized)
Thank you Chrissir! Very helpful of you and amazing work on the 3D fractal wow :)>- I am working on a version of this which is more object-oriented presently. Thanks for posting the link as well. @Koogs you are right as your approach would be the object oriented one.
The 3D version kick serious a#@.
Nevertheless, I am a bit confused still on this section of code:
Why is 'count++' variable outside of the brackets and why is 'shape++'' inside the brackets? Thank you again, great work and very helpful. Best, Erik
Hey The count variable is within the draw function. The draw function is basically a loop that could be running up to 60fps (frame per second). So what that code does is to execute the change of shape every 60 frames, or every 60 counts. As you see, the count is reset to zero. In fact, because the modulus operator is being used (%), there is no need to reset the counter to zero. This last detail is more of a technicality.
So in other words, if we assume the computer is running 60 fps, then every second to increase the shape. If the shape exceed the value of 6 then it resets it back to 1. This ensures the shape only has a value of 1 to 6, inclusive.
I hope this helps,
Kf
Thanks so much kfrajer. Your explanation is very helpful and articulate. Much appreciated!
working on the transition a bit.
Also has a class / objects / OOP now
Thank you @Chrisir. That is an elegant code, but I'm still trying to work up to it. I have gotten this far: Everything is working right, except for the fact that my new generation is erasing the previous one. I am trying to modify this code so that the previous generation remains on the screen.
Thank you again for the help. =Erik
Maybe change
circle = next;
tocircle.addAll(next);
. :-/http://docs.Oracle.com/javase/8/docs/api/java/util/List.html#addAll-java.util.Collection-
Perfect. That does the trick! Gracias.
My version has fading
The fading is epic. I am attempting to implement the fading into an object-oriented version now.