-
Notifications
You must be signed in to change notification settings - Fork 0
/
trigonometry_graphs.pde
103 lines (96 loc) · 2.16 KB
/
trigonometry_graphs.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
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
/* @pjs preload="data/curve-sin.png"; */
/* @pjs preload="data/curve-cos.png"; */
/* @pjs preload="data/curve-tan.png"; */
/* @pjs preload="data/curve-cosec.png"; */
/* @pjs preload="data/curve-sec.png"; */
/* @pjs preload="data/curve-cot.png"; */
/* @pjs font="data/BradleyHandITC-18.ttf"; */
/* @pjs font="data/HarlowSolid-32.ttf"; */
// Global Variables
PFont harlow, bradley;
String Menu[] = {"sin", "cos", "tan", "sec", "cosec", "cot"};
PImage BackImg[];
int Sel;
void setup()
{
int i;
size(1000, 480);
background(50, 60, 100);
smooth();
harlow = loadFont("data/HarlowSolid-32.vlw");
bradley = loadFont("data/BradleyHandITC-18.vlw");
BackImg = new PImage[6];
for(i=0; i<6; i++)
BackImg[i] = loadImage("data/curve-"+Menu[i]+".png");
Sel = 0;
}
void draw()
{
int slt;
float x0, y0, x, y;
float th, ans;
int delX, delY, ptX, ptY;
// Draw sample
image(BackImg[Sel],0,0);
// Select Curve
if(mouseX > 865)
{
slt = (int)((mouseY) / 80);
y = 40 + slt*80;
textFont(harlow, 32);
textAlign(CENTER);
fill(160,140,160);
stroke(110, 120, 150);
strokeWeight(46);
line(870, y, 960, y);
text(Menu[(int)((y-40)/80)], 910, y+5);
if(mousePressed)
{
Sel = slt;
stroke(150, 120, 150);
line(870, y, 960, y);
text(Menu[(int)((y-40)/80)], 910, y+5);
}
}
// Draw Curve
strokeWeight(4);
delX = mouseX - 200;
delY = 240 - mouseY;
th = atan2(delY, delX);
if(th < 0) th += 2.0 * PI;
ptX = (int)(200 + 150*cos(th));
ptY = (int)(240 - 150*sin(th));
stroke(70, 150, 195);
line(200, 240, ptX, ptY);
x = (180.0*th)/PI;
switch(Sel)
{
case 0:
ans = sin(th);
break;
case 1:
ans = cos(th);
break;
case 2:
ans = tan(th);
break;
case 3:
ans = 1/cos(th);
break;
case 4:
ans = 1/sin(th);
break;
default:
ans = 1/tan(th);
}
if(Sel<2) y = 150.0*ans;
else y = 25.0*ans;
line(450.0+x, 240.0, 450.0+x, 240.0-y);
stroke(105, 105, 85);
strokeWeight(1);
line(ptX, ptY, 450.0+x, 240.0-y);
textFont(bradley, 18);
textAlign(LEFT);
fill(200,180,200);
text(Menu[Sel] + "( " + x +"deg ) = " + ans, 10, 470);
}