home *** CD-ROM | disk | FTP | other *** search
/ ftp.cs.arizona.edu / ftp.cs.arizona.edu.tar / ftp.cs.arizona.edu / icon / historic / v941.tgz / icon.v941src.tar / icon.v941src / ipl / gprogs / lorenz.icn < prev    next >
Text File  |  2000-07-29  |  3KB  |  119 lines

  1. ############################################################################
  2. #
  3. #    File:     lorenz.icn
  4. #
  5. #    Subject:  Program to display Lorenz strange attractor
  6. #
  7. #    Author:   Ralph E. Griswold
  8. #
  9. #    Date:     December 5, 1995
  10. #
  11. ############################################################################
  12. #
  13. #   This file is in the public domain.
  14. #
  15. ############################################################################
  16. #
  17. #  This is a barebones version of a display of the Lorenz strange
  18. #  attractor.  It has deliberately been left simple and free of options so
  19. #  that the basic idea is clear and so that it can be used as the basis of
  20. #  more capable versions.
  21. #
  22. #  This program is based on material given in "Fractal, Programming in
  23. #  Turbo Pascal", Roger T. Stevens, M&T Books, 1990.
  24. #
  25. ############################################################################
  26. #
  27. #  Requires:  Version 9 graphics
  28. #
  29. ############################################################################
  30. #
  31. #  Links:  numbers, wopen
  32. #
  33. ############################################################################
  34.  
  35. link numbers
  36. link wopen
  37.  
  38. procedure main()
  39.    local col, color, colorlist, cx, cy, cz, d0_x, d0_y, d0_z, d1_x
  40.    local d1_y, d1_z, d2_x, d2_y, d2_z, d3_x, d3_y, d3_z, dt, dt2
  41.    local i, old_col, old_row, old_y, row, sx, sy, sz, x, x_angle
  42.    local xt, y, y_angle, yt, z, z_angle, zt
  43.  
  44.    x_angle  :=  rtod(45)
  45.    sx  :=  sin(x_angle)
  46.    cx  :=  cos(x_angle)
  47.    y_angle  :=  rtod(0)
  48.    sy  :=  sin(y_angle)
  49.    cy  :=  cos(y_angle)
  50.    z_angle  :=  rtod(90)
  51.    sz  :=  sin(z_angle)
  52.    cz  :=  cos(z_angle)
  53.  
  54.    WOpen("label=Lorenz", "width=640", "height=350",
  55.       "fg=white", "bg=black") | stop("*** cannot open window")
  56.  
  57.    colorlist := ["red", "blue", "green", "magenta", "cyan", "yellow"]
  58.  
  59.    color := colorlist[1]
  60.  
  61.    x  :=  0.0
  62.    y  :=  1.0
  63.    z  :=  0.0
  64.    old_col  :=  round(y * 9 + 320)
  65.    old_row  :=  round(350 - 6.56 * z)
  66.    dt  :=  0.01
  67.    dt2  :=  dt / 2
  68.    every i := 0 to 8000 do {
  69.       d0_x  :=  10 * (y-x) * dt2
  70.       d0_y  :=  (-x * z + 28 * x - y) * dt2
  71.       d0_z   :=  (x * y - 8 * z / 3) * dt2
  72.       xt  :=  x + d0_x
  73.       yt  :=  y + d0_y
  74.       zt  :=  z + d0_z
  75.       d1_x  :=  (10 * (yt-xt)) * dt2
  76.       d1_y  :=  (-xt * zt + 28 * xt - yt) * dt2
  77.       d1_z   := (xt * yt - 8 * zt / 3) * dt2
  78.       xt  :=  x + d1_x
  79.       yt  :=  y + d1_y
  80.       zt  :=  z + d1_z
  81.       d2_x  :=  (10 * (yt-xt)) * dt
  82.       d2_y  :=  (-xt * zt + 28 * xt - yt) * dt
  83.       d2_z   := (xt * yt - 8 * zt / 3) * dt
  84.       xt  :=  x + d2_x
  85.       yt  :=  y + d2_y
  86.       zt  :=  z + d2_z
  87.       d3_x  :=  (10 * (yt - xt)) * dt2
  88.       d3_y  :=  (-xt * zt + 28 * xt - yt) * dt2
  89.       d3_z  :=  (xt * yt - 8 * zt / 3) * dt2
  90.                      old_y  :=  y
  91.       x  :=  x + (d0_x + d1_x + d1_x + d2_x + d3_x) * 0.333333333
  92.       y  :=  y + (d0_y + d1_y + d1_y + d2_y + d3_y) * 0.333333333
  93.       z  :=  z +  (d0_z + d1_z + d1_z + d2_z + d3_z) * 0.333333333
  94.  
  95.       col  :=  round(y * 9 + 320)
  96.       row  :=  round(350 - 6.56 * z)
  97.  
  98.       if col < 320 then
  99.          if old_col >= 320 then {
  100.             color := get(colorlist)
  101.             put(colorlist, color)
  102.             }
  103.       else if col > 320 then
  104.          if old_col <= 320 then {
  105.             color := get(colorlist)
  106.             put(colorlist, color)
  107.             }
  108.  
  109.       Fg(color)
  110.       DrawLine(old_col, old_row, col, row)
  111.       old_row := row
  112.       old_col := col
  113.  
  114.       }
  115.  
  116.    Event()
  117.  
  118. end
  119.