-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathGraph.java
More file actions
83 lines (79 loc) · 2.65 KB
/
Graph.java
File metadata and controls
83 lines (79 loc) · 2.65 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
/*
╭────────────────────────────────────────────────────╮
│ ╵
│ File: Graph.java
│ Project: FirstProject
│
│ Created by Everett Wilber on 21/09/17 at 11:21 AM.
│ ╷
╰────────────────────────────────────────────────────╯
*/
import java.util.ArrayList;
import java.util.List;
import static java.lang.Math.*;
@SuppressWarnings("ALL")
public class Graph {
float maxY;
float minY;
int times;
float dist;
String printString = "";
List<Float> xs = new ArrayList<>(List.of());
List<Float> ys = new ArrayList<>(List.of());
public static void main(String[] args) {
Graph testGraph = new Graph(20, 0.5f);
testGraph.print();
}
public float func(float x) {
// return x;
return ((float) Math.pow(x, 2)); // x^2-1
}
public Graph(int points, float pointDist) {
this.times = points;
this.dist = pointDist;
this.iterate();
this.findRange();
}
public void iterate() {
xs = new ArrayList<>(List.of());
ys = new ArrayList<>(List.of());
for (int i = -round(times/2); i < round(times/2); i++) {
float amt = ((float) i)*dist;
xs.add(amt);
ys.add(func(amt));
}
}
public void findRange() {
for (float y : ys) {
maxY = max(y, maxY);
minY = min(y, minY);
}
}
private void EvalPrintString() {
System.out.println("EvalPrint");
findRange();
System.out.println("Min: "+minY+"; Max: "+maxY);
for (float y = maxY; y > minY; y--) {
// System.out.println("y:"+y);
for (float x : xs) {
float currentYTop = y+1;
float currentYBottom = y-1;
boolean XIsInCurrentY = (x>currentYBottom) && (x<currentYTop);
// System.out.println(XIsInCurrentY);
if (!XIsInCurrentY) {
this.printString = this.printString + " ";
} else {
this.printString = this.printString + "*";
}
}
this.printString = this.printString + "|\n|";
}
}
public void print() {
System.out.println(xs);
System.out.println(ys);
System.out.println("Beginning Print");
EvalPrintString();
System.out.println(printString);
}
}