Wednesday, 29 November 2006

Graphics with .NET

I've spent the past couple of weeks developing graphical demos using F# and .NET. My previous blogs mention the ray tracer and spinning teapot Direct X demo.

Under .NET, developers are spoiled for choice when it comes to graphics. You can use WinForms and bitmaps, as I did for the ray tracer. There's managed DirectX, which I used for the teapot. More recently, Microsoft have create XNA and WPF.

However, none of these systems are as easy to use from languages like C# and F# as competing systems, such as OCaml and OpenGL. In my book "OCaml for Scientists" I introduce OpenGL visualisation with a 6-line program that reliably displays a blank window. That takes over 80 lines of code with managed Direct X because you must limit the minimum size of the Direct X widget or it will crash and you must handle device losses and resets yourself. To make matters harder, it is almost impossible to find accurate information on how this is accomplished.

I appreciate that this is boiler-plate code, you get it working once and then cut and paste it into every one of your programs but it is too much to expect users to write those 80 lines of code everytime they want to see a triangle.

In Mathematica, for example, you can write a single line of code to get a 3D surface plot that you can then export as a PostScript or PDF file:

Plot3D[Sin[x^2+y^2], {x, -3, 3}, {y, -3, 3}]

I want to be able to do this from F#, 100x faster and with .NET interoperability.

So I set about writing a library to make it as easy as possible to do real-time, interactive, 2D and 3D visualisation from F#. The foundation comes from the code base of our presentation software Presenta:

http://www.ffconsultancy.com/products/presenta/

In addition to compiling and running programs to create visualisations, you can now slice and dice your data in the F# interactive mode and have it throw up windows visualising your data as you go. You can even control the contents of the windows after they've been created!

Needless to say, I'll be commercialising this as soon as its done. One thing is ringing true though - F# is the next stage in the evolution of programming languages!

Cheers,
Jon.

Thursday, 23 November 2006

Wednesday, 22 November 2006

Quotations

Tomas Petricek posted an interesting blog entry on the use of quotations in F#:

http://cs.hubfs.net/blogs/tomasp/archive/2006/07/07/413.aspx

To paraphrase, you can quote some F# code:

> <@1+2*3@>


and get the abstract syntax tree representing that code:

val it : ast = Add(Int 1, Mul(Int 2, Int 3))

Monday, 20 November 2006

Ray tracer

Just uploaded a new F# example program with executable and complete source code:

http://www.ffconsultancy.com/dotnet/fsharp/raytracer/index.html

Sunday, 19 November 2006

Sudoku solver in F#

I've uploaded the first of many example F# programs: a Sudoku solver complete with GUI.

http://www.ffconsultancy.com/dotnet/fsharp/sudoku/

Saturday, 18 November 2006

Google Trends shows F# taking off

I've been doing a lot of Google Trend searches to improve the direction of my company recently. The results certainly seem to back my decision to go into the F# market:

http://www.google.com/trends?q=f%23&ctab=0&geo=all&date=all

F# has been visible for a few years but has really started to increase during 2006.

Cheers,
Jon.

Friday, 17 November 2006

Welcome to my new blog about the F# programming language for .NET. I'll be posting any interesting tidbits that I find on this blog.

Check out our F# web pages here:

http://www.ffconsultancy.com/dotnet/fsharp/index.html