From decwrl!uunet!allbery Thu Apr 19 05:38:54 PDT 1990
Article 1491 of comp.sources.misc:
Path: decwrl!uunet!allbery
From: edgar@shape.mps.ohio-state.edu (Gerald Edgar)
Newsgroups: comp.sources.misc
Subject: v12i011: Dragon curves with music
Message-ID: <85035@uunet.UU.NET>
Date: 18 Apr 90 00:45:24 GMT
Sender: allbery@uunet.UU.NET
Organization: The Ohio State University, Dept. of Math.
Lines: 415
Approved: allbery@uunet.UU.NET (Brandon S. Allbery - comp.sources.misc)
Posting-number: Volume 12, Issue 11
Submitted-by: edgar@shape.mps.ohio-state.edu (Gerald Edgar)
Archive-name: music.logo/part01
Dragon curves with music. Explanation and Logo source code.
#! /bin/sh
# This is a shell archive. Remove anything before this line, then unpack
# it by saving it into a file and typing "sh file". To overwrite existing
# files, type "sh file -c". You can also feed this as standard input via
# unshar, or by typing "sh 'music.doc' <<'END_OF_FILE'
X
X ***** DRAGON CURVES WITH MUSIC *****
X
XMany of the "fractal" or "self-similar" curves (I call them dragon curves)
Xcan be generated by recursive turtle graphics routines. The basic
Xinstructions in turtle graphics are:
X FORWARD :D go forward for a distance :D
X RIGHT :X turn right by :X degrees
X LEFT :Y turn left by :Y degrees
XFor example, here is the program for the Koch curve:
X
X TO KOCH :SIZE :DEPTH
X IF :DEPTH=0 [FORWARD :SIZE STOP]
X KOCH :SIZE/3 :DEPTH-1
X LEFT 60
X KOCH :SIZE/3 :DEPTH-1
X RIGHT 120
X KOCH :SIZE/3 :DEPTH-1
X LEFT 60
X KOCH :SIZE/3 :DEPTH-1
X END
X
XIn this program, and the other recursive programs that construct dragon
Xcurves, there is a parameter :DEPTH. When :DEPTH is zero, the curve
Xis just a line segment. When :DEPTH is increased by one, each segment
Xis replaced by a copy of a basic figure consisting of a few line segments.
XThe lengths of the individual segments are decreased when this happens,
Xof course.
X
XThe drawing commands are simply moving forward by a certain distance,
Xand turning by a certain angle. This suggests a musical accompaniment
Xfor the drawing of such dragon curves. Moving forward for a distance :D
Xwill correspond to playing a note for length of time :D. Turning will
Xcorrespond to changing the pitch of the note. (Right = higher,
Xleft = lower.) The natural correspondence between angles and changes in
Xpitch lets an octave change correspond to 360 degrees turn. Thus, a turn
Xby :D degrees means that the frequency is multiplied by the factor
X2^(:D/360). For example, a 60-degree turn is a full step; a right-angle
Xturn is a minor third; a 120-degree turn is a major third; and so on.
XNote that the dragon "McWorter's Pentigree" uses angles of 72 degrees;
Xthis interval, 2^(1/5), is not used in Western music. Do you like the
Xsound?
X
XIn the programs, the length of the note played is simply proportional to
Xthe length of the line segment. But a more mathematically correct system
Xwould be to make the time to traverse the whole curve remain constant
Xwhen :DEPTH is changed. (So the duration of the note is proportional
Xto a power of the length of the segment. The exponent used here is
Xthe "fractal dimension".) For example, it the Koch curve, above,
Xthe fractal dimension is s = (log 4)/(log 3). So when :DEPTH is
Xincreased by 1, the length of the line segments is decreased by
Xfactor 1/3, and the length of the notes should be decreased by factor
X(1/3)^s = 1/4. The number of line segments is increased by a factor of
X4, so the total playing time is unchanged.
X
XThe actual "fractal" is the self-similar curve that is the limit as
X:DEPTH increases without bound. In practice, when :DEPTH gets large
Xenough, the pictures no longer change; so the picture gives us a good
Xidea of the fractal curve itself. An interesting experiment would be
Xto do this with the music. I have not been able to reach this goal on my
XMacintosh Plus, since I am using a fairly slow Logo, and since the Mac
Xwill not play notes shorter than a certain length.
X
X(There is some literature on "fractal music". It is NOT this.)
X
X--------------------------------------------------------------------
X Gerald A. Edgar April, 1990
X Dept. of Mathematics
X The Ohio State University
X Columbus, OH 43210 70715,1324 (CompuServe)
X edgar@mps.ohio-state.edu (internet) EDGAR@OHSTPY (bitnet)
END_OF_FILE
if test 3435 -ne `wc -c <'music.doc'`; then
echo shar: \"'music.doc'\" unpacked with wrong size!
fi
# end of 'music.doc'
fi
if test -f 'music.logo' -a "${1}" != "-c" ; then
echo shar: Will not clobber existing file \"'music.logo'\"
else
echo shar: Extracting \"'music.logo'\" \(6588 characters\)
sed "s/^X//" >'music.logo' <<'END_OF_FILE'
X
X;; Dragon curves with music. Logo source code.
X
X;; The curves are:
X;; 1 McWorter's Pentigree
X;; 2 2 Dimensional Curve
X;; 3 Triadic (SNOWFLAKE) Curve
X;; 4 Quadric Curve
X;; 5 Pinwheel Curve
X;; 6 Hexomino Curve
X;; 7 Gosper Curve (FLOWSNAKE)
X;; 8 Arrow Curve
X;; 9 Peano Curve
X
X;; Sample usage: FRACTAL6 100 2
X;; This draws the Hexomino curve with :size 100 and :depth 2
X;; :size is the size of the curve,
X;; :depth is the complexity of the curve (simplest is 0)
X
X;; Or try my preset values to start with: for example
X;; FRACTALS 6 for the Hexomino Curve. (Replace 6 by any
X;; digit 1 to 9 for the other curves.)
X
X;; ---------------------------------------------------------------
X
X;; Tested on a Macintosh Plus using Coral Object Logo.
X;; For other versions of Logo, you may need to make changes.
X;; For example the following:
X
X;; CS
X;; clears the screen. It may be called CG; if so, define it:
X;; TO CS
X;; CG
X;; END
X
X;; TOOT :F :A :D
X;; produces a note with frequency :F Hertz;
X;; amplitude :A (0 to 255); duration :D seconds
X;; Toot is called only by TOOTX with a duration :X/:DENOM,
X;; so the speed can be adjusted by changing the value of
X;; "DENOM. If your TOOT has duration measured in 60ths of
X;; a second, then redefine TOOTX as follows:
X;; TO TOOTX :X
X;; TOOT :FREQ 100 :X/(:DENOM/60)
X;; END
X
X;; The starting frequency is :FREQ, so the pitch can be adjusted
X;; by changing the value of "FREQ.
X
X;; G. A. Edgar April, 1990
X;; Dept. of Mathematics
X;; The Ohio State University
X;; Columbus, OH 43210
X;; edgar@mps.ohio-state.edu (internet) EDGAR@OHSTPY (bitnet)
X
X;; ---------------------------------------------------------------
X
Xmake "genlist [3 5 4 4 3 3 3 3 3]
Xmake "denomlist [200 175 50 50 100 80 150 80 65]
Xmake "denom 50
Xht cs
X
Xto fractal1 :size :depth
Xif :depth = 0 [forward :size tootx :size stop]
Xleftmusic 36
Xfractal1 :size/2.62 :depth-1
Xleftmusic 72
Xfractal1 :size/2.62 :depth-1
Xrightmusic 144
Xfractal1 :size/2.62 :depth-1
Xrightmusic 72
Xfractal1 :size/2.62 :depth-1
Xleftmusic 72
Xfractal1 :size/2.62 :depth-1
Xleftmusic 72
Xfractal1 :size/2.62 :depth-1
Xrightmusic 36
Xend
X
XTO FRACTAL2 :SIZE :DEPTH
XIF :DEPTH = 0 [FD :SIZE TOOTX :SIZE STOP]
XFRACTAL2 :SIZE / 2 :DEPTH - 1
Xleftmusic 90
XFRACTAL2 :SIZE / 2 :DEPTH - 1
Xrightmusic 180
XFRACTAL2 :SIZE / 2 :DEPTH - 1
Xleftmusic 90
XFRACTAL2 :SIZE / 2 :DEPTH - 1
XEND
X
XTO FRACTAL3 :SIZE :DEPTH
XIF :DEPTH = 0 [FD :SIZE TOOTX :SIZE STOP]
XFRACTAL3 :SIZE / 3 :DEPTH - 1
Xleftmusic 60
XFRACTAL3 :SIZE / 3 :DEPTH - 1
Xrightmusic 120
XFRACTAL3 :SIZE / 3 :DEPTH - 1
Xleftmusic 60
XFRACTAL3 :SIZE / 3 :DEPTH - 1
XEND
X
XTO FRACTAL4 :SIZE :DEPTH
XIF :DEPTH = 0 [FD :SIZE TOOTX :SIZE STOP]
XFRACTAL4 :SIZE / 3 :DEPTH - 1
Xleftmusic 90
XFRACTAL4 :SIZE / 3 :DEPTH - 1
Xrightmusic 90
XFRACTAL4 :SIZE / 3 :DEPTH - 1
Xrightmusic 90
XFRACTAL4 :SIZE / 3 :DEPTH - 1
Xleftmusic 90
XFRACTAL4 :SIZE / 3 :DEPTH - 1
XEND
X
XTO FRACTAL5 :SIZE :LEVEL
XPINWHEEL :SIZE :LEVEL
XEND
X
XTO FRACTAL6 :SIZE :LEVEL
XHEX :SIZE :LEVEL
XEND
X
XTO FRACTAL7 :SIZE :DEPTH
XFLOW 0.9 * :SIZE "TRUE :DEPTH
XEND
X
XTO FRACTAL8 :SIZE :LEVEL
XARROW :SIZE :LEVEL
XEND
X
XTO FRACTAL9 :SIZE :LEVEL
XPEANO 0.9 * :SIZE :LEVEL 1
XEND
X
XTO FRACTALS :TYPE
XSETUP
Xmake "denom item :type :denomlist
XRUN ( SE (WORD "FRACTAL :type) 200 (item :type :genlist) )
XEND
X
XTO TOOTX :X
Xtoot :freq 100 :X/:denom
XEND
X
XTO PEANO :S :LEVEL :P
XLOCAL "A
XIF :LEVEL = 0 [FD :S TOOTX :S STOP]
XMAKE "A 0.25 * 2.236067977 * :S
Xleftmusic 60 * :P
XPEANO :S / 3 :LEVEL - 1 -:P
XPEANO :S / 3 :LEVEL - 1 :P
Xrightmusic 60 * :P
XPEANO :S / 3 :LEVEL - 1 :P
Xrightmusic 60 * :P
XPEANO :S / 3 :LEVEL - 1 :P
Xrightmusic 150 * :P
XPEANO :A / 3 :LEVEL - 1 :P
XPEANO :A / 3 :LEVEL - 1 -:P
Xleftmusic 60 * :P
XPEANO :A / 3 :LEVEL - 1 -:P
Xleftmusic 60 * :P
XPEANO :A / 3 :LEVEL - 1 -:P
Xleftmusic 90 * :P
XPEANO :S / 3 :LEVEL - 1 :P
Xrightmusic 150 * :P
XPEANO :A / 3 :LEVEL - 1 :P
XPEANO :A / 3 :LEVEL - 1 -:P
Xleftmusic 150 * :P
XPEANO :S / 3 :LEVEL - 1 -:P
XPEANO :S / 3 :LEVEL - 1 :P
XEND
X
XTO SETUP
XCS
XPU SETPOS [-100 -20] PD
XSETH 90
Xmake "freq 440
XEND
X
XTO 7LB :N :DIR :L
Xrightmusic 79.107
XFLOW :N NOT :DIR :L
Xleftmusic 60 FLOW :N :DIR :L
XFLOW :N :DIR :L
Xleftmusic 120 FLOW :N :DIR :L
Xleftmusic 60 FLOW :N NOT :DIR :L
Xrightmusic 120 FLOW :N NOT :DIR :L
Xrightmusic 60 FLOW :N :DIR :L
Xleftmusic 19.107
XEND
X
XTO 7LF :N :DIR :L
Xrightmusic 19.107
XFLOW :N :DIR :L
Xleftmusic 60 FLOW :N NOT :DIR :L
Xleftmusic 120 FLOW :N NOT :DIR :L
Xrightmusic 60 FLOW :N :DIR :L
Xrightmusic 120 FLOW :N :DIR :L
XFLOW :N :DIR :L
Xrightmusic 60 FLOW :N NOT :DIR :L
Xleftmusic 79.107
XEND
X
XTO FLOW :N :DIR :L
XIF :L = 0 [FD :N TOOTX :N STOP]
XIFelse :DIR [7LF :N / SQrt 7 :DIR :L - 1] [7LB :N / SQrt 7 :DIR :L - 1]
XEND
X
XTO FLOWSNAKE
Xcs ht
XPU SETPOS [30 -20] PD
XREPEAT 3 [FLOW 90 "TRUE 3 rightmusic 120]
Xleftmusic 120
XFLOW 90 "TRUE 3
Xrightmusic 120
XFLOW 90 "TRUE 3
XFLOW 90 "TRUE 3
XEND
X
XTO HEX :SIZE :LEVEL
XIF :LEVEL = 0 [FD :SIZE TOOTX :SIZE STOP]
XHEX 0.25 * :SIZE :LEVEL - 1
Xleftmusic 60
XHEX 0.25 * :SIZE :LEVEL - 1
Xrightmusic 60
XHEX 0.25 * :SIZE :LEVEL - 1
Xrightmusic 60
XHEX 0.25 * :SIZE :LEVEL - 1
Xrightmusic 120
XHEX 0.25 * :SIZE :LEVEL - 1
XHEX 0.25 * :SIZE :LEVEL - 1
Xleftmusic 120
XHEX 0.25 * :SIZE :LEVEL - 1
Xleftmusic 60
XHEX 0.25 * :SIZE :LEVEL - 1
Xleftmusic 60
XHEX 0.25 * :SIZE :LEVEL - 1
Xrightmusic 60
XHEX 0.25 * :SIZE :LEVEL - 1
XEND
X
XTO PINWHEEL :SIZE :LEVEL
XIF :LEVEL = 0 [FD :SIZE TOOTX :SIZE STOP]
Xleftmusic 30
XPINWHEEL 0.288675 * :SIZE :LEVEL - 1
Xrightmusic 60
XPINWHEEL 0.288675 * :SIZE :LEVEL - 1
Xleftmusic 60
XPINWHEEL 0.288675 * :SIZE :LEVEL - 1
Xleftmusic 120
XPINWHEEL 0.288675 * :SIZE :LEVEL - 1
Xleftmusic 120
XPINWHEEL 0.288675 * :SIZE :LEVEL - 1
Xleftmusic 0
XPINWHEEL 0.288675 * :SIZE :LEVEL - 1
Xrightmusic 120
XPINWHEEL 0.288675 * :SIZE :LEVEL - 1
Xrightmusic 120
XPINWHEEL 0.288675 * :SIZE :LEVEL - 1
Xrightmusic 60
XPINWHEEL 0.288675 * :SIZE :LEVEL - 1
Xleftmusic 60
XPINWHEEL 0.288675 * :SIZE :LEVEL - 1
Xrightmusic 30
XEND
X
XTO ARROW :SIZE :LEVEL
XIF :LEVEL = 0 [FD :SIZE TOOTX :SIZE STOP]
XARROW 0.25 * :SIZE :LEVEL - 1
XARROW 0.25 * :SIZE :LEVEL - 1
Xleftmusic 120
XARROW 0.25 * :SIZE :LEVEL - 1
Xrightmusic 120
XARROW 0.25 * :SIZE :LEVEL - 1
Xrightmusic 60
XARROW 0.25 * :SIZE :LEVEL - 1
Xrightmusic 120
XARROW 0.25 * :SIZE :LEVEL - 1
Xleftmusic 60
XARROW 0.25 * :SIZE :LEVEL - 1
Xleftmusic 120
XARROW 0.25 * :SIZE :LEVEL - 1
Xleftmusic 60
XARROW 0.25 * :SIZE :LEVEL - 1
Xrightmusic 60
XARROW 0.25 * :SIZE :LEVEL - 1
XEND
X
Xto leftmusic :x
Xleft :x
Xmake "freq :freq/power 2 (:x/360)
Xend
X
Xto rightmusic :x
Xright :x
Xmake "freq :freq*power 2 (:x/360)
Xend
X
X
END_OF_FILE
if test 6588 -ne `wc -c <'music.logo'`; then
echo shar: \"'music.logo'\" unpacked with wrong size!
fi
# end of 'music.logo'
fi
echo shar: End of shell archive.
exit 0
--
Gerald A. Edgar
Department of Mathematics Bitnet: EDGAR@OHSTPY
The Ohio State University Internet: edgar@mps.ohio-state.edu
Columbus, OH 43210 ...!{att,pyramid}!osu-cis!shape.mps.ohio-state.edu!edgar