Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- public void paint() {
- getChildren().clear();
- startX0 = (getWidth() / 3);
- startX1 = (getWidth() - getWidth() / 3);
- startX2 = (getWidth() / 2);
- startY0 = (getHeight() / 2
- + Math.sqrt(Math.pow(startX1 - startX0, 2) - Math.pow(((startX1 - startX0) / 2), 2)) / 2);
- startY1 = startY0;
- startY2 = startY0 - Math.sqrt(Math.pow(startX1 - startX0, 2) - Math.pow(((startX1 - startX0) / 2), 2));
- paintKochCurve(order, startX0, startX1, startX2, startY0, startY1, startY2);
- }
- public void paintKochCurve(int order, double x0, double x1, double x2, double y0, double y1, double y2) {
- if (order == 0)
- ;//getChildren().add(new Polyline(startX0, startY0, startX1, startY0, startX2, startY2, startX0, startY0));
- else {
- double uxs = Math.sqrt(Math.pow((x1 - x0) / 3, 2) - Math.pow((y0 - y2) / 3, 2)) + x2;
- double uys = ((y0 - y2) / 3) + y2;
- double uxe = Math.sqrt(Math.pow((2 * (x1 - x0)) / 3, 2) - Math.pow((2 * (y0 - y2)) / 3, 2)) + x2;
- double uye = (2 * (y0 - y2)) / 3 + y2;
- double uxp = x1;
- double uyp = uys;
- double dxs = ((x1 - x0) / 3) + x0;
- double dys = y0;
- double dxe = (2 * (x1 - x0)) / 3 + x0;
- double dye = y0;
- double dxp = (x1 + x0) / 2;
- double dyp = y0 + Math.sqrt(Math.pow(dxe - dxs, 2) - Math.pow(((dxe - dxs) / 2), 2));
- double txs = dxs;
- double tys = ((y0 - y2) / 3) + y2;
- double txe = -Math.sqrt(Math.pow((2 * (x1 - x0)) / 3, 2) - Math.pow((2 * (y0 - y2)) / 3, 2)) + x2;
- double tye = (2 * (y0 - y2)) / 3 + y2;
- double txp = x0;
- double typ = tys;
- getChildren().add(new
- Polyline(x2,y2,uxs,uys,uxp,uyp,uxe,uye,x1,y0));
- getChildren().add(new
- Polyline(x0,y0,dxs,dys,dxp,dyp,dxe,dye,x1,y0));
- getChildren().add(new
- Polyline(x2,y2,txs,tys,txp,typ,txe,tye,x0,y0));
- paintKochCurve(order - 1, uxs, uys, uxp, uyp, uxe, uye);
- paintKochCurve(order -1, dxs, dys, dxp, dyp, dxe, dye);
- paintKochCurve(order -1, txs, tys, txp, typ, txe, tye);
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement