hglmandel/article/00_Introduction.lhs

54 lines
2.5 KiB
Text
Raw Normal View History

2012-05-03 13:40:35 +00:00
## Introduction
2012-06-15 10:18:16 +00:00
In my
[preceding article](/Scratch/en/blog/Haskell-the-Hard-Way/) I introduced Haskell.
2012-05-10 14:51:24 +00:00
This article goes further.
2012-06-15 10:18:16 +00:00
It will show how to use functional programming with interactive programs.
But more than that, it will show how to organize your code in a functional way.
2012-06-10 22:34:44 +00:00
This article is more about functional paradigm than functional language.
The code organization can be used in most imperative language.
2012-06-15 10:18:16 +00:00
As Haskell is designed for functional paradigm, it is easier to use in this context.
In reality, the firsts sections will use an imperative paradigm.
2012-06-10 22:34:44 +00:00
As you can use functional paradigm in imperative language,
you can also use imperative paradigm in functional languages.
2012-06-05 13:38:57 +00:00
This article is about creating an useful and clean program.
2012-06-10 22:34:44 +00:00
It can interact with the user in real time.
It uses OpenGL, a library with imperative programming foundations.
Despite this fact,
most of the final code will remain in the pure part (no `IO`).
2012-06-05 13:38:57 +00:00
2012-06-10 22:34:44 +00:00
I believe the main audience for this article are:
2012-05-10 14:51:24 +00:00
2012-06-10 22:34:44 +00:00
- Haskell programmer looking for an OpengGL tutorial.
- People interested in program organization (programming language agnostic).
- Fractal lovers and in particular 3D fractal.
- People interested in user interaction in a functional paradigm.
2012-05-10 14:51:24 +00:00
2012-06-15 10:18:16 +00:00
I had in mind for some time now to make a Mandelbrot set explorer.
I had already written a [command line Mandelbrot set generator in Haskell](http://github.com/yogsototh/mandelbrot.git).
This utility is highly parallel; it uses the `repa` package[^001].
2012-06-10 22:34:44 +00:00
2012-06-15 10:18:16 +00:00
[^001]: Unfortunately, I couldn't make this program to work on my Mac. More precisely, I couldn't make the [DevIL](http://openil.sourceforge.net/) library work on Mac to output the image. Yes I have done a `brew install libdevil`. But even a minimal program who simply write some `jpg` didn't worked. I tried both with `Haskell` and `C`.
2012-05-10 14:51:24 +00:00
This time, we will not parallelize the computation.
Instead, we will display the Mandelbrot set extended in 3D using OpenGL and Haskell.
2012-06-10 22:34:44 +00:00
You will be able to move it using your keyboard.
This object is a Mandelbrot set in the plan (z=0),
and something nice to see in 3D.
2012-05-03 13:40:35 +00:00
2012-06-15 10:18:16 +00:00
Here are some screenshots of the result:
2012-05-03 13:40:35 +00:00
2012-06-14 14:30:46 +00:00
blogfigure("GoldenMandelbulb.png","The entire Mandelbulb")
blogfigure("3DMandelbulbDetail.png","A Mandelbulb detail")
blogfigure("3DMandelbulbDetail2.png","Another detail of the Mandelbulb")
2012-05-03 13:40:35 +00:00
2012-06-15 10:18:16 +00:00
And you can see the intermediate steps to reach this goal:
2012-05-03 13:40:35 +00:00
2012-06-10 22:34:44 +00:00
blogimage("HGL_Plan.png","The parts of the article")
From the 2nd section to the 4th it will be _dirtier_ and _dirtier_.
2012-06-15 10:18:16 +00:00
We start cleaning the code at the 5th section.