- AVS Troubleshooting
- Fractal Geometry in avs
Archive: Fractal Geometry in avs
Silverbain
29th December 2006 10:36 UTC
Fractal Geometry in avs
Ok is it posable to use fractal geometry in the AVS editor ? and if so how. Iv been trying to do it for a while now and I got it to work once but winamp crashed and I lost the code to make it work and I dont remimber what that code was. :(
If fractal geometry dos not work can complex numbers work in the avs editor ?
if you need help on understanding what I just said one website that can tell you is
http://mathforum.org/library/drmath/view/54523.html
this link will help you under stand what a fractal is.
http://mathforum.org/library/drmath/view/53809.html
this link will help you in under stand complext numbers.
Thank you for any help that you may be able to give.
P.S Sorry for any misspelling its late hear and im tyared.
jheriko
29th December 2006 13:26 UTC
Yes it can be done. All of it.
If you would like to me more specific (which fractal you are trying to render) then I could give you some pointers.
Nic01
29th December 2006 20:01 UTC
I recommend asking around for avs-king's presets.
Silverbain
29th December 2006 20:35 UTC
The main fractal geometry im trying to get to work would be Mandelbrot's set the equation for it is some what simpel but I have no idea how I would go about putting it in to the editor. the equation is. Z = z^2 + c there are some other that I would also like to try but if I could figer out how to put that equation in then the others would fall right in to place.
Thanks for all the help
By the way jheriko your pack 9 was realy good.
Silverbain
Nic01
30th December 2006 04:07 UTC
To my knowledge, the most-used method (for drawing Mandelbrot fractals, at least) is using a line superscope sweep the screen drawing a fractal in the process. You can also skip that and make a superscope grid that covers the entire screen; after that, things are mostly trivial.
That grid would be ridiculously slow, by the way.
Julia fractals can be approximated with a dynamic movement.
Have you had any experience with fractals before this thought about putting it in AVS?
Silverbain
30th December 2006 06:16 UTC
The only other time I had to use fractals was in high school and it was just a small lesson on them. I naver thought about putting the fractals in to AVS entel cupel of days ago. I had a fossel code at one time but my winamp crashed before I was abel to wright the code down. I was useing just the DM with just a plane Simpel render. It cool looking but I have not been abel to reperduce the same affect with any of my other codes that I have tryed. I also have been doing some codes that give a fractal type image with a simpel render but for some reason I can not get a real fractal out of any thing I try. Its some what stressfull knowing you can make one image but not be abel to do it twice.
Thanks for all the help Nic01.
To let you know I realy hate useing the super scope one of the only renders I can naver seam to work the way I want it to.
Nic01
30th December 2006 19:17 UTC
Mind linking us an image of the kind of fractal you have in mind?
Silverbain
1st January 2007 02:13 UTC
One of the fractals I would like to make is like this one.
http://www.fractalism.com/fractals/glow.htm
That one would to me would be one of the best to do becase of the way it looks but then that is just me
Nic01
1st January 2007 21:21 UTC
Emulating that in AVS, you'd get, maybe, .0002 FPS or less.
Fractal pictures like that are a bit of artistic work to get (Hunting down the right spot, coloring, blending multiple pictures...) -- sure, you can render it in AVS (and then blend it, etc), but you're a lot better off with UltraFractal or the like to make those pictures.
Try to look around for fractal AVS presets in DeviantART; you should be able to find a few. Try to find presets, and not pictures, hmmkay ;) (I think there are quite a few Julia fractal presets, a few Mandelbrot fractal presets, and at least one IFS fractal preset)
Remember that AVS is usually meant for animated, high framerate stuff. Fractal arts like those tend to take hours of investment of the artist's time and computer time for rendering.
Silverbain
1st January 2007 22:22 UTC
Ok hears a newbi quetion how do I plot a z-axis or make a X or Y-axis go on for aver. All most aver time I try to use the Z-axis it make my screen go blank or it just pulses with the colors im useing. In that Frac that I had you look at I would not be useing the coloring form it. If any thing I would just like to know how to plot some thing like that In the Pixel of the DM and just use the simpel render for the coloring and beat.
Thanks for the help and sorry for being suck a dumb ass at this stuff.
I have maid a pack of avs before but to me they where not that good.
If you would like to look at the hears the link to down load it.
http://forums.winamp.com/attachment....postid=2004543
Warrior of the Light
1st January 2007 22:22 UTC
http://forums.winamp.com/showthread....hlight=3d+fern
you might find some good examples in that preset
Silverbain
1st January 2007 22:26 UTC
Thanks Warrior I will look at and see what I can learn from it.
jheriko
2nd January 2007 01:32 UTC
You need to iterate the equation z_n+1 = (z_n)^2 + c to test if a point is in the fractal or not. Use a superscope, iterate, count how many iterations it takes for abs(z)>2 then color the point accordingly. Make it a point that traces across the screen and turn clear every frame off, then you can watch it render...
Personally I would forget abotut using DM, the way it gets used to create fractals is not nice or easy to understand, its also limited to special cases.
BTW. If you are having trouble with complex arithmetic you should sit down and think about it harder. :p
Silverbain
2nd January 2007 07:09 UTC
thanks Jheriko.
your right trying to use the DM was a bad Idea. Im starting to get the Superscope to work. Dont know what you mean by abs(Z)>2. I have tryed to look at the expression Help but that is all old from what it says. But any ways thanks for the help I have got at least one point to show up and I can make a line so now that I got that I should be abel to work with it and get superscope to do what I want.
agen thanks to all for the help.
jheriko
2nd January 2007 15:13 UTC
I will explain the implementation of complex arithmetic, since I think that that is where you are having trouble. Firstly we need to be aware that there is no inbuilt support for complex numbers. This is not a big issue though since each complex number can be represented by a pair of real numbers, and AVS does support these.
The basic operations can be done like this in maths and code:
Where w, z are complex numbers a + ib and c + id respectively:
w + z = a + ib + c + id = (a+c) + i(b+d)
w - z = a + ib - c - id = (a-c) + i(b-d)
assuming we have variables a, b, c and d containing our complex number components we can write this in code as:
// addition
result_real = a + c;
result_complex = b + d;
// subtraction
result_real = a - c;
result_complex = b - d;
Multiplication is slightly more painful, we also consider the special case of squaring which is useful for generating the Mandelbrot set.
wz = (a + ib)(c + id) = ac + iad + ibc - bd = (ac - bd) + i(ad + bc)
ww = (a + ib)(a + ib) = (a² - b²) + i(2ab)
// multiplication
result_real = a*c - b*d;
result_complex = a*d + b*c;
// square
result_real = sqr(a) - sqr(b);
result_complex = 2*a*b;
If you want to optimise you can use result_complex = a*b; result_complex = result_complex + result_complex; I think it is marginally faster.
Division is slightly more painful since we need to do some "algebraic juggling" to get the expression into a friendly form. We also need to make use of the idea of
complex conjugate which is usually denoted with a "*" but sometimes with a bar over the top instead.
w* = a - ib
The conjugate has the property that w + w* and ww* are both real numbers:
w + w* = a + ib + a - ib = 2a
ww* = (a + ib)(a - ib) = a² + b²
We use the latter property to simplify w/z :
w/z = (a + ib)/(c + id)
w/z = wz*/zz* = (a + ib)(c - id)/(c + id)(c - id) = (ac + bd + i(bc - ad))/(c² + d²)
This is quite hard to read so here is an image with nice formatting:
http://img413.imageshack.us/img413/8...ivisionfs1.gif
// division
divopt = 1/(sqr(c) + sqr(d));
result_real = (a*c + b*d)*divopt;
result_complex = (b*c - a*d)*divopt;
Remember that divisions are very expensive relative to other arithmetic operations so we do it once and then use multiplication to apply it, rather than doing it twice.
We can also define a function Abs which uses the conjugate:
Abs(w) = √(ww*)
Notice that if there are no complex components this is the same as taking the absolute value of a real number. This function also has a property if we look at the complex plane, it is the distance of a complex number from the origin.
When iterating to generate the Mandelbrot set we are interested in those points which do not diverge. Lets use w_0 = 0, w_n+1 = (w_n)² + z to stick with our current convention for the complex numbers. I have again done the maths as an image since in text it is pretty horrible to make readable:
http://img177.imageshack.us/img177/8...rotrealjv8.gif
Now, if Abs(z) > 2 the w_n are always going to diverge. There is a nice geometric argument for this based on the geometric properties of the complex number product. You can expand out the algebra above to check this, but Abs(z*w) = Abs(w)*Abs(z). At first glance it looks like z > 1 is sufficient for divergence since the repeated squaring will always increase the distance from the origin. However we have to consider the z which is used to generate the w_n as well. Complex addition is geometrically like adding a little arrow to the point where our number is which is the arrow from the origin to the number we are adding with. With Abs(z) > 2 the length of this arrow is greater than 2, but the length of the arrow from squaring is going to be Abs(z)*Abs(z) > 2*Abs(z), i.e. more than twice as long. So no matter how we add the final arrow, we always end up further away from the origin in the second iteration than in first iteration.
The same logic then applies to subsequent iterations.
This is easier to understand with diagrams... but I am too lazy for that :p
Hope this all helps. I think I included everything you should need to know.
EDIT: Just noticed a typo in the complex division, it should be ac
+ bd and bc
- ad, that came through in the .gif as well and I am too lazy to fix that. Just be aware of it. I copy pasted my multiplication without thinking hard enough. :)
Silverbain
2nd January 2007 20:59 UTC
Thanks for the complex arithmitic. What you just put there help me understand it better then the Many of websites I have gone to. But there are still some part that confuse me I will see if I can look them up.
Thanks agen.
Nanakiwurkz
8th January 2007 23:43 UTC
darn it. in relation to Nic01's thing about the IFS preset.
I found one lying around on my backups somewhere. darn it i just wish i knew who made it. me thinks Shock-Value
Silverbain
9th January 2007 00:21 UTC
Well even with all this help that I have got I still cant seem to get how to add a fractal in to AVS with out getting brain fry frist so Im going to go a head and take a break from it and let my brain get back to normal.
But thanks to all thos that helped me out.
Nanakiwurkz
10th January 2007 22:34 UTC
correction
-_-'
sorry
the name was wrong.
I found the preset.
the name is flame fractal.
made by "Skupers" >_<*.
can't believe my own memory betrayed me like that.
anywho i found it lying around on oone of the VB compilations i downloaded. sorry can't remember name.
jheriko
11th January 2007 00:07 UTC
Originally posted by Silverbain
Well even with all this help that I have got I still cant seem to get how to add a fractal in to AVS with out getting brain fry
There is nothing really difficult about rendering a fractal (at least very slowly).
I will write a superscope here and explain it heavily with comments:
Init
n=200; // number of points for superscope
Frame
ih = 2/h; // I am going to draw a line which scans down the
// screen then starts at the top once it reaches the bottom
// this is the height to move down each frame which roughly
// corresponds to a pixel height
y0 = if(above(y0,1),-1,y0+ih); // this moves the line from
// -1 to 1 over and over again by incrementing y0 each
// frame, which we use later to position the line vertically
Point
x=2*i-1; //make x span the screen from -1 to 1 using i which
// runs from 0 to 1 as the superscope goes through each point
y=y0;
// make coordinates of complex number from our position on
// the screen (xc real, yc complex)
xc = 2*x; // real component
yc = 2*y; // complex component
// first iteration is zero so we set up some variables to
// represent the number of iterations and the actual values
it = 0; // iteration count
xi = 0; // real iterate
yi = 0; // complex iterate
/* --- iteration code --- */
// here we use complex multiplication and addition to iterate
xs = xi; // store xi because we are about to modify it and
// we need it to calculate yi
xi = xi*xi - yi*yi + xc; // z = z^2 + c real part
yi = 2*xs*yi + yc; // z = z^2 + c imaginary part
// add to count of iterations until the absolute value
// exceeds 2
it=if(above(sqrt(sqr(xi)+sqr(yi)),2),it,it+1);
/* --- iteration code --- */
/* --- iteration code --- */
// here we use complex multiplication and addition to iterate
xs = xi; // store xi because we are about to modify it and
// we need it to calculate yi
xi = xi*xi - yi*yi + xc; // z = z^2 + c real part
yi = 2*xs*yi + yc; // z = z^2 + c imaginary part
// add to count of iterations until the absolute value
// exceeds 2
it=if(above(sqrt(sqr(xi)+sqr(yi)),2),it,it+1);
/* --- iteration code --- */
/* --- iteration code --- */
// here we use complex multiplication and addition to iterate
xs = xi; // store xi because we are about to modify it and
// we need it to calculate yi
xi = xi*xi - yi*yi + xc; // z = z^2 + c real part
yi = 2*xs*yi + yc; // z = z^2 + c imaginary part
// add to count of iterations until the absolute value
// exceeds 2
it=if(above(sqrt(sqr(xi)+sqr(yi)),2),it,it+1);
/* --- iteration code --- */
// copy paste more as needed or workout how to use loop()
red = it/10; // set color depending on iteration count so we
// can see if it is working or not
green = red; blue = red;
This should help...
edit: sorry if the comments are weird, i edited them so it didnt make the page super wide...
Silverbain
12th January 2007 03:53 UTC
Well thanks for the two avs and the code.
Nanakiwurkz thanks for the help and not trying to be mean but the one you gave me was not realy a fractal if it was I could have put thos types of avs up a log time ago. No the color bar on the side is a nice trick I would have never thought about doing that.
Jheriko thanks for the code I have not had a chance to look all the way through it. And agen not trying to be mean but I have only done one other AVS pack before this one and that was all the work I had aver done with avs.
Agen thanks to the both of you.
jheriko
12th January 2007 13:09 UTC
Originally posted by Silverbain
Jheriko thanks for the code I have not had a chance to look all the way through it. And agen not trying to be mean but I have only done one other AVS pack before this one and that was all the work I had aver done with avs.
Not trying to be mean, but if you can't work it out from the code, the complex arithmetic i explained above, and the mandebrot set generator function then I will be totally out of ideas as to how to provide further help.
The only other thing I could think of is that you might not understand what code does, in which case read PAK-9's AVS programming guide. It is an pretty thorough introduction to programming for AVS.
http://www.deviantart.com/deviation/11200891/
Nanakiwurkz
12th January 2007 23:06 UTC
Correction 2
Originally posted by Silverbain
Well thanks for the two avs and the code.
Nanakiwurkz thanks for the help and not trying to be mean but the one you gave me was not really a fractal
now i'm not going to be mean but this is a correction.
IFS stands for
"Iterrated Fractal System"
which technically renders a dot fractal in 3d.
there is 2 apes that render fractals.
one is called IFS and the other well nvr mind the other its crap to. but IFS is a true fractal system based on the Julia set. the reason it runs very well is because its just dots.
*note* "fractals are more then just pictures that repeat themselves infinte. you have more then one type of fractals.
my fav has to be the Sierpenski Curve fractal and IFS fractals."
sorry if that sounded mean.
DummyDDD
13th January 2007 11:35 UTC
#Silverbrain
Wikipedia has a pretty down to earth guide of how to implement the mandelbrot set: http://en.wikipedia.org/wiki/Mandelb...or_Programmers
Keep in mind that writing loops in avs is a real pain, in order to write a conditional loop performing sevral tasks, you basicly need to write something like:
loop(somenumber, if(below(xx+yy,4),exec3(
assign(something, tosomething)
, assign(something, tosomething)
, assign(something, tosomething)),0));
Which as you can see, is really ugly. Therefore I encourage you to look up Tommylobos AVSTrans, if you are serious about implementing the mandelbrot fractal in AVS (most other iterative fractals are at least as tough to write).