2012-06-01 13:24:58 +00:00
|
|
|
module ExtComplex where
|
|
|
|
|
|
|
|
import Graphics.Rendering.OpenGL
|
|
|
|
|
2012-06-25 08:59:41 +00:00
|
|
|
-- This time I use unpacked strict data type
|
|
|
|
-- Far faster when compiled.
|
|
|
|
data ExtComplex = C {-# UNPACK #-} !GLfloat
|
|
|
|
{-# UNPACK #-} !GLfloat
|
|
|
|
{-# UNPACK #-} !GLfloat
|
2012-06-01 13:24:58 +00:00
|
|
|
deriving (Show,Eq)
|
|
|
|
|
|
|
|
instance Num ExtComplex where
|
|
|
|
-- The shape of the 3D mandelbrot
|
|
|
|
-- will depend on this formula
|
2012-06-25 08:59:41 +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-06-01 13:24:58 +00:00
|
|
|
-- The rest is straightforward
|
2012-06-25 08:59:41 +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-06-01 13:24:58 +00:00
|
|
|
|
|
|
|
extcomplex :: GLfloat -> GLfloat -> GLfloat -> ExtComplex
|
2012-06-25 08:59:41 +00:00
|
|
|
extcomplex x y z = C x y z
|
2012-06-01 13:24:58 +00:00
|
|
|
|
|
|
|
real :: ExtComplex -> GLfloat
|
2012-06-25 08:59:41 +00:00
|
|
|
real (C x _ _) = x
|
2012-06-01 13:24:58 +00:00
|
|
|
|
|
|
|
im :: ExtComplex -> GLfloat
|
2012-06-25 08:59:41 +00:00
|
|
|
im (C _ y _) = y
|
2012-06-01 13:24:58 +00:00
|
|
|
|
|
|
|
strange :: ExtComplex -> GLfloat
|
2012-06-25 08:59:41 +00:00
|
|
|
strange (C _ _ z) = z
|
2012-06-01 13:24:58 +00:00
|
|
|
|
|
|
|
magnitude :: ExtComplex -> GLfloat
|
|
|
|
magnitude = real.abs
|