Wednesday, February 17, 2016

ikeda map

Continuing the theme of strange attractors, here's the well-known one embedded in the Ikeda map. The thumbnail at right shows the central 'vortex' of the attractor, and links to a larger viewport.

In these images, I've plotted the real and imaginary components along the x and y axes respectively. But the more popular way to visualize this attractor adds an extra parameter to the system and is expressed in trigonometric functions. Such adaptation of the code below yields these results.

{-# LANGUAGE NoMonomorphismRestriction #-}
 
import Data.Complex
import Graphics.UI.SDL as SDL
  
(xRes, yRes) = (1366, 768)
[a, b, k, p] = [0.85, 0.9, 0.4, 7.7]
 
main = withInit [InitVideo] $ do
  w <- setVideoMode xRes yRes 32 [NoFrame]
  s <- createRGBSurface [] 1 1 32 0 0 0 0
  fillRect s Nothing $ Pixel 0xFFFFFF
  enableEvent SDLMouseMotion False
  setCaption "Ikeda" "Ikeda"
  render w s $ ikeda $ 0 :+ 0
  SDL.flip w
  run w
 
run w = do
  e <- pollEvent
  delay 64
  case e of
   KeyUp (Keysym SDLK_ESCAPE _ _) -> return ()
   _                              -> run w
 
render w s = mapM_ draw
 where
  rect (x,y) = Just $ Rect (round x) (round y) 1 1
  g (x,y)    = (x + xRes / 24, y + yRes / 2.25)
  draw z     = blitSurface s Nothing w $ rect $ g p
   where
    p = (1050 * realPart z, 1050 * imagPart z)
 
ikeda = take 1500000 . filter g . iterate f
 where
  f z      = a + b * z * exp(i * (k-p) * (1 + abs z^2))
  i        = 0 :+ 1
  g (r:+i) = -35 < r && r < 35 && -18 < i && i < 18

No comments:

Post a Comment