summaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
Diffstat (limited to 'src')
-rwxr-xr-xsrc/Core.java8
-rwxr-xr-xsrc/OptionWindow.java60
-rwxr-xr-xsrc/aufgaben/Aufgabe.java13
-rwxr-xr-xsrc/aufgaben/b20160411/Aufgabe1.java62
-rwxr-xr-xsrc/aufgaben/b20160411/Aufgabe2.java56
-rwxr-xr-xsrc/aufgaben/b20160411/Aufgabe3.java58
-rwxr-xr-xsrc/aufgaben/b20160411/Aufgabe4.java56
-rwxr-xr-xsrc/aufgaben/b20160411/Aufgabe5.java56
-rwxr-xr-xsrc/aufgaben/b20160413/Aufgabe4.java71
-rwxr-xr-xsrc/aufgaben/b20160413/Aufgabe6.java105
-rwxr-xr-xsrc/aufgaben/b20160413/Image.java68
-rwxr-xr-xsrc/aufgaben/b20160413/Zusatz1.java84
-rwxr-xr-xsrc/aufgaben/b20160420/Aufgabe2.java76
-rwxr-xr-xsrc/aufgaben/b20160425/Aufgabe1.java73
-rwxr-xr-xsrc/aufgaben/b20160425/Aufgabe2.java82
-rwxr-xr-xsrc/aufgaben/b20160425/Aufgabe3.java121
-rwxr-xr-xsrc/aufgaben/b20160604/Aufgabe1.java109
-rwxr-xr-xsrc/aufgaben/b20160604/Aufgabe2.java63
-rwxr-xr-xsrc/aufgaben/b20160604/Aufgabe3.java67
-rwxr-xr-xsrc/aufgaben/b20160604/Aufgabe4.java79
-rwxr-xr-xsrc/aufgaben/bildverarbeitung/Aufgabe1.java72
-rwxr-xr-xsrc/aufgaben/bildverarbeitung/Aufgabe3.java59
-rwxr-xr-xsrc/aufgaben/blatt1/Aufgabe1.java58
-rwxr-xr-xsrc/aufgaben/blatt1/Aufgabe2a.java58
-rwxr-xr-xsrc/aufgaben/blatt1/Aufgabe2b40.java97
-rwxr-xr-xsrc/aufgaben/blatt1/Aufgabe2bEPIC.java97
-rwxr-xr-xsrc/aufgaben/blatt1/Aufgabe2c40.java58
-rwxr-xr-xsrc/aufgaben/blatt1/Aufgabe2c40UTF8.java58
-rwxr-xr-xsrc/aufgaben/blatt1/Aufgabe2cEPIC.java58
-rwxr-xr-xsrc/aufgaben/blatt1/Aufgabe2cEPICUTF8.java58
-rwxr-xr-xsrc/aufgaben/blatt2/Aufgabe1.java64
-rwxr-xr-xsrc/aufgaben/blatt2/Objekt.java65
-rwxr-xr-xsrc/aufgaben/imageio/Aufgabe1.java193
-rwxr-xr-xsrc/aufgaben/imageio/ImageType.java8
-rwxr-xr-xsrc/aufgaben/imageio/Komprimierung1.java225
-rwxr-xr-xsrc/function/Display.java45
-rwxr-xr-xsrc/function/Function.java7
-rwxr-xr-xsrc/function/Grade1.java17
-rwxr-xr-xsrc/function/Grade2.java17
-rwxr-xr-xsrc/function/Sin.java19
-rwxr-xr-xsrc/function/SquareRoot.java17
-rwxr-xr-xsrc/misc/CompressedImage.java129
-rwxr-xr-xsrc/misc/Stapel.java51
-rwxr-xr-xsrc/misc/Utils.java73
44 files changed, 2970 insertions, 0 deletions
diff --git a/src/Core.java b/src/Core.java
new file mode 100755
index 0000000..8a9b319
--- /dev/null
+++ b/src/Core.java
@@ -0,0 +1,8 @@
+
+public class Core {
+
+ public static void main(String[] bla) {
+ new OptionWindow();
+ }
+
+}
diff --git a/src/OptionWindow.java b/src/OptionWindow.java
new file mode 100755
index 0000000..bbba5bc
--- /dev/null
+++ b/src/OptionWindow.java
@@ -0,0 +1,60 @@
+import java.awt.BorderLayout;
+import java.awt.Dimension;
+import java.awt.FlowLayout;
+import java.awt.Frame;
+import java.awt.GridLayout;
+import java.awt.event.ActionEvent;
+import java.awt.event.ActionListener;
+
+import javax.swing.JButton;
+import javax.swing.JComboBox;
+import javax.swing.JPanel;
+
+import aufgaben.*;
+import aufgaben.blatt1.*;
+
+public class OptionWindow extends Frame {
+
+ private final int width = 300, height = 300;
+ private GridLayout layout;
+ private JComboBox combo;
+ private JButton button;
+ private JPanel panel;
+ private Aufgabe current;
+ private Aufgabe[] aufgaben;
+
+ public OptionWindow() {
+ layout = getLayout();
+ this.setTitle("Aufgabenauswahl");
+ this.setResizable(false);
+ this.setLayout(layout);
+ this.setPreferredSize(new Dimension(width, height));
+ aufgaben = new Aufgabe[] { new aufgaben.blatt1.Aufgabe1(), new aufgaben.blatt1.Aufgabe2a(), new aufgaben.blatt1.Aufgabe2b40(), new aufgaben.blatt1.Aufgabe2bEPIC(), new aufgaben.blatt1.Aufgabe2c40(), new aufgaben.blatt1.Aufgabe2c40UTF8(), new aufgaben.blatt1.Aufgabe2cEPIC(), new aufgaben.blatt1.Aufgabe2cEPICUTF8(), new aufgaben.blatt2.Aufgabe1(), new aufgaben.bildverarbeitung.Aufgabe1(), new aufgaben.bildverarbeitung.Aufgabe3(), new aufgaben.b20160604.Aufgabe1(), new aufgaben.b20160604.Aufgabe2(), new aufgaben.b20160604.Aufgabe3(), new aufgaben.b20160604.Aufgabe4(), new aufgaben.b20160411.Aufgabe1(), new aufgaben.b20160411.Aufgabe2(), new aufgaben.b20160411.Aufgabe3(), new aufgaben.b20160411.Aufgabe4(), new aufgaben.b20160411.Aufgabe5(), new aufgaben.b20160413.Image(), new aufgaben.b20160413.Aufgabe4(), new aufgaben.b20160413.Aufgabe6(), new aufgaben.b20160413.Zusatz1(), new aufgaben.b20160425.Aufgabe1(), new aufgaben.b20160425.Aufgabe2(), new aufgaben.b20160425.Aufgabe3(), new aufgaben.imageio.Aufgabe1(), new aufgaben.imageio.Komprimierung1() };
+ combo = new JComboBox();
+ for(int i = 0; i<aufgaben.length; i++) {
+ combo.addItem(aufgaben[i].getName());
+ }
+ button = new JButton("Starten");
+ button.addActionListener(new ActionListener() {
+ @Override
+ public void actionPerformed(ActionEvent arg0) {
+ aufgaben[combo.getSelectedIndex()].init();
+ aufgaben[combo.getSelectedIndex()].setVisible(true);
+ }
+ });
+
+ this.add(combo);
+ this.add(button);
+
+ this.pack();
+ this.setVisible(true);
+ }
+
+ public GridLayout getLayout() {
+ GridLayout layout = new GridLayout();
+ layout.setColumns(1);
+ layout.setRows(2);
+ return layout;
+ }
+
+}
diff --git a/src/aufgaben/Aufgabe.java b/src/aufgaben/Aufgabe.java
new file mode 100755
index 0000000..174ee26
--- /dev/null
+++ b/src/aufgaben/Aufgabe.java
@@ -0,0 +1,13 @@
+package aufgaben;
+
+import java.awt.Frame;
+
+public abstract class Aufgabe extends Frame {
+
+ public abstract boolean done();
+
+ public abstract void init();
+
+ public abstract String getName();
+
+}
diff --git a/src/aufgaben/b20160411/Aufgabe1.java b/src/aufgaben/b20160411/Aufgabe1.java
new file mode 100755
index 0000000..ebd4cb7
--- /dev/null
+++ b/src/aufgaben/b20160411/Aufgabe1.java
@@ -0,0 +1,62 @@
+package aufgaben.b20160411;
+
+import java.awt.Color;
+import java.awt.Graphics;
+import java.awt.event.WindowAdapter;
+import java.awt.event.WindowEvent;
+
+import misc.Utils;
+import aufgaben.Aufgabe;
+
+public class Aufgabe1 extends Aufgabe {
+
+ private final int width = 500, height = 500;
+ private boolean done;
+ private String name;
+
+ public Aufgabe1() {
+ name = "RGB Farbraum - Aufgabe 1";
+ done = false;
+ this.setSize(width, height);
+ this.setTitle("Blatt 1 - Aufgabe 1");
+ }
+
+ @Override
+ public boolean done() {
+ return false;
+ }
+
+ public void paint(Graphics g) {
+ int r = 0, b = 0;
+ for(int x = 50; x<110; x+=10) {
+ for(int y = 50; y<110; y+=10) {
+ b += 42;
+ g.setColor(new Color(0,0,0));
+ g.drawRect(x, y, 10, 10);
+ g.setColor(new Color(r, 0, b));
+ g.fillRect(x, y, 10, 10);
+ }
+ r += 42;
+ b = 0;
+ }
+ }
+
+ @Override
+ public String getName() {
+ return name;
+ }
+
+ @Override
+ public void init() {
+ this.addWindowListener(
+ new WindowAdapter() {
+ @Override
+ public void windowClosing(WindowEvent e) {
+ System.out.println("close");
+ done = true;
+ }
+ }
+ );
+ }
+
+}
diff --git a/src/aufgaben/b20160411/Aufgabe2.java b/src/aufgaben/b20160411/Aufgabe2.java
new file mode 100755
index 0000000..deb21c2
--- /dev/null
+++ b/src/aufgaben/b20160411/Aufgabe2.java
@@ -0,0 +1,56 @@
+package aufgaben.b20160411;
+
+import java.awt.Color;
+import java.awt.Graphics;
+import java.awt.event.WindowAdapter;
+import java.awt.event.WindowEvent;
+
+import misc.Utils;
+import aufgaben.Aufgabe;
+
+public class Aufgabe2 extends Aufgabe {
+
+ private final int width = 500, height = 500;
+ private boolean done;
+ private String name;
+
+ public Aufgabe2() {
+ name = "RGB Farbraum - Aufgabe 2";
+ done = false;
+ this.setSize(width, height);
+ this.setTitle(name);
+ }
+
+ @Override
+ public boolean done() {
+ return false;
+ }
+
+ public void paint(Graphics g) {
+ for(int i = 0; i<255; i++) {
+ g.setColor(new Color(255-i, 0, i));
+ g.drawLine(100+i, 100, 100+i, 355);
+ }
+ g.setColor(new Color(0,0,0));
+ g.drawRect(100, 100, 255, 255);
+ }
+
+ @Override
+ public String getName() {
+ return name;
+ }
+
+ @Override
+ public void init() {
+ this.addWindowListener(
+ new WindowAdapter() {
+ @Override
+ public void windowClosing(WindowEvent e) {
+ System.out.println("close");
+ done = true;
+ }
+ }
+ );
+ }
+
+}
diff --git a/src/aufgaben/b20160411/Aufgabe3.java b/src/aufgaben/b20160411/Aufgabe3.java
new file mode 100755
index 0000000..c6e9510
--- /dev/null
+++ b/src/aufgaben/b20160411/Aufgabe3.java
@@ -0,0 +1,58 @@
+package aufgaben.b20160411;
+
+import java.awt.Color;
+import java.awt.Graphics;
+import java.awt.event.WindowAdapter;
+import java.awt.event.WindowEvent;
+
+import misc.Utils;
+import aufgaben.Aufgabe;
+
+public class Aufgabe3 extends Aufgabe {
+
+ private final int width = 1000, height = 500;
+ private boolean done;
+ private String name;
+
+ public Aufgabe3() {
+ name = "RGB Farbraum - Aufgabe 3";
+ done = false;
+ this.setSize(width, height);
+ this.setTitle(name);
+ }
+
+ @Override
+ public boolean done() {
+ return false;
+ }
+
+ public void paint(Graphics g) {
+ for(int i = 0; i<255; i++) {
+ g.setColor(new Color(255-i, 0, i));
+ g.drawLine(100+i, 100, 100+i, 355);
+ }
+ for(int i = 0; i<255; i++) {
+ g.setColor(new Color(0, i, 255-i));
+ g.drawLine(355+i, 100, 355+i, 355);
+ }
+ }
+
+ @Override
+ public String getName() {
+ return name;
+ }
+
+ @Override
+ public void init() {
+ this.addWindowListener(
+ new WindowAdapter() {
+ @Override
+ public void windowClosing(WindowEvent e) {
+ System.out.println("close");
+ done = true;
+ }
+ }
+ );
+ }
+
+}
diff --git a/src/aufgaben/b20160411/Aufgabe4.java b/src/aufgaben/b20160411/Aufgabe4.java
new file mode 100755
index 0000000..7f3250e
--- /dev/null
+++ b/src/aufgaben/b20160411/Aufgabe4.java
@@ -0,0 +1,56 @@
+package aufgaben.b20160411;
+
+import java.awt.Color;
+import java.awt.Graphics;
+import java.awt.event.WindowAdapter;
+import java.awt.event.WindowEvent;
+
+import misc.Utils;
+import aufgaben.Aufgabe;
+
+public class Aufgabe4 extends Aufgabe {
+
+ private final int width = 1000, height = 1000;
+ private boolean done;
+ private String name;
+
+ public Aufgabe4() {
+ name = "RGB Farbraum - Aufgabe 4";
+ done = false;
+ this.setSize(width, height);
+ this.setTitle(name);
+ }
+
+ @Override
+ public boolean done() {
+ return false;
+ }
+
+ public void paint(Graphics g) {
+ for(int i = 0; i<255; i++) {
+ g.setColor(new Color(255-i, 0, i));
+ g.drawLine(100+i, 100, 100+i, 255);
+ }
+ g.setColor(new Color(0,0,0));
+ g.drawRect(100, 100, 255, 255);
+ }
+
+ @Override
+ public String getName() {
+ return name;
+ }
+
+ @Override
+ public void init() {
+ this.addWindowListener(
+ new WindowAdapter() {
+ @Override
+ public void windowClosing(WindowEvent e) {
+ System.out.println("close");
+ done = true;
+ }
+ }
+ );
+ }
+
+}
diff --git a/src/aufgaben/b20160411/Aufgabe5.java b/src/aufgaben/b20160411/Aufgabe5.java
new file mode 100755
index 0000000..124feed
--- /dev/null
+++ b/src/aufgaben/b20160411/Aufgabe5.java
@@ -0,0 +1,56 @@
+package aufgaben.b20160411;
+
+import java.awt.Color;
+import java.awt.Graphics;
+import java.awt.event.WindowAdapter;
+import java.awt.event.WindowEvent;
+
+import misc.Utils;
+import aufgaben.Aufgabe;
+
+public class Aufgabe5 extends Aufgabe {
+
+ private final int width = 1000, height = 1000;
+ private boolean done;
+ private String name;
+
+ public Aufgabe5() {
+ name = "RGB Farbraum - Aufgabe 5";
+ done = false;
+ this.setSize(width, height);
+ this.setTitle(name);
+ }
+
+ @Override
+ public boolean done() {
+ return false;
+ }
+
+ public void paint(Graphics g) {
+ for(int i = 0; i<255; i++) {
+ g.setColor(new Color(255-i, 0, i));
+ g.drawLine(100+i, 100, 100+i, 255);
+ }
+ g.setColor(new Color(0,0,0));
+ g.drawRect(100, 100, 255, 255);
+ }
+
+ @Override
+ public String getName() {
+ return name;
+ }
+
+ @Override
+ public void init() {
+ this.addWindowListener(
+ new WindowAdapter() {
+ @Override
+ public void windowClosing(WindowEvent e) {
+ System.out.println("close");
+ done = true;
+ }
+ }
+ );
+ }
+
+}
diff --git a/src/aufgaben/b20160413/Aufgabe4.java b/src/aufgaben/b20160413/Aufgabe4.java
new file mode 100755
index 0000000..ad720b9
--- /dev/null
+++ b/src/aufgaben/b20160413/Aufgabe4.java
@@ -0,0 +1,71 @@
+package aufgaben.b20160413;
+
+import java.awt.Color;
+import java.awt.Graphics;
+import java.awt.event.WindowAdapter;
+import java.awt.event.WindowEvent;
+import java.awt.image.BufferedImage;
+import java.io.File;
+import java.io.IOException;
+
+import javax.imageio.ImageIO;
+
+import aufgaben.Aufgabe;
+import misc.Utils;
+
+public class Aufgabe4 extends Aufgabe {
+
+ private final int width = 500, height = 500;
+ private boolean done = false;
+ private String name;
+ private BufferedImage image;
+ private Color[][] pixels;
+
+ public Aufgabe4() {
+ name = "Graustufen";
+ this.setSize(width, height);
+ this.setTitle(name);
+ this.addWindowListener(
+ new WindowAdapter() {
+ @Override
+ public void windowClosing(WindowEvent e) {
+ System.out.println("close");
+ done = true;
+ }
+ }
+ );
+ }
+
+ @Override
+ public boolean done() {
+ return done;
+ }
+
+ public void paint(Graphics g) {
+ if(image != null)
+ g.drawImage(image, 0, 100, 500, 300, this);
+ }
+
+ @Override
+ public String getName() {
+ return name;
+ }
+
+ @Override
+ public void init() {
+ pixels = new Color[width][height];
+ try {
+ image = ImageIO.read(new File("title.png"));
+ for(int x = 0, width = image.getWidth(); x<width; x++) {
+ for(int y = 0, height = image.getHeight(); y<height; y++) {
+ Color c = new Color(image.getRGB(x, y));
+ int h = (int)(((double)(c.getRed()+c.getGreen()+c.getBlue())/765)*255);
+ image.setRGB(x, y, new Color(h, h, h).getRGB());
+ }
+ }
+ } catch (IOException e) {
+ e.printStackTrace();
+ }
+ }
+
+}
diff --git a/src/aufgaben/b20160413/Aufgabe6.java b/src/aufgaben/b20160413/Aufgabe6.java
new file mode 100755
index 0000000..a888197
--- /dev/null
+++ b/src/aufgaben/b20160413/Aufgabe6.java
@@ -0,0 +1,105 @@
+package aufgaben.b20160413;
+
+import java.awt.Color;
+import java.awt.Graphics;
+import java.awt.event.WindowAdapter;
+import java.awt.event.WindowEvent;
+import java.awt.image.BufferedImage;
+import java.io.File;
+import java.io.IOException;
+import java.util.ArrayList;
+
+import javax.imageio.ImageIO;
+import javax.swing.JPanel;
+import javax.swing.JSlider;
+import javax.swing.JSpinner;
+import javax.swing.SpinnerNumberModel;
+import javax.swing.event.ChangeEvent;
+import javax.swing.event.ChangeListener;
+
+import aufgaben.Aufgabe;
+import misc.Utils;
+
+public class Aufgabe6 extends Aufgabe {
+
+ private final int width = 500, height = 500;
+ private boolean done = false;
+ private String name;
+ private BufferedImage image;
+ private Color[][] pixels;
+ private JSpinner spinner;
+ private JPanel panel;
+ private ArrayList<Double> arr;
+
+ public Aufgabe6() {
+ name = "YUV Visualisierung";
+ this.setSize(width, height);
+ this.setTitle(name);
+ this.addWindowListener(
+ new WindowAdapter() {
+ @Override
+ public void windowClosing(WindowEvent e) {
+ System.out.println("close");
+ done = true;
+ }
+ }
+ );
+ this.setLayout(null);
+ }
+
+ @Override
+ public boolean done() {
+ return done;
+ }
+
+ @Override
+ public String getName() {
+ return name;
+ }
+
+ @Override
+ public void init() {
+ arr = new ArrayList<Double>();
+ panel = new JPanel() {
+ public void paint(Graphics g) {
+ g.clearRect(0, 0, this.getWidth(), this.getHeight());
+ for(int x = 0; x<this.getWidth(); x++) {
+ for(int y = 0; y<this.getHeight(); y++) {
+ double r = (double)spinner.getValue()+(((y-100)/100.0)/0.877),
+ b = (double)spinner.getValue()+(((x-100)/100.0)/0.493),
+ gr = (1/0.587)*(double)spinner.getValue()-(0.299/0.587)*r-(0.114/0.587)*b;
+ //System.out.println("R: " + r + ", G: " + gr + ", B: " + b);
+ //arr.add(r);
+ if(r >= 0.0 && gr >= 0.0 && b >= 0.0 && r <= 1.0 && gr <= 1.0 && b <= 1.0) {
+ g.setColor(new Color((int)Math.round(r*255), (int)Math.round(gr*255), (int)Math.round(b*255)));
+ g.fillRect(x, y, 1, 1);
+ }
+ }
+ }
+ /*
+ double max = 0.0;
+ for(int x = 0; x<arr.size(); x++) {
+ for(int y = 0; y<arr.size(); y++) {
+ if(arr.get(x)>arr.get(y))
+ max = arr.get(x);
+ }
+ }
+ System.out.println(max);
+ */
+ g.setColor(Color.BLACK);
+ g.drawRect(0, 0, 199, 199);
+ }
+ };
+ panel.setBounds(100, 200, 200, 200);
+ spinner = new JSpinner(new SpinnerNumberModel(1f, 0f, 1f, 0.01f));
+ spinner.setBounds(100, 100, 100, 20);
+ spinner.addChangeListener(new ChangeListener() {
+ public void stateChanged(ChangeEvent e) {
+ panel.repaint();
+ }
+ });
+ this.add(panel);
+ this.add(spinner);
+ }
+
+}
diff --git a/src/aufgaben/b20160413/Image.java b/src/aufgaben/b20160413/Image.java
new file mode 100755
index 0000000..eb3b95f
--- /dev/null
+++ b/src/aufgaben/b20160413/Image.java
@@ -0,0 +1,68 @@
+package aufgaben.b20160413;
+
+import java.awt.Color;
+import java.awt.Graphics;
+import java.awt.event.WindowAdapter;
+import java.awt.event.WindowEvent;
+import java.awt.image.BufferedImage;
+import java.io.File;
+import java.io.IOException;
+
+import javax.imageio.ImageIO;
+
+import aufgaben.Aufgabe;
+import misc.Utils;
+
+public class Image extends Aufgabe {
+
+ private final int width = 500, height = 500;
+ private boolean done = false;
+ private String name;
+ private BufferedImage image;
+
+ public Image() {
+ name = "Image";
+ this.setSize(width, height);
+ this.setTitle(name);
+ this.addWindowListener(
+ new WindowAdapter() {
+ @Override
+ public void windowClosing(WindowEvent e) {
+ System.out.println("close");
+ done = true;
+ }
+ }
+ );
+ }
+
+ @Override
+ public boolean done() {
+ return done;
+ }
+
+ public void paint(Graphics g) {
+ if(image != null)
+ g.drawImage(image, 0, 100, 500, 300, this);
+ }
+
+ @Override
+ public String getName() {
+ return name;
+ }
+
+ @Override
+ public void init() {
+ try {
+ image = ImageIO.read(new File("title.png"));
+ Color c = new Color(image.getRGB(400, 150));
+ System.out.println("R: " + c.getRed() + ", G: " + c.getGreen() + ", B: " + c.getBlue());
+ c = new Color(image.getRGB(410, 150));
+ System.out.println("R: " + c.getRed() + ", G: " + c.getGreen() + ", B: " + c.getBlue());
+ c = new Color(image.getRGB(420, 150));
+ System.out.println("R: " + c.getRed() + ", G: " + c.getGreen() + ", B: " + c.getBlue());
+ } catch (IOException e) {
+ e.printStackTrace();
+ }
+ }
+
+}
diff --git a/src/aufgaben/b20160413/Zusatz1.java b/src/aufgaben/b20160413/Zusatz1.java
new file mode 100755
index 0000000..470a908
--- /dev/null
+++ b/src/aufgaben/b20160413/Zusatz1.java
@@ -0,0 +1,84 @@
+package aufgaben.b20160413;
+
+import java.awt.Color;
+import java.awt.Graphics;
+import java.awt.event.WindowAdapter;
+import java.awt.event.WindowEvent;
+import java.awt.image.BufferedImage;
+import java.io.File;
+import java.io.IOException;
+
+import javax.imageio.ImageIO;
+import javax.swing.JSpinner;
+import javax.swing.SpinnerNumberModel;
+import javax.swing.event.ChangeEvent;
+import javax.swing.event.ChangeListener;
+
+import aufgaben.Aufgabe;
+import misc.Utils;
+
+public class Zusatz1 extends Aufgabe {
+
+ private final int width = 110, height = 200;
+ private boolean done = false;
+ private String name;
+ private JSpinner[] spinners;
+
+ public Zusatz1() {
+ name = "RGB Int Umwandlung";
+ this.setSize(width, height);
+ this.setTitle(name);
+ this.addWindowListener(
+ new WindowAdapter() {
+ @Override
+ public void windowClosing(WindowEvent e) {
+ System.out.println("close");
+ done = true;
+ }
+ }
+ );
+ this.setLayout(null);
+ }
+
+ @Override
+ public boolean done() {
+ return done;
+ }
+
+ @Override
+ public String getName() {
+ return name;
+ }
+
+ @Override
+ public void init() {
+ spinners = new JSpinner[4];
+ spinners[0] = new JSpinner(new SpinnerNumberModel(0, 0, 16777215, 1));
+ spinners[0].setBounds(10, 50, 100, 20);
+ spinners[1] = new JSpinner(new SpinnerNumberModel(0, 0, 255, 1));
+ spinners[1].setBounds(10, 80, 100, 20);
+ spinners[2] = new JSpinner(new SpinnerNumberModel(0, 0, 255, 1));
+ spinners[2].setBounds(10, 110, 100, 20);
+ spinners[3] = new JSpinner(new SpinnerNumberModel(0, 0, 255, 1));
+ spinners[3].setBounds(10, 140, 100, 20);
+ for(int i = 0; i<spinners.length; i++) {
+ spinners[i].addChangeListener(new ChangeListener() {
+ public void stateChanged(ChangeEvent e) {
+ if(e.getSource().equals(spinners[0])) {
+ spinners[1].setValue((int)((int)spinners[0].getValue() & 0xFF));
+ spinners[2].setValue((int)(((int)spinners[0].getValue() >> 8) & 0xFF));
+ spinners[3].setValue((int)(((int)spinners[0].getValue() >> 16) & 0xFF));
+ } else if(e.getSource().equals(spinners[1])) {
+ spinners[0].setValue((int)spinners[1].getValue() & 0xFF | ((int)spinners[2].getValue() & 0xFF) << 8 | ((int)spinners[3].getValue() & 0xFF) << 16);
+ } else if(e.getSource().equals(spinners[2])) {
+ spinners[0].setValue((int)spinners[1].getValue() & 0xFF | ((int)spinners[2].getValue() & 0xFF) << 8 | ((int)spinners[3].getValue() & 0xFF) << 16);
+ } else if(e.getSource().equals(spinners[3])) {
+ spinners[0].setValue((int)spinners[1].getValue() & 0xFF | ((int)spinners[2].getValue() & 0xFF) << 8 | ((int)spinners[3].getValue() & 0xFF) << 16);
+ }
+ }
+ });
+ this.add(spinners[i]);
+ }
+ }
+
+}
diff --git a/src/aufgaben/b20160420/Aufgabe2.java b/src/aufgaben/b20160420/Aufgabe2.java
new file mode 100755
index 0000000..3199885
--- /dev/null
+++ b/src/aufgaben/b20160420/Aufgabe2.java
@@ -0,0 +1,76 @@
+package aufgaben.b20160420;
+
+import java.awt.Color;
+import java.awt.Graphics;
+import java.awt.event.WindowAdapter;
+import java.awt.event.WindowEvent;
+import java.awt.image.BufferedImage;
+import java.io.File;
+import java.io.IOException;
+
+import javax.imageio.ImageIO;
+
+import aufgaben.Aufgabe;
+import misc.Utils;
+
+public class Aufgabe2 extends Aufgabe {
+
+ private final int width = 500, height = 500;
+ private boolean done = false;
+ private String name;
+ private BufferedImage image;
+
+ public Aufgabe2() {
+ name = "Komische Methoden";
+ this.setSize(width, height);
+ this.setTitle(name);
+ this.addWindowListener(
+ new WindowAdapter() {
+ @Override
+ public void windowClosing(WindowEvent e) {
+ System.out.println("close");
+ done = true;
+ }
+ }
+ );
+ }
+
+ @Override
+ public boolean done() {
+ return done;
+ }
+
+ public void paint(Graphics g) {
+ if(image != null)
+ g.drawImage(image, 50, 50, 500, 300, this);
+ }
+
+ @Override
+ public String getName() {
+ return name;
+ }
+
+ @Override
+ public void init() {
+ try {
+ image = ImageIO.read(new File("title.png"));
+ } catch (IOException e) {
+ e.printStackTrace();
+ }
+ }
+
+ private int getGrayValueImg(int x, int y) {
+ if(image == null) return -1;
+ Color c = new Color(image.getRGB(x, y));
+ if(c.getRed() == c.getGreen() && c.getRed() == c.getBlue())
+ return c.getRed();
+ return -1;
+ }
+
+ private void setGrayValueImgProc(int x, int y, int gray) {
+ if(image == null)
+ System.out.println("err");
+ image.setRGB(x, y, new Color(gray, gray, gray).getRGB());
+ }
+
+}
diff --git a/src/aufgaben/b20160425/Aufgabe1.java b/src/aufgaben/b20160425/Aufgabe1.java
new file mode 100755
index 0000000..9f90600
--- /dev/null
+++ b/src/aufgaben/b20160425/Aufgabe1.java
@@ -0,0 +1,73 @@
+package aufgaben.b20160425;
+
+import java.awt.Color;
+import java.awt.Graphics;
+import java.awt.event.WindowAdapter;
+import java.awt.event.WindowEvent;
+import java.awt.image.BufferedImage;
+import java.io.File;
+import java.io.IOException;
+
+import javax.imageio.ImageIO;
+
+import aufgaben.Aufgabe;
+import misc.Utils;
+
+public class Aufgabe1 extends Aufgabe {
+
+ private final int width = 500, height = 500;
+ private boolean done = false;
+ private String name;
+ private BufferedImage image, todraw;
+ private Color[][] pixels;
+
+ public Aufgabe1() {
+ name = "Spiegelung";
+ this.setSize(width, height);
+ this.setTitle(name);
+ this.addWindowListener(
+ new WindowAdapter() {
+ @Override
+ public void windowClosing(WindowEvent e) {
+ System.out.println("close");
+ done = true;
+ }
+ }
+ );
+ }
+
+ @Override
+ public boolean done() {
+ return done;
+ }
+
+ public void paint(Graphics g) {
+ if(image != null)
+ g.drawImage(todraw, 0, 100, 500, 300, this);
+ }
+
+ @Override
+ public String getName() {
+ return name;
+ }
+
+ @Override
+ public void init() {
+ System.out.println("test");
+ pixels = new Color[width][height];
+ try {
+ image = ImageIO.read(new File("kraehne2.jpg"));
+ todraw = ImageIO.read(new File("kraehne2.jpg"));
+ for(int x = image.getWidth()-1, width = image.getWidth(); x>0; x--) {
+ for(int y = 0, height = image.getHeight(); y<height; y++) {
+ Color c = new Color(image.getRGB(x, y));
+ int h = (int)(((double)(c.getRed()+c.getGreen()+c.getBlue())/765)*255);
+ todraw.setRGB(image.getWidth()-x-1, y, new Color(h, h, h).getRGB());
+ }
+ }
+ } catch (IOException e) {
+ e.printStackTrace();
+ }
+ }
+
+}
diff --git a/src/aufgaben/b20160425/Aufgabe2.java b/src/aufgaben/b20160425/Aufgabe2.java
new file mode 100755
index 0000000..5ab54a7
--- /dev/null
+++ b/src/aufgaben/b20160425/Aufgabe2.java
@@ -0,0 +1,82 @@
+package aufgaben.b20160425;
+
+import java.awt.Color;
+import java.awt.Graphics;
+import java.awt.event.WindowAdapter;
+import java.awt.event.WindowEvent;
+import java.awt.image.BufferedImage;
+import java.io.File;
+import java.io.IOException;
+
+import javax.imageio.ImageIO;
+
+import aufgaben.Aufgabe;
+import misc.Utils;
+
+public class Aufgabe2 extends Aufgabe {
+
+ private final int width = 1000, height = 500;
+ private boolean done = false;
+ private String name;
+ private BufferedImage source, vertical, horizontal, both;
+ private Color[][] pixels;
+
+ public Aufgabe2() {
+ name = "Spiegelung 2";
+ this.setSize(width, height);
+ this.setTitle(name);
+ this.addWindowListener(
+ new WindowAdapter() {
+ @Override
+ public void windowClosing(WindowEvent e) {
+ System.out.println("close");
+ done = true;
+ }
+ }
+ );
+ }
+
+ @Override
+ public boolean done() {
+ return done;
+ }
+
+ public void paint(Graphics g) {
+ if(source != null)
+ g.drawImage(source, 0, 0, 500, 500, this);
+ if(vertical != null)
+ g.drawImage(vertical, 500, 0, 250, 250, this);
+ if(horizontal != null)
+ g.drawImage(horizontal, 750, 0, 250, 250, this);
+ if(both != null)
+ g.drawImage(both, 500, 250, 250, 250, this);
+ }
+
+ @Override
+ public String getName() {
+ return name;
+ }
+
+ @Override
+ public void init() {
+ pixels = new Color[width][height];
+ try {
+ source = ImageIO.read(new File("kraehne2.jpg"));
+ vertical = ImageIO.read(new File("kraehne2.jpg"));
+ horizontal = ImageIO.read(new File("kraehne2.jpg"));
+ both = ImageIO.read(new File("kraehne2.jpg"));
+ for(int x = 0, width = source.getWidth(); x<width; x++) {
+ for(int y = 0, height = source.getHeight(); y<height; y++) {
+ Color c = new Color(source.getRGB(x, y));
+ int h = (int)(((double)(c.getRed()+c.getGreen()+c.getBlue())/765)*255);
+ vertical.setRGB(source.getWidth()-x-1, y, new Color(h, h, h).getRGB());
+ horizontal.setRGB(x, source.getHeight()-1-y, new Color(h, h, h).getRGB());
+ both.setRGB(source.getWidth()-x-1, source.getHeight()-1-y, new Color(h, h, h).getRGB());
+ }
+ }
+ } catch (IOException e) {
+ e.printStackTrace();
+ }
+ }
+
+}
diff --git a/src/aufgaben/b20160425/Aufgabe3.java b/src/aufgaben/b20160425/Aufgabe3.java
new file mode 100755
index 0000000..2a2b242
--- /dev/null
+++ b/src/aufgaben/b20160425/Aufgabe3.java
@@ -0,0 +1,121 @@
+package aufgaben.b20160425;
+
+import java.awt.Color;
+import java.awt.Graphics;
+import java.awt.event.WindowAdapter;
+import java.awt.event.WindowEvent;
+import java.awt.image.BufferedImage;
+import java.io.File;
+import java.io.IOException;
+
+import javax.imageio.ImageIO;
+import javax.swing.JPanel;
+import javax.swing.JSpinner;
+import javax.swing.SpinnerNumberModel;
+import javax.swing.event.ChangeEvent;
+import javax.swing.event.ChangeListener;
+
+import aufgaben.Aufgabe;
+import misc.Utils;
+
+public class Aufgabe3 extends Aufgabe {
+
+ private final int width = 500, height = 500;
+ private boolean done = false;
+ private String name;
+ private BufferedImage image, todraw;
+ private JPanel panel;
+ private JSpinner spinner;
+
+ public Aufgabe3() {
+ name = "Interpolation";
+ this.setSize(width, height);
+ this.setTitle(name);
+ this.addWindowListener(
+ new WindowAdapter() {
+ @Override
+ public void windowClosing(WindowEvent e) {
+ System.out.println("close");
+ done = true;
+ }
+ }
+ );
+ this.setLayout(null);
+ }
+
+ @Override
+ public boolean done() {
+ return done;
+ }
+
+ @Override
+ public String getName() {
+ return name;
+ }
+
+ @Override
+ public void init() {
+ panel = new JPanel(){
+ public void paint(Graphics g) {
+ if(todraw != null)
+ g.drawImage(todraw, 0, 0, this.getWidth(), this.getHeight(), this);
+ }
+ };
+ panel.setBounds(0, 100, width, height-100);
+ spinner = new JSpinner(new SpinnerNumberModel(0, 0, 100, 1));
+ spinner.setBounds(100, 50, 100, 20);
+ spinner.addChangeListener(new ChangeListener() {
+ public void stateChanged(ChangeEvent e) {
+ for(int x = 0; x<image.getWidth(); x++) {
+ for(int y = 0; y<image.getHeight(); y++) {
+ todraw.setRGB(x, y, getDurchschnitt(image, x, y, (int)spinner.getValue()).getRGB());
+ }
+ }
+ panel.repaint();
+ }
+ });
+ try {
+ image = ImageIO.read(new File("title.png"));
+ todraw = ImageIO.read(new File("title.png"));
+ } catch (IOException e) {
+ e.printStackTrace();
+ }
+ this.add(panel);
+ this.add(spinner);
+ }
+
+ private int getGrayValueImg(int x, int y) {
+ if(image == null) return -1;
+ Color c = new Color(image.getRGB(x, y));
+ if(c.getRed() == c.getGreen() && c.getRed() == c.getBlue())
+ return c.getRed();
+ return -1;
+ }
+
+ private void setGrayValueImgProc(int x, int y, int gray) {
+ if(image == null)
+ System.out.println("err");
+ image.setRGB(x, y, new Color(gray, gray, gray).getRGB());
+ }
+
+ private Color getDurchschnitt(BufferedImage image, int x, int y, int r) {
+ Color color;
+ int[] colori = new int[3];
+ int absoluteX = 0, absoluteY = 0, c = 0;
+ for(int x1 = (-1)*r; x1<=r; x1++) {
+ for(int y1 = (-1)*r; y1<=r; y1++) {
+ absoluteX = x+x1;
+ absoluteY = y+y1;
+ if(absoluteX >= 0 && absoluteX < image.getWidth() && absoluteY >= 0 && absoluteY < image.getHeight()) {
+ color = new Color(image.getRGB(absoluteX, absoluteY));
+ colori[0] += color.getRed();
+ colori[1] += color.getGreen();
+ colori[2] += color.getBlue();
+ c++;
+ }
+ }
+ }
+ return new Color(colori[0]/c, colori[1]/c, colori[2]/c);
+ }
+
+}
diff --git a/src/aufgaben/b20160604/Aufgabe1.java b/src/aufgaben/b20160604/Aufgabe1.java
new file mode 100755
index 0000000..9574334
--- /dev/null
+++ b/src/aufgaben/b20160604/Aufgabe1.java
@@ -0,0 +1,109 @@
+package aufgaben.b20160604;
+
+import java.awt.Color;
+import java.awt.Graphics;
+import java.awt.event.WindowAdapter;
+import java.awt.event.WindowEvent;
+
+import function.Display;
+import function.Grade1;
+import function.Grade2;
+import function.Sin;
+import function.SquareRoot;
+import misc.Utils;
+import aufgaben.Aufgabe;
+import aufgaben.blatt2.Objekt;
+
+public class Aufgabe1 extends Aufgabe implements Runnable {
+
+ private final int width = 500, height = 500;
+ private volatile boolean done;
+ private String name;
+ private Display wasser, boot, segel;
+ private Display[] regenbogen;
+
+ public Aufgabe1() {
+ name = "BV 2 - Aufgabe 1";
+ done = false;
+ this.setSize(width, height);
+ this.setTitle(name);
+ this.addWindowListener(
+ new WindowAdapter() {
+ @Override
+ public void windowClosing(WindowEvent e) {
+ System.out.println("close");
+ done = true;
+ }
+ }
+ );
+ }
+
+ @Override
+ public boolean done() {
+ return done;
+ }
+
+ public void paint(Graphics g) {
+ wasser.draw(g);
+ boot.draw(g);
+ g.drawLine(250, 385, 350, 385);
+ g.drawLine(350, 385, 350, 415);
+ g.drawLine(300, 385, 300, 300);
+ segel.draw(g);
+ g.drawLine(300, 385, 330, 370);
+ g.drawOval(450, 0, 100, 100);
+ g.drawLine(400, 50, 450, 50);
+ g.drawLine(400, 60, 450, 60);
+ //ziel1 bei 475, 75
+ g.drawLine(419, 100, 457, 75);
+ g.drawLine(426, 110, 464, 85);
+ for(int i = 0; i<regenbogen.length/5; i++) {
+ g.setColor(new Color(255, i*10, 0));
+ regenbogen[i].draw(g);
+ }
+ for(int i = 0; i<regenbogen.length/5; i++) {
+ g.setColor(new Color(255-(i*10), 255, 0));
+ regenbogen[(regenbogen.length/5)+i].draw(g);
+ }
+ for(int i = 0; i<regenbogen.length/5; i++) {
+ g.setColor(new Color(0, 255, i*10));
+ regenbogen[((regenbogen.length/5)*2)+i].draw(g);
+ }
+ for(int i = 0; i<regenbogen.length/5; i++) {
+ g.setColor(new Color(0, 255-(i*10), 255));
+ regenbogen[((regenbogen.length/5)*3)+i].draw(g);
+ }
+ for(int i = 0; i<regenbogen.length/5; i++) {
+ g.setColor(new Color(i*10, 0, 255));
+ regenbogen[((regenbogen.length/5)*4)+i].draw(g);
+ }
+ }
+
+ @Override
+ public String getName() {
+ return name;
+ }
+
+ public void init() {
+ wasser = new Display(0, 400, 500, 10, 0, 7, -1, 1);
+ wasser.addFunction(new Sin(1, 10, 0, 0));
+ boot = new Display(250, 375, 100, 100, 0, 10, 0, 10);
+ boot.addFunction(new SquareRoot(1, 1, 0));
+ segel = new Display(300, 300, 100, 70, 0, 10, 0, 10);
+ segel.addFunction(new Grade2(1, 0, 0));
+ regenbogen = new Display[125];
+ for(int i = 0; i<regenbogen.length; i++) {
+ regenbogen[i] = new Display(0, 100+i, 500, 100, 0, 10, 0, 10);
+ regenbogen[i].addFunction(new Grade2(0.4, -4.0, 10.0));
+ }
+ new Thread(this).start();
+ }
+
+ @Override
+ public void run() {
+ while(!done);
+ done = false;
+ this.setVisible(false);
+ }
+
+}
diff --git a/src/aufgaben/b20160604/Aufgabe2.java b/src/aufgaben/b20160604/Aufgabe2.java
new file mode 100755
index 0000000..1527727
--- /dev/null
+++ b/src/aufgaben/b20160604/Aufgabe2.java
@@ -0,0 +1,63 @@
+package aufgaben.b20160604;
+
+import java.awt.Color;
+import java.awt.Graphics;
+import java.awt.event.WindowAdapter;
+import java.awt.event.WindowEvent;
+
+import function.Display;
+import function.Grade1;
+import function.Grade2;
+import function.Sin;
+import function.SquareRoot;
+import misc.Utils;
+import aufgaben.Aufgabe;
+
+public class Aufgabe2 extends Aufgabe {
+
+ private final int width = 500, height = 500;
+ private boolean done;
+ private String name;
+
+ public Aufgabe2() {
+ name = "BV 2 - Aufgabe 2";
+ done = false;
+ this.setSize(width, height);
+ this.setTitle(name);
+ this.addWindowListener(
+ new WindowAdapter() {
+ @Override
+ public void windowClosing(WindowEvent e) {
+ System.out.println("close");
+ done = true;
+ }
+ }
+ );
+
+ }
+
+ @Override
+ public boolean done() {
+ return done;
+ }
+
+ public void paint(Graphics g) {
+ for(int i = 0; i<255; i++) {
+ g.setColor(new Color(255-i, 0, i));
+ g.drawLine(100+i, 100, 100+i, 355);
+ }
+ g.setColor(new Color(0,0,0));
+ g.drawRect(100, 100, 255, 255);
+ }
+
+ @Override
+ public String getName() {
+ return name;
+ }
+
+ @Override
+ public void init() {
+
+ }
+
+}
diff --git a/src/aufgaben/b20160604/Aufgabe3.java b/src/aufgaben/b20160604/Aufgabe3.java
new file mode 100755
index 0000000..0b5212a
--- /dev/null
+++ b/src/aufgaben/b20160604/Aufgabe3.java
@@ -0,0 +1,67 @@
+package aufgaben.b20160604;
+
+import java.awt.Color;
+import java.awt.Graphics;
+import java.awt.event.WindowAdapter;
+import java.awt.event.WindowEvent;
+
+import function.Display;
+import function.Grade1;
+import function.Grade2;
+import function.Sin;
+import function.SquareRoot;
+import misc.Utils;
+import aufgaben.Aufgabe;
+
+public class Aufgabe3 extends Aufgabe {
+
+ private final int width = 700, height = 500;
+ private boolean done;
+ private String name;
+
+ public Aufgabe3() {
+ name = "BV 2 - Aufgabe 3";
+ done = false;
+ this.setSize(width, height);
+ this.setTitle(name);
+ this.addWindowListener(
+ new WindowAdapter() {
+ @Override
+ public void windowClosing(WindowEvent e) {
+ System.out.println("close");
+ done = true;
+ }
+ }
+ );
+
+ }
+
+ @Override
+ public boolean done() {
+ return done;
+ }
+
+ public void paint(Graphics g) {
+ for(int i = 0; i<255; i++) {
+ g.setColor(new Color(255-i, 0, i));
+ g.drawLine(100+i, 100, 100+i, 355);
+ }
+ for(int i = 0; i<255; i++) {
+ g.setColor(new Color(0, i, 255-i));
+ g.drawLine(355+i, 100, 355+i, 355);
+ }
+ g.setColor(new Color(0,0,0));
+ g.drawRect(100, 100, 510, 255);
+ }
+
+ @Override
+ public String getName() {
+ return name;
+ }
+
+ @Override
+ public void init() {
+
+ }
+
+}
diff --git a/src/aufgaben/b20160604/Aufgabe4.java b/src/aufgaben/b20160604/Aufgabe4.java
new file mode 100755
index 0000000..4bb8dc3
--- /dev/null
+++ b/src/aufgaben/b20160604/Aufgabe4.java
@@ -0,0 +1,79 @@
+package aufgaben.b20160604;
+
+import java.awt.Color;
+import java.awt.Graphics;
+import java.awt.event.WindowAdapter;
+import java.awt.event.WindowEvent;
+
+import function.Display;
+import function.Grade1;
+import function.Grade2;
+import function.Sin;
+import function.SquareRoot;
+import misc.Utils;
+import aufgaben.Aufgabe;
+
+public class Aufgabe4 extends Aufgabe {
+
+ private final int width = 1475, height = 500;
+ private boolean done;
+ private String name;
+
+ public Aufgabe4() {
+ name = "BV 2 - Aufgabe 4";
+ done = false;
+ this.setSize(width, height);
+ this.setTitle(name);
+ this.addWindowListener(
+ new WindowAdapter() {
+ @Override
+ public void windowClosing(WindowEvent e) {
+ System.out.println("close");
+ done = true;
+ }
+ }
+ );
+
+ }
+
+ @Override
+ public boolean done() {
+ return done;
+ }
+
+ public void paint(Graphics g) {
+ for(int i = 0; i<255; i++) {
+ g.setColor(new Color(255, i, 0));
+ g.drawLine(100+i, 100, 100+i, 355);
+ }
+ for(int i = 0; i<255; i++) {
+ g.setColor(new Color(255-i, 255, 0));
+ g.drawLine(355+i, 100, 355+i, 355);
+ }
+ for(int i = 0; i<255; i++) {
+ g.setColor(new Color(0, 255, i));
+ g.drawLine(610+i, 100, 610+i, 355);
+ }
+ for(int i = 0; i<255; i++) {
+ g.setColor(new Color(0, 255-i, 255));
+ g.drawLine(865+i, 100, 865+i, 355);
+ }
+ for(int i = 0; i<255; i++) {
+ g.setColor(new Color(i, 0, 255));
+ g.drawLine(1120+i, 100, 1120+i, 355);
+ }
+ g.setColor(new Color(0,0,0));
+ g.drawRect(100, 100, 1275, 255);
+ }
+
+ @Override
+ public String getName() {
+ return name;
+ }
+
+ @Override
+ public void init() {
+
+ }
+
+}
diff --git a/src/aufgaben/bildverarbeitung/Aufgabe1.java b/src/aufgaben/bildverarbeitung/Aufgabe1.java
new file mode 100755
index 0000000..1c89612
--- /dev/null
+++ b/src/aufgaben/bildverarbeitung/Aufgabe1.java
@@ -0,0 +1,72 @@
+package aufgaben.bildverarbeitung;
+
+import java.awt.Color;
+import java.awt.Graphics;
+import java.awt.event.WindowAdapter;
+import java.awt.event.WindowEvent;
+
+import misc.Utils;
+import aufgaben.Aufgabe;
+
+public class Aufgabe1 extends Aufgabe {
+
+ private final int width = 500, height = 500;
+ private boolean done;
+ private String name;
+
+ public Aufgabe1() {
+ name = "BV 1 - Aufgabe 1";
+ done = false;
+ this.setSize(width, height);
+ this.setTitle("Blatt 1 - Aufgabe 1");
+ this.addWindowListener(
+ new WindowAdapter() {
+ @Override
+ public void windowClosing(WindowEvent e) {
+ System.out.println("close");
+ done = true;
+ }
+ }
+ );
+ }
+
+ @Override
+ public boolean done() {
+ return false;
+ }
+
+ public void paint(Graphics g) {
+ System.out.println((int)(255*Math.random()) + " " + (int)(255*Math.random()) + " " + (int)(255*Math.random()));
+ g.setColor(new Color((int)(255*Math.random()), (int)(255*Math.random()), (int)(255*Math.random())));
+ g.drawArc(100, 100, 100, 100, 0, 360);
+ g.drawLine(150, 200, 150, 300);
+ g.drawLine(150, 300, 100, 400);
+ g.drawLine(150, 300, 200, 400);
+ g.drawLine(150, 250, 250, 150);
+ g.drawLine(150, 250, 50, 150);
+ }
+
+ @Override
+ public String getName() {
+ return name;
+ }
+
+ @Override
+ public void init() {
+ new Thread(new Runnable(){
+ @Override
+ public void run() {
+ while(true) {
+ try {
+ Thread.sleep(1000);
+ } catch (InterruptedException e) {
+ // TODO Auto-generated catch block
+ e.printStackTrace();
+ }
+ repaint();
+ }
+ }
+ }).start();
+ }
+
+}
diff --git a/src/aufgaben/bildverarbeitung/Aufgabe3.java b/src/aufgaben/bildverarbeitung/Aufgabe3.java
new file mode 100755
index 0000000..612407d
--- /dev/null
+++ b/src/aufgaben/bildverarbeitung/Aufgabe3.java
@@ -0,0 +1,59 @@
+package aufgaben.bildverarbeitung;
+
+import java.awt.Color;
+import java.awt.Graphics;
+import java.awt.event.WindowAdapter;
+import java.awt.event.WindowEvent;
+
+import misc.Utils;
+import aufgaben.Aufgabe;
+
+public class Aufgabe3 extends Aufgabe {
+
+ private final int width = 500, height = 500;
+ private boolean done;
+ private String name;
+
+ public Aufgabe3() {
+ name = "BV 1 - Aufgabe 3";
+ done = false;
+ this.setSize(width, height);
+ this.setTitle("Blatt 1 - Aufgabe 1");
+ this.addWindowListener(
+ new WindowAdapter() {
+ @Override
+ public void windowClosing(WindowEvent e) {
+ System.out.println("close");
+ done = true;
+ }
+ }
+ );
+ }
+
+ @Override
+ public boolean done() {
+ return false;
+ }
+
+ public void paint(Graphics g) {
+ for(int i = 0; i<10; i++) {
+ for(int x = 0; x<20; x++) {
+ g.setColor(new Color((int)(255*Math.random()), (int)(255*Math.random()), (int)(255*Math.random())));
+ g.fillRect(x*10, i*10, 10, 10);
+ g.setColor(new Color(0,0,0));
+ g.drawRect(x*10, i*10, 10, 10);
+ }
+ }
+ }
+
+ @Override
+ public String getName() {
+ return name;
+ }
+
+ @Override
+ public void init() {
+
+ }
+
+}
diff --git a/src/aufgaben/blatt1/Aufgabe1.java b/src/aufgaben/blatt1/Aufgabe1.java
new file mode 100755
index 0000000..dbd29a6
--- /dev/null
+++ b/src/aufgaben/blatt1/Aufgabe1.java
@@ -0,0 +1,58 @@
+package aufgaben.blatt1;
+
+import java.awt.Color;
+import java.awt.Graphics;
+import java.awt.event.WindowAdapter;
+import java.awt.event.WindowEvent;
+
+import aufgaben.Aufgabe;
+import misc.Utils;
+
+public class Aufgabe1 extends Aufgabe {
+
+ private final int width = 500, height = 500;
+ private boolean done = false;
+ private String name;
+
+ public Aufgabe1() {
+ name = "Blatt 1 - Aufgabe 1";
+ this.setSize(width, height);
+ this.setTitle("Blatt 1 - Aufgabe 1");
+ this.addWindowListener(
+ new WindowAdapter() {
+ @Override
+ public void windowClosing(WindowEvent e) {
+ System.out.println("close");
+ done = true;
+ }
+ }
+ );
+ }
+
+ @Override
+ public boolean done() {
+ return done;
+ }
+
+ public void paint(Graphics g) {
+ int x, y;
+ for(int i = 0; i<40; i++) {
+ x = Utils.randomInt(0, width);
+ y = Utils.randomInt(0, height);
+ g.drawRect(x, y, Utils.randomInt(0, width-x), Utils.randomInt(0, height-y));
+ g.setColor(new Color(Utils.randomInt(0, 255), Utils.randomInt(0, 255), Utils.randomInt(0, 255)));
+ }
+ }
+
+ @Override
+ public String getName() {
+ return name;
+ }
+
+ @Override
+ public void init() {
+ // TODO Auto-generated method stub
+
+ }
+
+}
diff --git a/src/aufgaben/blatt1/Aufgabe2a.java b/src/aufgaben/blatt1/Aufgabe2a.java
new file mode 100755
index 0000000..ced5ee8
--- /dev/null
+++ b/src/aufgaben/blatt1/Aufgabe2a.java
@@ -0,0 +1,58 @@
+package aufgaben.blatt1;
+
+import java.awt.Color;
+import java.awt.Graphics;
+import java.awt.event.WindowAdapter;
+import java.awt.event.WindowEvent;
+
+import aufgaben.Aufgabe;
+import misc.Utils;
+
+public class Aufgabe2a extends Aufgabe {
+
+ private final int width = 500, height = 500;
+ private boolean done = false;
+ private String name;
+
+ public Aufgabe2a() {
+ name = "Blatt 1 - 2a";
+ this.setSize(width, height);
+ this.setTitle("Blatt 1 - Aufgabe 2a");
+ this.addWindowListener(
+ new WindowAdapter() {
+ @Override
+ public void windowClosing(WindowEvent e) {
+ System.out.println("close");
+ done = true;
+ }
+ }
+ );
+ }
+
+ @Override
+ public boolean done() {
+ return done;
+ }
+
+ public void paint(Graphics g) {
+ int x, y;
+ for(int i = 0; i<40; i++) {
+ x = Utils.randomInt(0, width);
+ y = Utils.randomInt(0, height);
+ g.fillArc(x, y, Utils.randomInt(0, width-x), Utils.randomInt(0, height-y), Utils.randomInt(0, 360), Utils.randomInt(0, 360));
+ g.setColor(new Color(Utils.randomInt(0, 255), Utils.randomInt(0, 255), Utils.randomInt(0, 255)));
+ }
+ }
+
+ @Override
+ public String getName() {
+ return name;
+ }
+
+ @Override
+ public void init() {
+ // TODO Auto-generated method stub
+
+ }
+
+}
diff --git a/src/aufgaben/blatt1/Aufgabe2b40.java b/src/aufgaben/blatt1/Aufgabe2b40.java
new file mode 100755
index 0000000..55e9f57
--- /dev/null
+++ b/src/aufgaben/blatt1/Aufgabe2b40.java
@@ -0,0 +1,97 @@
+package aufgaben.blatt1;
+
+import java.awt.Color;
+import java.awt.Graphics;
+import java.awt.Polygon;
+import java.awt.event.WindowAdapter;
+import java.awt.event.WindowEvent;
+
+import aufgaben.Aufgabe;
+import misc.Utils;
+
+public class Aufgabe2b40 extends Aufgabe {
+
+ private final int width = 500, height = 500;
+ private boolean done = false;
+ private String name;
+
+ public Aufgabe2b40() {
+ name = "Blatt 1 - 2b40";
+ this.setSize(width, height);
+ this.setTitle("Blatt 1 - Aufgabe 2b - 40 Objekte");
+ this.addWindowListener(
+ new WindowAdapter() {
+ @Override
+ public void windowClosing(WindowEvent e) {
+ System.out.println("close");
+ done = true;
+ }
+ }
+ );
+ }
+
+ @Override
+ public boolean done() {
+ return done;
+ }
+
+ public void paint(Graphics g) {
+ int x, y;
+ for(int i = 0; i<40; i++) {
+ x = Utils.randomInt(0, width);
+ y = Utils.randomInt(0, height);
+ switch(Utils.randomInt(0, 8)) {
+ case 0:
+ g.drawRect(x, y, Utils.randomInt(0, width-x), Utils.randomInt(0, height-y));
+ break;
+ case 1:
+ g.fillRect(x, y, Utils.randomInt(0, width-x), Utils.randomInt(0, height-y));
+ break;
+ case 2:
+ g.drawArc(x, y, Utils.randomInt(0, width-x), Utils.randomInt(0, height-y), Utils.randomInt(0, 360), Utils.randomInt(0, 360));
+ break;
+ case 3:
+ g.fillArc(x, y, Utils.randomInt(0, width-x), Utils.randomInt(0, height-y), Utils.randomInt(0, 360), Utils.randomInt(0, 360));
+ break;
+ case 4:
+ g.drawOval(x, y, Utils.randomInt(0, width-x), Utils.randomInt(0, height-y));
+ break;
+ case 5:
+ g.fillOval(x, y, Utils.randomInt(0, width-x), Utils.randomInt(0, height-y));
+ break;
+ case 6:
+ g.drawPolygon(getPolygon());
+ break;
+ case 7:
+ g.fillPolygon(getPolygon());
+ break;
+ case 8:
+ g.drawLine(Utils.randomInt(0, width), Utils.randomInt(0, height), Utils.randomInt(0, width), Utils.randomInt(0, height));
+ break;
+ }
+ g.setColor(new Color(Utils.randomInt(0, 255), Utils.randomInt(0, 255), Utils.randomInt(0, 255)));
+ }
+ }
+
+ private Polygon getPolygon() {
+ int bla = Utils.randomInt(1, 100);
+ int[] x = new int[bla], y = new int[bla];
+ for(int i = 0; i<bla; i++) {
+ x[i] = Utils.randomInt(0, width);
+ y[i] = Utils.randomInt(0, height);
+ }
+ return new Polygon(x, y, bla);
+ }
+
+ @Override
+ public String getName() {
+ return name;
+ }
+
+ @Override
+ public void init() {
+ // TODO Auto-generated method stub
+
+ }
+
+}
diff --git a/src/aufgaben/blatt1/Aufgabe2bEPIC.java b/src/aufgaben/blatt1/Aufgabe2bEPIC.java
new file mode 100755
index 0000000..aa8596a
--- /dev/null
+++ b/src/aufgaben/blatt1/Aufgabe2bEPIC.java
@@ -0,0 +1,97 @@
+package aufgaben.blatt1;
+
+import java.awt.Color;
+import java.awt.Graphics;
+import java.awt.Polygon;
+import java.awt.event.WindowAdapter;
+import java.awt.event.WindowEvent;
+
+import aufgaben.Aufgabe;
+import misc.Utils;
+
+public class Aufgabe2bEPIC extends Aufgabe {
+
+ private final int width = 1920, height = 1080;
+ private boolean done = false;
+ private String name;
+
+ public Aufgabe2bEPIC() {
+ name = "Blatt 1 - 2bEPIC";
+ this.setSize(width, height);
+ this.setTitle("Blatt 1 - Aufgabe 2b - Unendlich Objekte");
+ this.addWindowListener(
+ new WindowAdapter() {
+ @Override
+ public void windowClosing(WindowEvent e) {
+ System.out.println("close");
+ done = true;
+ }
+ }
+ );
+ }
+
+ @Override
+ public boolean done() {
+ return done;
+ }
+
+ public void paint(Graphics g) {
+ int x, y;
+ while(true) {
+ x = Utils.randomInt(0, width);
+ y = Utils.randomInt(0, height);
+ switch(Utils.randomInt(0, 8)) {
+ case 0:
+ g.drawRect(x, y, Utils.randomInt(0, width-x), Utils.randomInt(0, height-y));
+ break;
+ case 1:
+ g.fillRect(x, y, Utils.randomInt(0, width-x), Utils.randomInt(0, height-y));
+ break;
+ case 2:
+ g.drawArc(x, y, Utils.randomInt(0, width-x), Utils.randomInt(0, height-y), Utils.randomInt(0, 360), Utils.randomInt(0, 360));
+ break;
+ case 3:
+ g.fillArc(x, y, Utils.randomInt(0, width-x), Utils.randomInt(0, height-y), Utils.randomInt(0, 360), Utils.randomInt(0, 360));
+ break;
+ case 4:
+ g.drawOval(x, y, Utils.randomInt(0, width-x), Utils.randomInt(0, height-y));
+ break;
+ case 5:
+ g.fillOval(x, y, Utils.randomInt(0, width-x), Utils.randomInt(0, height-y));
+ break;
+ case 6:
+ g.drawPolygon(getPolygon());
+ break;
+ case 7:
+ g.fillPolygon(getPolygon());
+ break;
+ case 8:
+ g.drawLine(Utils.randomInt(0, width), Utils.randomInt(0, height), Utils.randomInt(0, width), Utils.randomInt(0, height));
+ break;
+ }
+ g.setColor(new Color(Utils.randomInt(0, 255), Utils.randomInt(0, 255), Utils.randomInt(0, 255)));
+ }
+ }
+
+ private Polygon getPolygon() {
+ int bla = Utils.randomInt(1, 100);
+ int[] x = new int[bla], y = new int[bla];
+ for(int i = 0; i<bla; i++) {
+ x[i] = Utils.randomInt(0, width);
+ y[i] = Utils.randomInt(0, height);
+ }
+ return new Polygon(x, y, bla);
+ }
+
+ @Override
+ public String getName() {
+ return name;
+ }
+
+ @Override
+ public void init() {
+ // TODO Auto-generated method stub
+
+ }
+
+}
diff --git a/src/aufgaben/blatt1/Aufgabe2c40.java b/src/aufgaben/blatt1/Aufgabe2c40.java
new file mode 100755
index 0000000..144b2ab
--- /dev/null
+++ b/src/aufgaben/blatt1/Aufgabe2c40.java
@@ -0,0 +1,58 @@
+package aufgaben.blatt1;
+
+import java.awt.Color;
+import java.awt.Graphics;
+import java.awt.event.WindowAdapter;
+import java.awt.event.WindowEvent;
+
+import aufgaben.Aufgabe;
+import misc.Utils;
+
+public class Aufgabe2c40 extends Aufgabe {
+
+ private final int width = 500, height = 500;
+ private boolean done = false;
+ private String name;
+
+ public Aufgabe2c40() {
+ name = "Blatt 1 - 2c40";
+ this.setSize(width, height);
+ this.setTitle("Blatt 1 - Aufgabe 2c - 40 Strings, alphanumerisch");
+ this.addWindowListener(
+ new WindowAdapter() {
+ @Override
+ public void windowClosing(WindowEvent e) {
+ System.out.println("close");
+ done = true;
+ }
+ }
+ );
+ }
+
+ @Override
+ public boolean done() {
+ return done;
+ }
+
+ public void paint(Graphics g) {
+ int x, y;
+ for(int i = 0; i<40; i++) {
+ x = Utils.randomInt(0, width);
+ y = Utils.randomInt(0, height);
+ g.drawString(Utils.randomStringAN(Utils.randomInt(0, 100)), x, y);
+ g.setColor(new Color(Utils.randomInt(0, 255), Utils.randomInt(0, 255), Utils.randomInt(0, 255)));
+ }
+ }
+
+ @Override
+ public String getName() {
+ return name;
+ }
+
+ @Override
+ public void init() {
+ // TODO Auto-generated method stub
+
+ }
+
+}
diff --git a/src/aufgaben/blatt1/Aufgabe2c40UTF8.java b/src/aufgaben/blatt1/Aufgabe2c40UTF8.java
new file mode 100755
index 0000000..598ed86
--- /dev/null
+++ b/src/aufgaben/blatt1/Aufgabe2c40UTF8.java
@@ -0,0 +1,58 @@
+package aufgaben.blatt1;
+
+import java.awt.Color;
+import java.awt.Graphics;
+import java.awt.event.WindowAdapter;
+import java.awt.event.WindowEvent;
+
+import aufgaben.Aufgabe;
+import misc.Utils;
+
+public class Aufgabe2c40UTF8 extends Aufgabe {
+
+ private final int width = 500, height = 500;
+ private boolean done = false;
+ private String name;
+
+ public Aufgabe2c40UTF8() {
+ name = "Blatt 1 - 2c40UTF8";
+ this.setSize(width, height);
+ this.setTitle("Blatt 1 - Aufgabe 2c - 40 Strings, UTF8");
+ this.addWindowListener(
+ new WindowAdapter() {
+ @Override
+ public void windowClosing(WindowEvent e) {
+ System.out.println("close");
+ done = true;
+ }
+ }
+ );
+ }
+
+ @Override
+ public boolean done() {
+ return done;
+ }
+
+ public void paint(Graphics g) {
+ int x, y;
+ for(int i = 0; i<40; i++) {
+ x = Utils.randomInt(0, width);
+ y = Utils.randomInt(0, height);
+ g.drawString(Utils.randomStringUTF8(Utils.randomInt(0, 100)), x, y);
+ g.setColor(new Color(Utils.randomInt(0, 255), Utils.randomInt(0, 255), Utils.randomInt(0, 255)));
+ }
+ }
+
+ @Override
+ public String getName() {
+ return name;
+ }
+
+ @Override
+ public void init() {
+ // TODO Auto-generated method stub
+
+ }
+
+}
diff --git a/src/aufgaben/blatt1/Aufgabe2cEPIC.java b/src/aufgaben/blatt1/Aufgabe2cEPIC.java
new file mode 100755
index 0000000..48a3f72
--- /dev/null
+++ b/src/aufgaben/blatt1/Aufgabe2cEPIC.java
@@ -0,0 +1,58 @@
+package aufgaben.blatt1;
+
+import java.awt.Color;
+import java.awt.Graphics;
+import java.awt.event.WindowAdapter;
+import java.awt.event.WindowEvent;
+
+import aufgaben.Aufgabe;
+import misc.Utils;
+
+public class Aufgabe2cEPIC extends Aufgabe {
+
+ private final int width = 500, height = 500;
+ private boolean done = false;
+ private String name;
+
+ public Aufgabe2cEPIC() {
+ name = "Blatt 1 - 2cEPIC";
+ this.setSize(width, height);
+ this.setTitle("Blatt 1 - Aufgabe 2c - Unendlich Strings, alphanumerisch");
+ this.addWindowListener(
+ new WindowAdapter() {
+ @Override
+ public void windowClosing(WindowEvent e) {
+ System.out.println("close");
+ done = true;
+ }
+ }
+ );
+ }
+
+ @Override
+ public boolean done() {
+ return done;
+ }
+
+ public void paint(Graphics g) {
+ int x, y;
+ while(true) {
+ x = Utils.randomInt(0, width);
+ y = Utils.randomInt(0, height);
+ g.drawString(Utils.randomStringAN(Utils.randomInt(0, 100)), x, y);
+ g.setColor(new Color(Utils.randomInt(0, 255), Utils.randomInt(0, 255), Utils.randomInt(0, 255)));
+ }
+ }
+
+ @Override
+ public String getName() {
+ return name;
+ }
+
+ @Override
+ public void init() {
+ // TODO Auto-generated method stub
+
+ }
+
+}
diff --git a/src/aufgaben/blatt1/Aufgabe2cEPICUTF8.java b/src/aufgaben/blatt1/Aufgabe2cEPICUTF8.java
new file mode 100755
index 0000000..b6db746
--- /dev/null
+++ b/src/aufgaben/blatt1/Aufgabe2cEPICUTF8.java
@@ -0,0 +1,58 @@
+package aufgaben.blatt1;
+
+import java.awt.Color;
+import java.awt.Graphics;
+import java.awt.event.WindowAdapter;
+import java.awt.event.WindowEvent;
+
+import aufgaben.Aufgabe;
+import misc.Utils;
+
+public class Aufgabe2cEPICUTF8 extends Aufgabe {
+
+ private final int width = 100, height = 100;
+ private boolean done = false;
+ private String name;
+
+ public Aufgabe2cEPICUTF8() {
+ name = "Blatt 1 - 2cEPICUTF8";
+ this.setSize(width, height);
+ this.setTitle("Blatt 1 - Aufgabe 2c - Unendlich Strings, UTF8");
+ this.addWindowListener(
+ new WindowAdapter() {
+ @Override
+ public void windowClosing(WindowEvent e) {
+ System.out.println("close");
+ done = true;
+ }
+ }
+ );
+ }
+
+ @Override
+ public boolean done() {
+ return done;
+ }
+
+ public void paint( Graphics g ) {
+ int x, y;
+ while(true) {
+ x = Utils.randomInt(0, width);
+ y = Utils.randomInt(0, height);
+ g.drawString(Utils.randomStringUTF8(Utils.randomInt(0, 100)), x, y);
+ g.setColor(new Color(Utils.randomInt(0, 255), Utils.randomInt(0, 255), Utils.randomInt(0, 255)));
+ }
+ }
+
+ @Override
+ public String getName() {
+ return name;
+ }
+
+ @Override
+ public void init() {
+ // TODO Auto-generated method stub
+
+ }
+
+}
diff --git a/src/aufgaben/blatt2/Aufgabe1.java b/src/aufgaben/blatt2/Aufgabe1.java
new file mode 100755
index 0000000..014b2f6
--- /dev/null
+++ b/src/aufgaben/blatt2/Aufgabe1.java
@@ -0,0 +1,64 @@
+package aufgaben.blatt2;
+
+import java.awt.Color;
+import java.awt.Graphics;
+import java.awt.event.WindowAdapter;
+import java.awt.event.WindowEvent;
+
+import aufgaben.Aufgabe;
+import misc.Utils;
+
+public class Aufgabe1 extends Aufgabe {
+
+ private final int width = 500, height = 500;
+ private boolean done = false;
+ private volatile Objekt o;
+ private String name;
+
+ public Aufgabe1() {
+ name = "Blatt 2 - 1";
+ this.setSize(width, height);
+ this.setTitle("Blatt 1 - Aufgabe 1");
+ this.addWindowListener(
+ new WindowAdapter() {
+ @Override
+ public void windowClosing(WindowEvent e) {
+ System.out.println("close");
+ done = true;
+ }
+ }
+ );
+ }
+
+ @Override
+ public boolean done() {
+ return done;
+ }
+
+ public void paint(Graphics g) {
+ g.drawRect(o.getX(), o.getY(), 100, 100);
+ g.setColor(Color.BLACK);
+ }
+
+ @Override
+ public String getName() {
+ return name;
+ }
+
+ @Override
+ public void init() {
+ o = new Objekt(20, 200);
+ o.setMovement(0, 50);
+
+ new Thread(new Runnable(){
+ @Override
+ public void run() {
+ while(true) {
+ o.update();
+ repaint();
+ }
+ }
+ }).start();
+ }
+
+}
diff --git a/src/aufgaben/blatt2/Objekt.java b/src/aufgaben/blatt2/Objekt.java
new file mode 100755
index 0000000..031b73a
--- /dev/null
+++ b/src/aufgaben/blatt2/Objekt.java
@@ -0,0 +1,65 @@
+package aufgaben.blatt2;
+
+import java.util.Date;
+
+public class Objekt {
+
+ private float x, y, dir, v;
+ private long time;
+
+ public Objekt(int x, int y) {
+ this.x = x;
+ this.y = y;
+ }
+
+ public void setX(int x) {
+ this.x = x;
+ }
+
+ public void setY(int y) {
+ this.y = y;
+ }
+
+ public void setMovement(float degrees, float v) {
+ this.dir = degrees;
+ this.v = v;
+ this.time = System.nanoTime();
+ }
+
+ public void update() {
+ long delta = getDelta();
+ float change = (float) (delta/1e9);
+ if(dir == 0 || dir == 360) {
+ x += change * v;
+ } else if(dir >= 0 && dir < 90) {
+ x += change * v;
+ y -= Math.tan(Math.toRadians(dir)) * change * v;
+ } else if(dir >= 90 && dir < 180) {
+ x -= Math.tan(Math.toRadians(dir-90)) * change * v;
+ y -= change * v;
+ } else if(dir >= 180 && dir < 270) {
+ x -= change * v;
+ y += Math.tan(Math.toRadians(dir-180)) * change * v;
+ } else if(dir >= 270 && dir < 360) {
+ x += Math.tan(Math.toRadians(dir-270)) * change * v;
+ y += change * v;
+ } else {
+ System.out.println("Invalid angle! (float, 0<=angle<=360)");
+ }
+ System.out.println("X = " + x + ", Y = " + y + ", fps = " + delta/1e9);
+ }
+
+ public int getX() {
+ return Math.round(x);
+ }
+
+ public int getY() {
+ return Math.round(y);
+ }
+
+ public long getDelta() {
+ long old = time;
+ time = System.nanoTime();
+ return time-old;
+ }
+}
diff --git a/src/aufgaben/imageio/Aufgabe1.java b/src/aufgaben/imageio/Aufgabe1.java
new file mode 100755
index 0000000..6394f80
--- /dev/null
+++ b/src/aufgaben/imageio/Aufgabe1.java
@@ -0,0 +1,193 @@
+package aufgaben.imageio;
+
+import java.awt.Color;
+import java.awt.Graphics;
+import java.awt.event.ActionEvent;
+import java.awt.event.ActionListener;
+import java.awt.event.WindowAdapter;
+import java.awt.event.WindowEvent;
+import java.awt.image.BufferedImage;
+import java.io.BufferedInputStream;
+import java.io.BufferedOutputStream;
+import java.io.BufferedReader;
+import java.io.File;
+import java.io.FileInputStream;
+import java.io.FileNotFoundException;
+import java.io.FileOutputStream;
+import java.io.FileReader;
+import java.io.IOException;
+import java.io.InputStream;
+import java.nio.ByteBuffer;
+
+import javax.imageio.ImageIO;
+import javax.swing.JButton;
+import javax.swing.JPanel;
+import javax.swing.JTextField;
+
+import aufgaben.Aufgabe;
+import misc.Utils;
+
+public class Aufgabe1 extends Aufgabe {
+
+ private final int width = 500, height = 500;
+ private boolean done = false;
+ private String name;
+ private JPanel panel;
+ private JTextField inPath, outPath;
+ private JButton readButton, writeButton;
+ private BufferedImage bild;
+
+ public Aufgabe1() {
+ name = "Lesen Speichern";
+ this.setSize(width, height);
+ this.setTitle(name);
+ this.addWindowListener(
+ new WindowAdapter() {
+ @Override
+ public void windowClosing(WindowEvent e) {
+ System.out.println("close");
+ done = true;
+ }
+ }
+ );
+ this.setLayout(null);
+ }
+
+ @Override
+ public boolean done() {
+ return done;
+ }
+
+ @Override
+ public String getName() {
+ return name;
+ }
+
+ @Override
+ public void init() {
+ inPath = new JTextField();
+ inPath.setBounds(50, 50, 200, 20);
+ outPath = new JTextField();
+ outPath.setBounds(50, 80, 200, 20);
+ readButton = new JButton("Lesen");
+ readButton.setBounds(260, 50, 100, 20);
+ readButton.addActionListener(new ActionListener() {
+ public void actionPerformed(ActionEvent arg0) {
+ bild = readImage(new File(inPath.getText()));
+ /*
+ try {
+ bild = ImageIO.read(new File("title.png"));
+ } catch (IOException e) {
+ e.printStackTrace();
+ }
+ */
+ panel.repaint();
+ }
+ });
+ writeButton = new JButton("Schreiben");
+ writeButton.setBounds(260, 80, 100, 20);
+ writeButton.addActionListener(new ActionListener() {
+ public void actionPerformed(ActionEvent arg0) {
+ writeImage(new File(outPath.getText()), bild);
+ }
+ });
+ panel = new JPanel() {
+ public void paint(Graphics g) {
+ if(bild != null)
+ g.drawImage(bild, 0, 0, 500, 390, this);
+ }
+ };
+ panel.setBounds(0, 110, 500, 390);
+ this.add(inPath);
+ this.add(outPath);
+ this.add(readButton);
+ this.add(writeButton);
+ this.add(panel);
+ this.repaint();
+ }
+
+ private BufferedImage getGreyImage(BufferedImage i) {
+ BufferedImage image = new BufferedImage(i.getWidth(), i.getHeight(), i.getType());
+ for(int x = 0, width = i.getWidth(); x<width; x++) {
+ for(int y = 0, height = i.getHeight(); y<height; y++) {
+ Color c = new Color(i.getRGB(x, y));
+ int h = (int)(((double)(c.getRed()+c.getGreen()+c.getBlue())/765)*255);
+ image.setRGB(x, y, new Color(h, h, h).getRGB());
+ }
+ }
+ return image;
+ }
+
+ private BufferedImage readImage(File file) {
+ FileInputStream fis;
+ BufferedInputStream bis;
+ try {
+ fis = new FileInputStream(file);
+ bis = new BufferedInputStream(fis);
+ byte[] b = new byte[4];
+ bis.read(b);
+ int width = byteArrayToInt(b);
+ bis.read(b);
+ int height = byteArrayToInt(b);
+ bis.read(b);
+ int type = byteArrayToInt(b);
+ BufferedImage image = new BufferedImage(width, height, type);
+ for(int x = 0; x<width; x++) {
+ for(int y = 0; y<height; y++) {
+ bis.read(b);
+ image.setRGB(x, y, byteArrayToInt(b));
+ }
+ }
+ bis.close();
+ fis.close();
+ return image;
+ } catch (FileNotFoundException e) {
+ e.printStackTrace();
+ } catch (IOException e) {
+ e.printStackTrace();
+ }
+ return null;
+ }
+
+ private void writeImage(File file, BufferedImage image) {
+ FileOutputStream fos;
+ BufferedOutputStream bos;
+ try {
+ fos = new FileOutputStream(file);
+ bos = new BufferedOutputStream(fos);
+ bos.write(intToByteArray(image.getWidth()));
+ bos.write(intToByteArray(image.getHeight()));
+ bos.write(intToByteArray(image.getType()));
+ for(int x = 0, width = image.getWidth(); x<width; x++) {
+ for(int y = 0, height = image.getHeight(); y<height; y++) {
+ bos.write(intToByteArray(image.getRGB(x, y)));
+ }
+ }
+ bos.close();
+ fos.close();
+ } catch (FileNotFoundException e) {
+ e.printStackTrace();
+ } catch (IOException e) {
+ e.printStackTrace();
+ }
+ }
+
+ public static int byteArrayToInt(byte[] b)
+ {
+ return b[3] & 0xFF |
+ (b[2] & 0xFF) << 8 |
+ (b[1] & 0xFF) << 16 |
+ (b[0] & 0xFF) << 24;
+ }
+
+ public static byte[] intToByteArray(int a)
+ {
+ return new byte[] {
+ (byte) ((a >> 24) & 0xFF),
+ (byte) ((a >> 16) & 0xFF),
+ (byte) ((a >> 8) & 0xFF),
+ (byte) (a & 0xFF)
+ };
+ }
+
+}
diff --git a/src/aufgaben/imageio/ImageType.java b/src/aufgaben/imageio/ImageType.java
new file mode 100755
index 0000000..cfecabe
--- /dev/null
+++ b/src/aufgaben/imageio/ImageType.java
@@ -0,0 +1,8 @@
+package aufgaben.imageio;
+
+public class ImageType {
+
+ public static final byte RAW = 0x00;
+ public static final byte COMPRESSED = 0x01;
+
+}
diff --git a/src/aufgaben/imageio/Komprimierung1.java b/src/aufgaben/imageio/Komprimierung1.java
new file mode 100755
index 0000000..2265560
--- /dev/null
+++ b/src/aufgaben/imageio/Komprimierung1.java
@@ -0,0 +1,225 @@
+package aufgaben.imageio;
+
+import java.awt.Color;
+import java.awt.Graphics;
+import java.awt.event.ActionEvent;
+import java.awt.event.ActionListener;
+import java.awt.event.WindowAdapter;
+import java.awt.event.WindowEvent;
+import java.awt.image.BufferedImage;
+import java.io.BufferedInputStream;
+import java.io.BufferedOutputStream;
+import java.io.BufferedReader;
+import java.io.File;
+import java.io.FileInputStream;
+import java.io.FileNotFoundException;
+import java.io.FileOutputStream;
+import java.io.FileReader;
+import java.io.IOException;
+import java.io.InputStream;
+import java.nio.ByteBuffer;
+import java.util.ArrayList;
+
+import javax.imageio.ImageIO;
+import javax.swing.JButton;
+import javax.swing.JPanel;
+import javax.swing.JSpinner;
+import javax.swing.JTextField;
+import javax.swing.SpinnerNumberModel;
+
+import aufgaben.Aufgabe;
+import misc.CompressedImage;
+import misc.Stapel;
+import misc.Utils;
+
+public class Komprimierung1 extends Aufgabe {
+
+ private final int width = 500, height = 500;
+ private boolean done = false;
+ private String name;
+ private JPanel panel;
+ private JTextField inPath, outPath;
+ private JButton readButton, writeButton, compButton;
+ private JSpinner spinnerWidth, spinnerHeight, spinnerColors;
+ private BufferedImage bild, towrite;
+ private CompressedImage compressed;
+ private ArrayList<Byte[]> compData;
+
+ public Komprimierung1() {
+ name = "Komprimierung 1";
+ this.setSize(width, height);
+ this.setTitle(name);
+ this.addWindowListener(
+ new WindowAdapter() {
+ @Override
+ public void windowClosing(WindowEvent e) {
+ System.out.println("close");
+ done = true;
+ }
+ }
+ );
+ this.setLayout(null);
+ }
+
+ @Override
+ public boolean done() {
+ return done;
+ }
+
+ @Override
+ public String getName() {
+ return name;
+ }
+
+ @Override
+ public void init() {
+ inPath = new JTextField();
+ inPath.setBounds(20, 40, 150, 20);
+ outPath = new JTextField();
+ outPath.setBounds(20, 70, 150, 20);
+ readButton = new JButton("Lesen");
+ readButton.setBounds(180, 40, 100, 20);
+ readButton.addActionListener(new ActionListener() {
+ public void actionPerformed(ActionEvent arg0) {
+ //bild = readImage(new File(inPath.getText()));
+ try {
+ bild = ImageIO.read(new File("title.png"));
+ } catch (IOException e) {
+ e.printStackTrace();
+ }
+
+ towrite = new BufferedImage(bild.getWidth(), bild.getHeight(), bild.getType());
+ for(int x = 0, width = towrite.getWidth(); x<width; x++) {
+ for(int y = 0, height = towrite.getHeight(); y<height; y++) {
+ towrite.setRGB(x, y, bild.getRGB(x, y));
+ }
+ }
+
+ panel.repaint();
+ }
+ });
+ writeButton = new JButton("Schreiben");
+ writeButton.setBounds(180, 70, 100, 20);
+ writeButton.addActionListener(new ActionListener() {
+ public void actionPerformed(ActionEvent arg0) {
+ writeImage(new File(outPath.getText()));
+ }
+ });
+ spinnerWidth = new JSpinner(new SpinnerNumberModel(32, 1, 4096, 1));
+ spinnerWidth.setBounds(290, 40, 50, 20);
+ spinnerHeight = new JSpinner(new SpinnerNumberModel(32, 1, 4096, 1));
+ spinnerHeight.setBounds(350, 40, 50, 20);
+ spinnerColors = new JSpinner(new SpinnerNumberModel(8, 1, 4096, 1));
+ spinnerColors.setBounds(410, 40, 50, 20);
+ compButton = new JButton("Komprimieren");
+ compButton.setBounds(290, 70, 120, 20);
+ compButton.addActionListener(new ActionListener() {
+ public void actionPerformed(ActionEvent arg0) {
+ compressed = new CompressedImage(bild, (int)spinnerWidth.getValue(), (int)spinnerHeight.getValue(), (int)spinnerColors.getValue());
+ towrite = compressed.getImage();
+ panel.repaint();
+ }
+ });
+
+ panel = new JPanel() {
+ public void paint(Graphics g) {
+ if(towrite != null)
+ g.drawImage(towrite, 0, 0, 500, 390, this);
+ }
+ };
+ panel.setBounds(0, 110, 500, 390);
+ this.add(inPath);
+ this.add(outPath);
+ this.add(readButton);
+ this.add(writeButton);
+ this.add(spinnerWidth);
+ this.add(spinnerHeight);
+ this.add(spinnerColors);
+ this.add(compButton);
+ this.add(panel);
+ this.repaint();
+ }
+
+ private BufferedImage getGreyImage(BufferedImage i) {
+ BufferedImage image = new BufferedImage(i.getWidth(), i.getHeight(), i.getType());
+ for(int x = 0, width = i.getWidth(); x<width; x++) {
+ for(int y = 0, height = i.getHeight(); y<height; y++) {
+ Color c = new Color(i.getRGB(x, y));
+ int h = (int)(((double)(c.getRed()+c.getGreen()+c.getBlue())/765)*255);
+ image.setRGB(x, y, new Color(h, h, h).getRGB());
+ }
+ }
+ return image;
+ }
+
+ private BufferedImage readImage(File file) {
+ FileInputStream fis;
+ BufferedInputStream bis;
+ try {
+ fis = new FileInputStream(file);
+ bis = new BufferedInputStream(fis);
+ byte[] b = new byte[1];
+ bis.read(b);
+ switch(b[0]) {
+ case ImageType.RAW:
+
+ break;
+ case ImageType.COMPRESSED:
+ break;
+ }
+ int width = Utils.byteArrayToInt(b);
+ bis.read(b);
+ int height = Utils.byteArrayToInt(b);
+ bis.read(b);
+ int type = Utils.byteArrayToInt(b);
+ BufferedImage image = new BufferedImage(width, height, type);
+ for(int x = 0; x<width; x++) {
+ for(int y = 0; y<height; y++) {
+ bis.read(b);
+ image.setRGB(x, y, Utils.byteArrayToInt(b));
+ }
+ }
+ bis.close();
+ fis.close();
+ return image;
+ } catch (FileNotFoundException e) {
+ e.printStackTrace();
+ } catch (IOException e) {
+ e.printStackTrace();
+ }
+ return null;
+ }
+
+ private void writeImage(File file) {
+ FileOutputStream fos;
+ BufferedOutputStream bos;
+ try {
+ fos = new FileOutputStream(file);
+ bos = new BufferedOutputStream(fos);
+ if(compData == null) {
+ bos.write(ImageType.RAW);
+ } else {
+ bos.write(ImageType.COMPRESSED);
+ }
+ if(compData == null) {
+ bos.write(Utils.intTobyteArray(towrite.getWidth()));
+ bos.write(Utils.intTobyteArray(towrite.getHeight()));
+ bos.write(Utils.intTobyteArray(towrite.getType()));
+ for(int x = 0, width = towrite.getWidth(); x<width; x++) {
+ for(int y = 0, height = towrite.getHeight(); y<height; y++) {
+ bos.write(Utils.intTobyteArray(towrite.getRGB(x, y)));
+ }
+ }
+ } else {
+ bos.write(compressed.getData());
+ }
+ bos.close();
+ fos.close();
+ } catch (FileNotFoundException e) {
+ e.printStackTrace();
+ } catch (IOException e) {
+ e.printStackTrace();
+ }
+ }
+
+}
diff --git a/src/function/Display.java b/src/function/Display.java
new file mode 100755
index 0000000..3241c5c
--- /dev/null
+++ b/src/function/Display.java
@@ -0,0 +1,45 @@
+package function;
+import java.awt.Color;
+import java.awt.Graphics;
+import java.util.ArrayList;
+
+
+public class Display {
+
+ private int x, y, width, height, xMin, xMax, yMin, yMax;
+ private ArrayList<Function> functions;
+
+ public Display(int x, int y, int width, int height, int xMin, int xMax, int yMin, int yMax, ArrayList<Function> functions) {
+ this.x = x;
+ this.y = y;
+ this.width = width;
+ this.height = height;
+ this.xMin = xMin;
+ this.xMax = xMax;
+ this.yMin = yMin;
+ this.yMax = yMax;
+ this.functions = functions;
+ }
+
+ public Display(int x, int y, int width, int height, int xMin, int xMax, int yMin, int yMax) {
+ this(x, y, width, height, xMin, xMax, yMin, yMax, new ArrayList<Function>());
+ }
+
+ public void draw(Graphics g) {
+ for(int i = 0, size = functions.size(); i<size; i++) {
+ for(int x = 0; x<width; x++) {
+ int y1 = (int) Math.round(functions.get(i).getY(x*((double)(xMax-xMin)/width))*((double)height/(yMax-yMin))) + (height/(yMax-yMin));
+ int y2 = (int) Math.round(functions.get(i).getY((x+1)*((double)(xMax-xMin)/width))*((double)height/(yMax-yMin))) + (height/(yMax-yMin));
+ if(y1 >= 0 && y1 <= height && y2 >= 0 && y2 <= height)
+ g.drawLine(this.x+x, this.y+y1, this.x+x+1, this.y+y2);
+ }
+ }
+ g.setColor(Color.BLACK);
+ g.drawRect(x, y, width, height);
+ }
+
+ public void addFunction(Function f) {
+ functions.add(f);
+ }
+
+}
diff --git a/src/function/Function.java b/src/function/Function.java
new file mode 100755
index 0000000..873fc0d
--- /dev/null
+++ b/src/function/Function.java
@@ -0,0 +1,7 @@
+package function;
+
+public abstract class Function {
+
+ public abstract double getY(double x);
+
+}
diff --git a/src/function/Grade1.java b/src/function/Grade1.java
new file mode 100755
index 0000000..6cf5ea5
--- /dev/null
+++ b/src/function/Grade1.java
@@ -0,0 +1,17 @@
+package function;
+
+public class Grade1 extends Function {
+
+ private double a, b;
+
+ public Grade1(double a, double b) {
+ this.a = a;
+ this.b = b;
+ }
+
+ @Override
+ public double getY(double x) {
+ return a*x+b;
+ }
+
+}
diff --git a/src/function/Grade2.java b/src/function/Grade2.java
new file mode 100755
index 0000000..2198d3a
--- /dev/null
+++ b/src/function/Grade2.java
@@ -0,0 +1,17 @@
+package function;
+
+public class Grade2 extends Function {
+
+ private double a, b, c;
+
+ public Grade2(double a, double b, double c) {
+ this.a = a;
+ this.b = b;
+ this.c = c;
+ }
+
+ public double getY(double x) {
+ return a*Math.pow(x, 2)+b*x+c;
+ }
+
+}
diff --git a/src/function/Sin.java b/src/function/Sin.java
new file mode 100755
index 0000000..83bbb6b
--- /dev/null
+++ b/src/function/Sin.java
@@ -0,0 +1,19 @@
+package function;
+
+public class Sin extends Function {
+
+ private double a, b, c, d;
+
+ public Sin(double a, double b, double c, double d) {
+ this.a = a;
+ this.b = b;
+ this.c = c;
+ this.d = d;
+ }
+
+ @Override
+ public double getY(double x) {
+ return a*Math.sin(b*(x+c))+d;
+ }
+
+}
diff --git a/src/function/SquareRoot.java b/src/function/SquareRoot.java
new file mode 100755
index 0000000..0fbbb6c
--- /dev/null
+++ b/src/function/SquareRoot.java
@@ -0,0 +1,17 @@
+package function;
+
+public class SquareRoot extends Function {
+
+ private double a, b, c;
+
+ public SquareRoot(double a, double b, double c) {
+ this.a = a;
+ this.b = b;
+ this.c = c;
+ }
+
+ public double getY(double x) {
+ return a*Math.pow(b*x, 0.5)+c;
+ }
+
+}
diff --git a/src/misc/CompressedImage.java b/src/misc/CompressedImage.java
new file mode 100755
index 0000000..b37daf9
--- /dev/null
+++ b/src/misc/CompressedImage.java
@@ -0,0 +1,129 @@
+package misc;
+
+import java.awt.Color;
+import java.awt.image.BufferedImage;
+import java.util.ArrayList;
+
+public class CompressedImage {
+
+ private BufferedImage image;
+ private int blockWidth, blockHeight, colors;
+ private byte[] data;
+
+ public CompressedImage(BufferedImage image, int blockWidth, int blockHeight, int colors) {
+ ArrayList<Byte[]> compData = new ArrayList<Byte[]>();
+ int imageWidth = image.getWidth(), imageHeight = image.getHeight();
+ this.image = new BufferedImage(imageWidth, imageHeight, image.getType());
+ this.blockWidth = blockWidth;
+ this.blockHeight = blockHeight;
+ compData.add(Utils.intToByteArray(imageWidth));
+ compData.add(Utils.intToByteArray(imageHeight));
+ compData.add(Utils.intToByteArray(image.getType()));
+ compData.add(Utils.intToByteArray(blockWidth));
+ compData.add(Utils.intToByteArray(blockHeight));
+ compData.add(Utils.intToByteArray(colors));
+ Color[][] block;
+ int[][][] table;
+ boolean inList;
+ ArrayList<Integer[]> list;
+ for(int xb = 0; xb<imageWidth; xb+=blockWidth) {
+ for(int yb = 0; yb<imageHeight; yb+=blockHeight) {
+ block = new Color[blockWidth][blockHeight];
+ list = new ArrayList<Integer[]>();
+ x: for(int x = 0; x<blockWidth; x++) {
+ y: for(int y = 0; y<blockHeight; y++) {
+ System.out.println("Lese pixel: (" + (xb+x) + "," + (yb+y) + ")");
+ if(xb+x>=imageWidth) break y;
+ if(yb+y>=imageHeight) continue x;
+ block[x][y] = new Color(image.getRGB(xb+x, yb+y));
+ inList = false;
+ for(int i = 0, size = list.size(); i<size; i++) {
+ if(list.get(i)[0] == block[x][y].getRed() && list.get(i)[1] == block[x][y].getGreen() && list.get(i)[2] == block[x][y].getBlue() && list.get(i)[3] == block[x][y].getAlpha()) {
+ list.set(i, new Integer[] { block[x][y].getRed(), block[x][y].getGreen(), block[x][y].getBlue(), block[x][y].getAlpha(), list.get(i)[4]+1 });
+ inList = true;
+ }
+ }
+ if(!inList)
+ list.add(new Integer[] { block[x][y].getRed(), block[x][y].getGreen(), block[x][y].getBlue(), block[x][y].getAlpha(), 1 });
+ }
+ }
+ int count = 0;
+ Stapel a = new Stapel(), b = new Stapel(), c = new Stapel();
+ for(int i = 0, size = list.size(); i<size; i++) {
+ System.out.println("Zwischenspeichern... (" + i + "/" + size + ")");
+ a.ablegen(list.get(i));
+ }
+ count = 0;
+ while(!a.istLeer()) {
+ System.out.println("Verarbeiten... (" + count + "/" + list.size() + ")");
+ Integer[] top = (Integer[])a.entnehmen();
+ while(!b.istLeer() && ((Integer[])b.inhaltGeben())[4] > top[4]) {
+ a.ablegen(b.entnehmen());
+ count--;
+ }
+ b.ablegen(top);
+ count++;
+ }
+ Color[] palette = new Color[colors];
+ Color previous = null;
+ Integer[] current = null;
+ for(int i = 0; i<palette.length; i++) {
+ if(b.istLeer()) {
+ if(previous == null) {
+ palette[i] = new Color(0,0,0);
+ } else {
+ palette[i] = previous;
+ }
+ } else {
+ current = (Integer[])b.entnehmen();
+ palette[i] = new Color(current[0], current[1], current[2], current[3]);
+ previous = new Color(current[0], current[1], current[2], current[3]);
+ }
+
+ }
+ for(int i = 0; i<palette.length; i++) {
+ compData.add(Utils.intToByteArray(palette[i].getRGB()));
+ }
+ int min, diff, smallest;
+ x: for(int x = 0; x<blockWidth; x++) {
+ y: for(int y = 0; y<blockHeight; y++) {
+ if(xb+x>=imageWidth) break y;
+ if(yb+y>=imageHeight) continue x;
+ Color col = new Color(image.getRGB(xb+x, yb+y));
+ min = 2000;
+ diff = 0;
+ smallest = 0;
+ for(int i = 0; i<palette.length; i++) {
+ if((diff = (int)Math.sqrt(Math.pow(((palette[i].getRed()+palette[i].getGreen()+palette[i].getBlue()+palette[i].getAlpha()) - (col.getRed()+col.getGreen()+col.getBlue()+col.getAlpha())), 2))) < min) {
+ min = diff;
+ smallest = i;
+ }
+ }
+ this.image.setRGB(xb+x, yb+y, palette[smallest].getRGB());
+ compData.add(new Byte[] {(byte)smallest});
+ }
+ }
+ }
+ }
+ int total = 0;
+ for(int i = 0, size = compData.size(); i<size; i++) {
+ total += compData.get(i).length;
+ }
+ this.data = new byte[total];
+ for(int i = 0, size = compData.size(); i<size; i++) {
+ Byte[] current = compData.get(i);
+ for(int j = 0; j<current.length; j++) {
+ this.data[i+j] = current[j];
+ }
+ }
+ }
+
+ public BufferedImage getImage() {
+ return image;
+ }
+
+ public byte[] getData() {
+ return data;
+ }
+
+}
diff --git a/src/misc/Stapel.java b/src/misc/Stapel.java
new file mode 100755
index 0000000..92efc6d
--- /dev/null
+++ b/src/misc/Stapel.java
@@ -0,0 +1,51 @@
+package misc;
+public class Stapel { //Die Klasse / Datei muss genau so heißen!
+
+ private Stapel nextObject;
+ private Object content;
+
+ private Stapel(Object o){
+ content = o;
+ nextObject = null;
+ }
+
+ public Stapel(){
+ nextObject = null;
+ }
+
+ public boolean istLeer(){
+ if (nextObject == null) return true;
+ else return false;
+ }
+
+ public Object inhaltGeben(){
+ if (!istLeer()) return nextObject.content;
+ else return null;
+ }
+
+ public void ablegen(Object o){
+ Stapel neu = new Stapel(o);
+ neu.nextObject = nextObject;
+ nextObject = neu;
+ }
+
+ public Object entnehmen(){
+ Object aus;
+ if (!istLeer()){
+ aus = inhaltGeben();
+ nextObject = nextObject.nextObject;
+ return aus;
+ }
+ else return null;
+ }
+
+ public String ausgeben(){
+ String aus = "";
+ if (!istLeer()){
+ aus = aus + nextObject.content + "|";
+ if (nextObject.nextObject != null) aus = aus + nextObject.ausgeben();
+ }
+ return aus;
+ }
+
+} \ No newline at end of file
diff --git a/src/misc/Utils.java b/src/misc/Utils.java
new file mode 100755
index 0000000..a3d5b0a
--- /dev/null
+++ b/src/misc/Utils.java
@@ -0,0 +1,73 @@
+package misc;
+
+
+import java.io.UnsupportedEncodingException;
+
+public class Utils {
+
+ public static int randomInt(int from, int to) {
+ return (int) (from + Math.round(Math.random() * to));
+ }
+
+ public static String randomStringAN(int length) {
+ String output = "";
+ char[] table = new char[] {
+ 'a', 'b', 'c', 'd', 'e', 'f', 'g', 'h', 'i', 'j', 'k', 'l', 'm', 'n', 'o', 'p', 'q', 'r', 's', 't', 'u', 'v', 'w', 'x', 'y', 'z',
+ 'A', 'B', 'C', 'D', 'E', 'F', 'G', 'H', 'I', 'J', 'K', 'L', 'M', 'N', 'O', 'P', 'Q', 'R', 'S', 'T', 'U', 'V', 'W', 'X', 'Y', 'Z',
+ '0', '1', '2', '3', '4', '5', '6', '7', '8', '9'
+ };
+ for(int i = 0; i<length; i++)
+ output += table[randomInt(0, table.length-1)];
+ return output;
+ }
+
+ public static String randomStringUTF8(int length) {
+ byte[] b = new byte[length];
+ while(true) {
+ for(int i = 0; i<length; i++)
+ b[i] = (byte) Utils.randomInt(0, 255);
+ try {
+ return new String(b, "UTF-8");
+ } catch (UnsupportedEncodingException e) {
+ e.printStackTrace();
+ }
+ }
+ }
+
+ public static int byteArrayToInt(Byte[] b)
+ {
+ return b[3] & 0xFF |
+ (b[2] & 0xFF) << 8 |
+ (b[1] & 0xFF) << 16 |
+ (b[0] & 0xFF) << 24;
+ }
+
+ public static Byte[] intToByteArray(int a)
+ {
+ return new Byte[] {
+ (byte) ((a >> 24) & 0xFF),
+ (byte) ((a >> 16) & 0xFF),
+ (byte) ((a >> 8) & 0xFF),
+ (byte) (a & 0xFF)
+ };
+ }
+
+ public static int byteArrayToInt(byte[] b)
+ {
+ return b[3] & 0xFF |
+ (b[2] & 0xFF) << 8 |
+ (b[1] & 0xFF) << 16 |
+ (b[0] & 0xFF) << 24;
+ }
+
+ public static byte[] intTobyteArray(int a)
+ {
+ return new byte[] {
+ (byte) ((a >> 24) & 0xFF),
+ (byte) ((a >> 16) & 0xFF),
+ (byte) ((a >> 8) & 0xFF),
+ (byte) (a & 0xFF)
+ };
+ }
+
+}