I am doing Koch fractal snowflake in java and save it in a svg file.
I am doing it memorizing the fractal with a LineStrip2D class (it is a wrapper of ArrayList of Vec2D that implements iterable).
The main function is this one:
public static LineStrip2D repeatPatternIntoLineStrip2D(
LineStrip2D pattern,
LineStrip2D polygon,
boolean repeatUp) {
/*
* pattern: must be a pattern between Vec(0,0) and Vec(1,0)
* (normalized beetween 0-1 and in X axis)
* */
float angle, distance;
Vec2D pivot, a, b, direction, b1;
LineStrip2D new_polygon = new LineStrip2D();
new_polygon.add(pattern.vertices.get(0));
a = polygon.vertices.get(0);
int count=0;
for (int i = 1; i < polygon.vertices.size(); i++) {
b = polygon.vertices.get(i);
a = polygon.vertices.get(i-1);
distance = b.distanceTo(a);
direction = b.sub(a).normalize();
angle = PApplet.atan2(direction.y, direction.x);
pivot = a;
for (int j = 1; j < pattern.vertices.size(); j++) {
Vec2D _b1 = pattern.vertices.get(j);
b1 = _b1.copy() ;
if(repeatUp)b1.y *= -1;
b1.scaleSelf(distance);
b1 = b1.rotate(angle);
b1.addSelf(pivot);
new_polygon.add(b1);
count++;
}
a = b;
}
System.out.println(count);
return new_polygon;
}
I have a pattern with initial koch curve:
And I call:
pattern = GeometryHelper.repeatPatternIntoLineStrip2D(pattern, pattern, false);
Now the problem:
After some iterations (851968) I have a java.lang.OutOfMemoryError: Java heap space. How can I avoid this error and achieve a huge svg file? I think I can do this process in various steps, but I don't understand how to implement it in a smart way.