############################################################################
#
#	File:     twists.icn
#
#	Subject:  Procedures to produce traces of "twists"
#
#	Author:   Ralph E. Griswold
#
#	Date:     May 2, 2001
#
############################################################################
#
#   This file is in the public domain.
#
############################################################################
#
#  These procedures produce traces of twisting orbits.  See
#
#	Geometric and Artistic Graphics; Design Generation with
#	Microcomputers, Jean-Paul Delahaye, Macmillan, 1987, pp. 73-80.
#
#  The arguments specify the starting positions, the extent of the
#  drawing, the number of segments, and various parameters that determine
#  the orbits.
#
############################################################################
#
#  Links:  gobject
#
############################################################################

link gobject

procedure twist1(x, y, extent, n, t1, t2, j1, j2, k1, k2, rscale1, rscale2,
sfact, sscale, soff, yfact)
   local radius1, radius2, angle, s, s1, s2, c1, c2, i
   local jangle1, jangle2, kangle1, kangle2, sangle
   
   radius1 := rscale1 * extent				# scaling
   radius2 := rscale2 * extent

   jangle1 := 2 * &pi / n * j1 * t1
   jangle2 := 2 * &pi / n * j2 * t1
   kangle1 := 2 * &pi / n * k1 * t2
   kangle2 := 2 * &pi / n * k2 * t2
   sangle := sfact * &pi / n

   every i := 0 to n do {
      s := sscale * cos(sangle * i) + soff
      c1 := cos(jangle1 * i)
      s1 := sin(jangle2 * i)
      c2 := s * cos(kangle1 * i)
      s2 := s * sin(kangle2 * i)
      suspend Point(x + radius1 * c1 + radius2 * (c1 * c2 - s1 * s2),
         y + yfact * (radius1 * s1 + radius2 * (s1 * c2 + c1 * s2)))
      }

end

procedure twist2(x, y, extent, n, t1, t2, j1, j2, k1, k2, rscale1, rscale2,
sfact, yfact)
   local radius1, radius2, angle, s1, s2, c1, c2, i
   local jangle1, jangle2, kangle1, kangle2, sangle

   radius1 := rscale1 * extent				# scaling
   radius2 := rscale2 * extent

   jangle1 := 2 * &pi / n * j1 * t1
   jangle2 := 2 * &pi / n * j2 * t1
   kangle1 := 2 * &pi / n * k1 * t2
   kangle2 := 2 * &pi / n * k2 * t2
   sangle := sfact * &pi / n

   every i := 0 to n do {
      c1 := cos(jangle1 * i)
      s1 := sin(jangle2 * i)
      c2 := cos(kangle1 * i)
      s2 := sin(kangle2 * i)
      suspend Point(x + radius1 * c1 + radius2 * (c1 * c2 - s1 * s2),
         y + yfact * (radius1 * s1 + radius2 * (s1 * c2 + c1 * s2)))
      }

end
