summaryrefslogtreecommitdiff
path: root/src/function
diff options
context:
space:
mode:
authorLeonard Kugis <leonard@kug.is>2022-04-25 18:36:30 +0200
committerLeonard Kugis <leonard@kug.is>2022-04-25 18:36:30 +0200
commit84e220b332bfffb0f2dcc39b9697a6fd6691d265 (patch)
tree0b861a9a099017ffd9bf00bae12e33ed6a309bbe /src/function
Initial commitHEADmaster
Diffstat (limited to 'src/function')
-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
6 files changed, 122 insertions, 0 deletions
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;
+ }
+
+}