; ;; Sierpinski's Triangle ; ; Sierpinksi's Triangle is a famous two-dimensional fractal. The ; rules to create Sierpinski's triangle are simple: ; 1. Start with a triangle. ; 2. Draw a smaller triangle in the middle of the larger triangle ; with the points of the smaller triangle on the midpoints of the ; larger triangle's sides. This partitions the large triangle into 4 ; smaller triangles: a middle triangle and the triangles at each of ; the corners of the larger triangle. ; 3. Leave the middle triangle empty. ; 4. Visit each of the corner triangles in the larger triangle and ; repeat the rules starting with step 1 but now using each of these ; smaller triangles as the starting triangle. ; 5. Repeat for as many levels as you want: the result is ; Sierpinski's Triangle. ; Here is a musical hommage to the Sierpinski triangle using a ; recursive process to generate a self-similar melody based on a set ; set of tones representing the "sides" of the triangle: process sierpinski(tone, melody, trans, levels, dur, amp) with len = length(melody) for i in melody for k = transpose(tone, i) ;; play current tone in melody mp:midi(dur: dur , amp: amp, key: k, chan: 0) if (levels > 1) ;; sprout melody on tone at next level sprout( sierpinski(transpose(k, trans), melody, trans, levels - 1, dur / len, amp)) end wait dur end ; This little algorithm generates a melodic shape on successive ; transpositions (levels) of itself. Tone is the melodic tone to ; base the melody on in the current level, melody is a list of ; intervals representing the melody, level is the number of levels ; the melody should be reproduced on, and dur and amp are the ; duration and amplitude of the process, respectively. Note that ; the actual duration of each note is the process duration (dur) ; divided by the number of intervals in the melody. Thus, the ; entire melody in the next level will occupy the same mount of ; time as one tone in the current level. When the process starts ; running it outputs each note in the melody transposed to the ; current tone. If levels is greater then 1 then the process ; sprouts recursive copies of itself for each note in the melody ; transposed up trans intervals. The value for levels is decremented ; by 1 , which will cause the recursive process to stop when the ; value reaches 0. ; ;; Listening to sierpinski. ; sprout(sierpinski(key("a0"), {0 7 5}, 12, 4, 3, .5)) sprout(sierpinski(key("a0"), {0 7 5}, 8, 5, 7, .5)) sprout(sierpinski(key("a0"), {0 -1 2 13}, 12, 5, 24, .5)) ; Specify levels and melody length with care! The number of events the ; sierpinski process generates is exponentially related to the length ; m of the melody and the number of levels l. For example the first ; sprout generates 120 events and the second produces 1364 events!