From cc914ab905b66271a779291159c01e45ba962d26 Mon Sep 17 00:00:00 2001 From: sabine Date: Tue, 5 Dec 2023 12:20:13 +0000 Subject: [PATCH] =?UTF-8?q?Online-IDE-files/Graph.java=20hinzugef=C3=BCgt?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- Online-IDE-files/Graph.java | 68 +++++++++++++++++++++++++++++++++++++ 1 file changed, 68 insertions(+) create mode 100644 Online-IDE-files/Graph.java diff --git a/Online-IDE-files/Graph.java b/Online-IDE-files/Graph.java new file mode 100644 index 0000000..2f4f86f --- /dev/null +++ b/Online-IDE-files/Graph.java @@ -0,0 +1,68 @@ +class Graph +{ + int breite = 500; + int hoehe = 400; + int rand = 15; + + ArrayList trainingset; + + ArrayList graphenobjekte; + + double streckenInX1Faktor = 0.8; + double streckenInX2Faktor = 10; + + World w = new World(breite, hoehe); + + public Graph(ArrayList t) + { + trainingset = t; + graphenobjekte = new ArrayList(); + w.setBackgroundColor(Color.whitesmoke); + // x1-Achse + Line x1_Achse = new Line(rand, hoehe - rand, breite - rand, hoehe - rand); + x1_Achse.setBorderWidth(1); + x1_Achse.setBorderColor(Color.black); + Text x1_Label = new Text(breite - 2 * rand, hoehe - 2 * rand, 10, "x1"); + x1_Label.setFillColor(Color.darkgrey); + Triangle t1 = new Triangle(breite - rand, hoehe - rand + 5, breite - rand, hoehe - rand - 5, breite - rand + 10, hoehe - rand); + t1.setFillColor(Color.black); + // x2-Achse + Line x2_Achse = new Line(rand, rand, rand, hoehe - rand); + x2_Achse.setBorderWidth(1); + x2_Achse.setBorderColor(Color.black); + Text x2_Label = new Text(rand + 2, rand, 10, "x2"); + x2_Label.setFillColor(Color.darkgrey); + Triangle t2 = new Triangle(rand + 5, rand, rand - 5, rand, rand, rand - 10); + t2.setFillColor(Color.black); + } + + public void zeichnen() + { + for (DataPoint p : trainingset) + { + double x = p.getX1() * streckenInX1Faktor + rand; + double y = -p.getX2() * streckenInX2Faktor - rand + hoehe; + Circle c = new Circle(x, y, 5); + Text t = new Text(x + 2, y + 2, 10, p.getName()); + t.setFillColor(Color.darkgrey); + if(p.getLabel() == 1) + { + c.setFillColor(Color.greenyellow); + } + else { + c.setFillColor(Color.red); + } + graphenobjekte.add(c); + graphenobjekte.add(t); + } + } + + public void leeren() + { + for (Shape o : graphenobjekte) + { + o.destroy(); + } + graphenobjekte.clear(); + } +} \ No newline at end of file