Chaos Fractal - 4D Julia Set Raytracer

Community Forums/Showcase/Chaos Fractal - 4D Julia Set Raytracer

Noobody(Posted 2009) [#1]
After two weeks of development, I can proudly release the first version of Chaos Fractal.

Chaos Fractal is an open source program that can render and manipulate 4D Julia sets.
The rendered images reveal bizarre and fascinating shapes and are good for wallpapers (you could also print them out and put them on your wall, if you like to :) ).

Of course you don't have to be a maths freak to run the program - the interface is simple to use; more detailed information is found in the ReadMe.txt (simply press F1 in the program).

Screenshot of the program:


A few example renders:



Download (Win): Link
Source: Link (BMax/wxMax required)

Due to unexplicable problems the program doesn't run on Mac (haven't tried it out on Linux yet) - images aren't displayed and the project list doesn't look right. Source is free, if anyone has an idea, please tell me :) The problem is presumably in TScrolledImageWindow::OnPaint.


Brucey(Posted 2009) [#2]
Hi. This looks amazing! I especially like the blue one.

You have a bug, in MarkProject(), which is causing the Mac version to crash.
this line :
For Local I:Int = 0 To GetItemCount()

should be
For Local I:Int = 0 To GetItemCount() -1

.. or ..

For Local I:Int = 0 Until GetItemCount()

The problem is that you are trying to set state on an item which doesn't exist.

Not really sure if I should be doing range-checking for you.... Some functions in BlitzMax didn't used to, but in more recent versions I note that Mark did add some checks for debug builds, which throw an assertion.


Noobody(Posted 2009) [#3]
Wow, thanks a lot for pointing this out!

I didn't notice that one, which is strange, since I normally run the program in debug mode.

I updated the code in the archive and hope this was the only error in the code (since I don't have a Mac, I can't really check).

I especially like the blue one.

One of my favourites too.


Brucey(Posted 2009) [#4]
Another minor issue :-)

In DispatchDeselection(), you kick off a timer which raises a call to DispatchTimer().
Event.GetEventObject() will not hold a wxTimer instance. It holds the value of ListEvent.Parent - which I think is your listctrl.
Therefore, in DispatchTimer(), the Timer variable is Null, and the call to Timer.Stop() throws an exception. Since you set "OneShot" to True, you don't need to Stop() it anyway.
However, you are creating timers and never freeing them - which could be a problem after a while.

Not sure of the logic behind the timer... I'm guessing you need to wait for a little while before you can "SetCurrentProject" again?
You may find it better to do this on an idle event instead? (idle events occur when all other events have been processed. In this way you'd know that everything else was done, and you could safely make the call).

Just some thoughts :-)


Noobody(Posted 2009) [#5]
As the deselection event gets called before the selection event, I had to make the DispatchDeselection() function get called again after a short while to check whether the user has selected another entry or just clicked in empy space.

I thought, stopping a timer would equal freeing it - which is wrong, as I understand now.
I'm trying out the idle event, which seems to be what I actually need.

It is strange that the debugger never threw an exception, even as I was attempting to call a method of a Null object.

Thanks a lot for your help!
I'm kinda new to BlitzMax, especially wxMax, so the whole source file is a bit... messy :)


Brucey(Posted 2009) [#6]
As the deselection event gets called before the selection event

Yes, I've noticed this too. I'll have a look into it and see if we can't come up with a better solution. I thought maybe it was just my Mac... but you appear to have the same problem on Windows.
I'll get back to you ;-)


Brucey(Posted 2009) [#7]
How's about this :
	Function DispatchDeselection( Event:wxEvent )
		Local ListEvent:wxListEvent = wxListEvent( Event )

		Local ListControl:TProjectListControl = TProjectListControl( Event.Parent )
		If ListControl.GetSelectedItemCount() = 0 Then

			Local MainWindow:TMainWindow = TMainWindow( wxWindow( ListEvent.Parent ).GetParent().GetParent() )

			MainWindow.ProjectListControl.NewSelection = False
			TMainWindow( ListControl.GetParent().GetParent() ).SetCurrentProject( Null )
		End If
		
	End Function

On deselection, it checks if any rows are currently selected, and if not, will only then clear the project. This seems to work fine on Mac.

And you may also want to set the flag wxLC_SINGLE_SEL on the listctrl for single-row selection only - unless you want multi-row selection enabled? (the default is multi)

HTH.


Noobody(Posted 2009) [#8]
Wow, I never thought about using it this way - thanks a lot!

Actually, I was looking for a single-row selection flag, but it would seem that it was late at night and I didn't read the documentation that well :)


Brucey(Posted 2009) [#9]
And my last word here....

You can comment out your wxID_ABOUT const on line 37. There is already one defined by wxMax - on Mac, wxID_ABOUT is a special ID, which will cause the menu item to be displayed in the Application Menu instead of the Help menu, where it is expected. By overriding the value, it appears in the Help menu, which is wrong. Simply commenting out the line solves the problem ;-)

Anyway, I've taken up far too much of your thread....

I'm off to try some renders :-)


Noobody(Posted 2009) [#10]
Thanks a lot for your help!
I read your last post just as I finished uploading the source archive with all the files updated - a typical d'oh moment :)

The source should now be OK, thanks to you.

By the way, fractal 7 (which is also one of my favourites) looks much better in higher resolution, which is why I rendered it 4 times bigger at 4096x3072.
Image found here (2 MB).


Who was John Galt?(Posted 2009) [#11]
Looking sweet. I will have a play with this later.


grindalf(Posted 2009) [#12]
Ive tried it out a little, Its well cool although I know nothing about fractals, but still very nice :D


Noobody(Posted 2009) [#13]
I'm currently experimenting with shaders in OpenGL (using GLSL), so as a first shader project I tried to make a Mandelbrot shader (the Mandelbrot set is similar to the Julia set).

It runs surprisingly fast - just as a comparison, similar code in Blitz3D runs at least 5000 times slower than the shader (Blitz3D: 10 seconds for a render, shader: 20ms). The only problem is that float is the only floating point data type on the GPU, which means that due to the limited precision the renderings look pixelated if you zoom in too much.

Disregarding that, the images look quite neat and the program runs fast enough so the user can zoom using the mouse in almost real-time.

Screenshot:


Download (Win binary + BMax source): Link
Zoom in/out using the left/right mouse button.
You will need a graphic card supporting shader model 3.0 to run this.


I'm planning to do the raytracing of the 4D julia sets on the GPU as well (which is why im posting this here :) ), which would decrease the rendering time greatly.
I guess I have to learn quite a bit more of shader programming, but I hope I will get this to run in the next few weeks.


Gabriel(Posted 2009) [#14]
I think that's only a limitation of GLSL, not the shader model. HLSL lets you use 64 bit floating point values, so I would assume that CG can do the same, since CG and HLSL are virtually identical. Could you use CG instead of GLSL?


Who was John Galt?(Posted 2009) [#15]
Hey, cool!

You got me interested in fractals again. You may be interested in this:

http://en.wikipedia.org/wiki/Fractal_flame

There's an open source project on the mac called oxidizer that produces animations with these fractal flames and they look pretty neat.

http://www.youtube.com/watch?v=D4bbJmPB_bs


Ruz(Posted 2009) [#16]
wow looks nice. i always liked fractal patterns. very trippy he hee


Noobody(Posted 2009) [#17]
You may be interested in this:

http://en.wikipedia.org/wiki/Fractal_flame

Thank you for the link. I've experimented with those a few months ago and wrote a program in Blitz3D to render them.
It's awfully slow, but the rendered fractals look pretty nice. This one is my favourite (and also the background image of my desktop :) ).


Floyd(Posted 2009) [#18]
Pretty cool.

I've wanted to experiment with this but it really needs double precision and I can't buy a high-end graphics card just to play with fractals.


Noobody(Posted 2009) [#19]
I think that's only a limitation of GLSL, not the shader model. HLSL lets you use 64 bit floating point values, so I would assume that CG can do the same, since CG and HLSL are virtually identical. Could you use CG instead of GLSL?

According to Wikipedia and MSDN neither HLSL nor Cg support 64bit floating point data types at the moment (HLSL will support double in Direct3D 11, which is currently under development).
Besides that, I would probably be too lazy to learn yet another shading language :) But thanks for the suggestion.


ubergeek(Posted 2009) [#20]
Thank you for the link. I've experimented with those a few months ago and wrote a program in Blitz3D to render them.

I've become very interested in fractal algorithms, but have been struggling to implement them on my own. Could you post the code you did in B3D?

Very nice little program by the way, it's really cool!


Noobody(Posted 2009) [#21]
I've uploaded the source here.

The code is'nt realky good documented (since comments disturb my programming :) ), but you can always PM me if you can't understand something.

I really like fractal flames, they produce neat images (I especially like this and this one).


ubergeek(Posted 2009) [#22]
Thanks so much!!!

That's exactly what I needed to help get my head around fractal code. (and my code has even fewer comments so don't worry ;) yours is clearly written and easy to follow though!)

Thanks!


Jesse(Posted 2009) [#23]
This is really nice,thank you for posting the source.
I thought of using the fractal image on a little hobby thing I am working on. So I converted the code to Bmax OO(with a few modifications). here is the code if anybody is interested:



Tachyon(Posted 2009) [#24]
Jesse- your code just leaves me with a black screen.


Jesse(Posted 2009) [#25]
wait about 30 seconds processing before the image is displayed?
change this line "30000":
If MilliSecs() - RenderTimer > 30000 Then

to a smaller number for a faster less detailed image so the more you wait the better it gets.
another problem might be that its a vista compatibility problem I read posts before where the user was having problems displaying pixmaps in Vista.
if that is the case, you can always change this line:
	DrawPixmap pixmap,0,0

to this:
        local image:Timage = LoadImage(pixmap)
        DrawImage image,0,0



Noobody(Posted 2009) [#26]
I have the same problem on Vista too, but setting the Max2D driver to OpenGL worked for me just fine.