Fractals in some cases can be represented using strings. The 1st order Koch snowflake can be represented by "SRSRS." The "S" stands for straight and the "R" stands for turn right 120 degrees. Higher order snowflakes can be obtained by replacing all the "S"s in an iteration with "SLSRSLS" where the "L" stands for turn left 60 degrees.
1st: "SRSRS"
2nd: "SLSRSLS R SLSRSLS R SLSRSLS"
3rd: "SLSRSLS L SLSRSLS R SLSRSLS L SLSRSLS R SLSRSLS L SLSRSLS R SLSRSLS L SLSRSLS R SLSRSLS L SLSRSLS R SLSRSLS L SLSRSLS"
Create a program that asks the user what order snowflake they would like and then fits that snowflake nicely on the screen. Do not hard code the strings for anything other than the 1st order snowflake. Use string manipulation techniques to increase the order of the snowflake.
Hint: Start at (-200,115) for every order. "S" is 400 pixels for a 1st order snowflake. The length of "S" goes down by a factor of 3 for every next order snowflake.
Method Hints: There are 3 String methods that will come in very handy: length, charAt, and replaceAll. You can read up about them here.
Structure Hints: You should have two loops. The first one will help you build up the string by repeatedly replacing all the "S" 's with "SLSRSLS". The second one can be a simple for loop. for(int i=0;i<?;i++) This second loop can be used to look at each character separately in the string and make the turtle do one of three things: go straight, turn left 60 degrees, or turn right 120 degrees.
Check out the Hilbert Curve and the Dragon Curve if this interests you.