-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathProject3_Functions.java
More file actions
27 lines (21 loc) · 896 Bytes
/
Project3_Functions.java
File metadata and controls
27 lines (21 loc) · 896 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
import java.util.HashMap;
public class Project3_Functions {
static String Generate_LSystem(int iterations, String start, HashMap<Character,String> rules){
//TODO: Implement the L-System generator. Apply the rules to the starting string, and loop some number of times.
String curr = start;
for (int i = 0; i < iterations; i++) {
System.out.println("Iteration " + (i + 1) + ": " + curr);
StringBuilder next = new StringBuilder();
for (int j = 0; j < curr.length(); j++) {
char character = curr.charAt(j);
if (rules.containsKey(character)){
next.append(rules.get(character));
}else{
next.append(character);
}
}
curr = next.toString();
}
return curr;
}
}