Pentagram: Difference between revisions

Content added Content deleted
(→‎{{header|Java}}: no need actually for recursion)
Line 43: Line 43:
}
}


private void drawPentagramR(Graphics2D g, int len, int x1, int y1,
private void drawPentagram(Graphics2D g, int len, int x1, int y1) {
double angle, int depth) {
double angle = 0;


if (depth == 0)
for (int i = 0; i < 5; i++) {
return;
int x2 = x1 + (int) (Math.cos(angle) * len);
int y2 = y1 + (int) (Math.sin(-angle) * len);

int x2 = x1 + (int) (Math.cos(angle) * len);
g.drawLine(x1, y1, x2, y2);
int y2 = y1 + (int) (Math.sin(-angle) * len);
x1 = x2;
y1 = y2;

g.drawLine(x1, y1, x2, y2);
angle -= degrees144;
}

drawPentagramR(g, len, x2, y2, angle - degrees144, depth - 1);
}
}


Line 90: Line 89:


g.setColor(Color.darkGray);
g.setColor(Color.darkGray);
drawPentagramR(g, 500, 70, 250, 0, 5);
drawPentagram(g, 500, 70, 250);
}
}
}</lang>
}</lang>