public class Main extends Application {
Eckpunkte eck = new Eckpunkte();
Iterationstiefe it = new Iterationstiefe();
FarbeEckpunkte fa = new FarbeEckpunkte();
Line l1,l2,l3;
Point2D p1,p2,p3;
AnchorPane root;
@Override
public void start(Stage primaryStage) {
int xWertPunkt1 = eck.xKoordinateErsterPunkt();
int yWertPunkt1 = eck.yKoordinateErsterPunkt();
int xWertPunkt2 = eck.xKoordinateZweiterPunkt();
int yWertPunkt3 = eck.yKoordinateDritterPunkt();
int level = it.iterationsTiefe();
root = new AnchorPane();
Scene scene = new Scene(root, 1400, 700);
p1 = new Point2D(xWertPunkt1,yWertPunkt1);
p2 = new Point2D(xWertPunkt2,yWertPunkt1);
p3 = new Point2D(((xWertPunkt1+xWertPunkt2)/2),yWertPunkt3);
run(level,p1,p2,p3);
primaryStage.setTitle("Sierpinski");
primaryStage.setScene(scene);
primaryStage.show();
}
public void run(int order,Point2D p1,Point2D p2,Point2D p3){
if(order==0){
l1=new Line(p1.getX(),p1.getY(),p2.getX(),p2.getY());
l2=new Line(p1.getX(),p1.getY(),p3.getX(),p3.getY());
l3=new Line(p2.getX(),p2.getY(),p3.getX(),p3.getY());
root.getChildren().addAll(l1,l2,l3);
}else{
Point2D p12=midpoint(p1,p2);
Point2D p23=midpoint(p2,p3);
Point2D p31=midpoint(p3,p1);
l1=new Line(p1.getX(),p1.getY(),p2.getX(),p2.getY());
l2=new Line(p1.getX(),p1.getY(),p3.getX(),p3.getY());
l3=new Line(p2.getX(),p2.getY(),p3.getX(),p3.getY());
root.getChildren().addAll(l1,l2,l3);
run(order-1,p1,p12,p31);
run(order-1,p12,p2,p23);
run(order-1,p31,p23,p3);
}
}
public Point2D midpoint(Point2D pp1, Point2D pp2) {
return new Point2D((pp1.getX() + pp2.getX()) / 2, (pp1.getY() + pp2.getY()) / 2);
}
}
;
javafx.embed.swing.SwingFXUtils fXUtils;
BufferedImage bufferedImage = new BufferedImage(550, 400, BufferedImage.TYPE_INT_ARGB);
File file = new File("D:/eigene Dokumente/Sierpinski.jpg");
VBox vbox = null;
public void start(Stage primaryStage) {
vbox = new VBox();
Button btn = new Button();
Image i = new Image("file:C:\\Sierpinski.jpg");
ImageView imageView = new ImageView();
imageView.setImage(i);
vbox.getChildren().add(imageView);
vbox.setSpacing(10);
btn.setText("Möchten Sie speichern?");
btn.setOnAction(new EventHandler<ActionEvent>(){
@Override
public void handle(ActionEvent arg0) {
// here we make image from vbox and add it to scene, can be repeated :)
WritableImage snapshot = vbox.snapshot(new SnapshotParameters(), null);
vbox.getChildren().add(new ImageView(snapshot));
saveImage(snapshot);
System.out.println(vbox.getChildren().size());
}
});
Scene scene = new Scene(new Group(btn), 500, 400);
primaryStage.setScene(scene);
primaryStage.show();
}
private void saveImage(WritableImage snapshot) {
BufferedImage image;
image = javafx.embed.swing.SwingFXUtils.fromFXImage(snapshot, bufferedImage);
try {
Graphics2D gd = (Graphics2D) image.getGraphics();
gd.translate(vbox.getWidth(), vbox.getHeight());
ImageIO.write(image, "png", file);
} catch (IOException ex) {
System.out.println("Kot");;
};
}
Image i = new Image("file:C:\\Sierpinski.jpg");
ImageView imageView = new ImageView();
imageView.setImage(i);
vbox.getChildren().add(imageView);
vbox.setSpacing(10);