int level = 3; int scale = 12; String twist = "slllsllr"; int[][] directions = {{1, 1},{-1, 1},{-1, -1},{1, -1}}; String instructions; int point = 0; int direction = 0; int x = 1; int y = 1; void setup () { framerate(20); size(326, 326); instructions = recurse("s", level); println("length: " + sqrt(instructions.length() - 1)); } String recurse(String s, int levels) { String result = ""; for(int i = 0; i < s.length(); i++) { result += s.charAt(i) + twist; } if (--levels > 0) { result = recurse(result, levels); } return(result); } void draw() { color(0); if (point == 0) { background(255); println(x + " x " + y); x = 1; y = 1; direction = 0; } char c = instructions.charAt(point); if (c == 'l') { direction--; } else if (c == 'r') { direction++; } if (direction < 0) { direction += 4; } int newx = x + directions[direction % 4][0] * scale; int newy = y + directions[direction % 4][1] * scale; line(x, y, newx, newy); x = newx; y = newy; point++; point %= instructions.length(); }