Jump to content

Koch curve: Difference between revisions

m
Minor changes to code.
m (Added language identifier.)
m (Minor changes to code.)
Line 1,179:
=={{header|Java}}==
<syntaxhighlight lang="java">
 
import java.awt.Point;
import java.io.IOException;
Line 1,196 ⟶ 1,197:
String text = kochCurveText(points, IMAGE_SIZE);
Files.write(Paths.get("C:/Users/psnow/Desktop/koch.svg"), text.getBytes());
}
private static List<Point> initialEquilateralTriangle() {
final int boxSizemargin = IMAGE_SIZE - MARGIN50;
final int boxSize = IMAGE_SIZE - margin;
final int sideLength = Math.round(boxSize * SIN_60_DEGREES);
final int x = ( boxSize + MARGINmargin - sideLength ) / 2;
final int y = Math.round(( boxSize + MARGINmargin ) / 2 - sideLength * SIN_60_DEGREES / 3);
List<Point> points = Arrays.asList(
Line 1,219 ⟶ 1,221:
for ( int i = 0; i < aPoints.size() - 1; i++ ) {
final int x0 = aPoints.get(i).x;
final int y0 = aPoints.get(i).y;
final int x1 = aPoints.get(i + 1).x;
final int y1 = aPoints.get(i + 1).y;
final int dy = y1 - y0;
final int dx = x1 - x0;
result.add(aPoints.get(i));
Line 1,244 ⟶ 1,246:
text.append("<polygon points='");
for ( int i = 0; i < aPoints.size(); i++ ) {
text.append(aPoints.get(i).x + ", " + aPoints.get(i).y + " ");
}
text.append("' style='fill:pink;stroke:black;stroke-width:2'/>\n</svg>\n");
Line 1,251 ⟶ 1,253:
}
private static final int IMAGE_SIZE = 700;
private static final int MARGIN = 50;
private static final float SIN_60_DEGREES = (float) Math.sin(Math.PI / 3.0);
908

edits

Cookies help us deliver our services. By using our services, you agree to our use of cookies.