-
Notifications
You must be signed in to change notification settings - Fork 0
/
Graphing_Calculator.pde
61 lines (51 loc) · 1.18 KB
/
Graphing_Calculator.pde
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
final float X_MAX = 20;
final float Y_MAX = 20;
boolean mirror = true;
void drawPlane() {
background(50);
textAlign(CENTER, CENTER);
stroke(140);
line(300, 0, 300, 600);
line(0, 300, 600, 300);
for(int i = 0; i <= 600; i += 60) {
line(i, 290, i, 310);
line(290, i, 310, i);
if(i != 300) {
text((int)((((float)i / 600) * (X_MAX * 2)) - X_MAX), i+2, 323);
text((int)((((float)i / 600) * (Y_MAX * 2)) - Y_MAX), 323, i-2);
}
else {
text(0, i+10, 323);
}
}
}
void drawFunc() {
float x1=-1000, y1=0, x2=0, y2=0;
float ny1=0, ny2=0;
stroke(#608360);
strokeWeight(2);
for(float x = -X_MAX; x <= X_MAX; x += X_MAX / 2000) {
/* EQUATION */
float y = sqrt(16 - (x*x));
float ny = -y;
x2 = (x*(300/X_MAX))+300;
y2 = 300-(y*(300/Y_MAX));
if(x1 != -1000) {
line(x1, y1, x2, y2);
}
if(mirror) {
ny2 = 300 - (ny*(300/Y_MAX));
if(x1 != -1000) {
line(x1, ny1, x2, ny2);
}
ny1 = ny2;
}
x1 = x2;
y1 = y2;
}
}
void setup() {
size(600, 600);
drawPlane();
drawFunc();
}