Hello Gerald et al: I like your solution. It is cleaner then mine, but I am having trouble with implementing it. I am not sure how to use erase 'F= ' recursively. I do not have a method in my turtle set for doing this. I am also not sure about how to translate this into a recursive method using Java and turtles.(If this is the wrong place to be asking this question, then just let me know. I am new ot the group, and I am not sure what constitutes an on topic or off topic post) Here is what I hacked out. It works but in kind of a 'wonky' way. So P becomes my method call. R and Q are executed after the respective method calls. angle 4 axiom P P = FPRPQPF R =+F-F Q=-F+F private void drawSkyline(Turtle t1, int itr, double distance) { if(itr == 0) { return; } drawSkyline(t1,itr-1,distance/1.5); t1.turn(90); t1.move(distance); t1.turn(-90); t1.move(distance/3); drawSkyline(t1,itr-1,distance/1.5); t1.turn(-90); t1.move(distance); t1.turn(90); t1.move(distance/3); drawSkyline(t1,itr-1,distance/1.5); //t1.move(distance); } Thanks j.
john,
I like your solution. It is cleaner then mine, but I am having trouble with implementing it. I am not sure how to use erase 'F= ' recursively. I do not have a method in my turtle set for doing this. I am also not sure about how to translate this into a recursive method using Java and turtles.
Well, the idea of the disappearing F is used in i.e. the Dragon Curve (from FRACTINT.L): Dragon { ; Adrian Mariano ; from The Fractal Geometry of Nature by Mandelbrot Angle 8 Axiom FX F= y=+FX--FY+ x=-FX++FY- } ...so I made use of it. In a straightforward iterated string-rewriting scheme this is easy of course (while scanning the source string, for each encountered token one puts the replacement for this token into the target string - and in case of an F one puts nothing into the target string). But using recursion... I googled a bit and found the following (see the URL below). He's doing l-systems in Postscript recursively - with the disappearing F trick. http://www.cs.unh.edu/~charpov/Programming/L-systems/ On the other hand you would need *two* recursive subroutines (X and Y in my Skyline example) calling themselves and/or each other (and both checking for itr == 0, with t1.move(distance) only called when itr == 0). Seems your "wonky" way turns out to be simpler for recursion purposes. Regards, Gerald
participants (2)
-
Gerald K. Dobiasovsky -
john