hglmandel/04_Mandelbulb/ExtComplex.hs

38 lines
1.1 KiB
Haskell
Raw Normal View History

2012-05-10 14:50:44 +00:00
module ExtComplex where
import Graphics.Rendering.OpenGL
2012-06-25 09:13:44 +00:00
-- This time I use unpacked strict data type
-- Far faster when compiled.
data ExtComplex = C {-# UNPACK #-} !GLfloat
{-# UNPACK #-} !GLfloat
{-# UNPACK #-} !GLfloat
2012-05-10 14:50:44 +00:00
deriving (Show,Eq)
instance Num ExtComplex where
-- The shape of the 3D mandelbrot
-- will depend on this formula
2012-06-25 09:13:44 +00:00
(C x y z) * (C x' y' z') = C (x*x' - y*y' - z*z')
(x*y' + y*x' + z*z')
(x*z' + z*x' )
2012-05-10 14:50:44 +00:00
-- The rest is straightforward
2012-06-25 09:13:44 +00:00
fromInteger n = C (fromIntegral n) 0 0
(C x y z) + (C x' y' z') = C (x+x') (y+y') (z+z')
abs (C x y z) = C (sqrt (x*x + y*y + z*z)) 0 0
signum (C x y z) = C (signum x) (signum y) (signum z)
2012-05-10 14:50:44 +00:00
extcomplex :: GLfloat -> GLfloat -> GLfloat -> ExtComplex
2012-06-25 09:13:44 +00:00
extcomplex x y z = C x y z
2012-05-10 14:50:44 +00:00
real :: ExtComplex -> GLfloat
2012-06-25 09:13:44 +00:00
real (C x _ _) = x
2012-05-10 14:50:44 +00:00
im :: ExtComplex -> GLfloat
2012-06-25 09:13:44 +00:00
im (C _ y _) = y
2012-05-10 14:50:44 +00:00
strange :: ExtComplex -> GLfloat
2012-06-25 09:13:44 +00:00
strange (C _ _ z) = z
2012-05-10 14:50:44 +00:00
magnitude :: ExtComplex -> GLfloat
magnitude = real.abs