-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathcalculator5.html
More file actions
executable file
·185 lines (122 loc) · 2.94 KB
/
calculator5.html
File metadata and controls
executable file
·185 lines (122 loc) · 2.94 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
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
<html>
<head>
<!-- Name- Payel Bandyopadhyay, Student Number - 014174692 -->
<script type="text/javascript">
function series()
{
elem1 = document.getElementById('numbers');
var elem2 = elem1.value;
if (elem2 == 'sin(x)')
{
sine();
}
else if ( elem2 == 'cos(x)')
{
cosine();
}
else
{
alert("Not a valid input!");
}
}
function sine()
{
var x;
var c=document.getElementById("myCanvas");
var ctx=c.getContext("2d");
c.width = c.width;
ctx.font="20px NewTimesRoman";
var gradient=ctx.createLinearGradient(0,0,c.width,0);
gradient.addColorStop("0","magenta");
gradient.addColorStop("0.5","blue");
gradient.addColorStop("1.0","red");
ctx.fillStyle=gradient;
ctx.fillText("Sine plot",10,90);
var w = ctx.canvas.width;
var l = ctx.canvas.height;
ctx.moveTo(0, l/2);
ctx.lineTo(w,l/2);
ctx.moveTo(w/2,0);
ctx.lineTo(w/2,l);
ctx.moveTo(0, l/2);
for(x=-3.14; x<=3.20;)
{
var xp = x*(w/(2*Math.PI));
var a= 3*2*1;
var b = 5*4*3*2*1;
var c = 7*6*5*4*3*2*1;
var d = 9*8*7*6*5*4*3*2*1;
var p;
p = x - ((x*x*x)/a) + ((x*x*x*x*x)/b) - ((x*x*x*x*x*x*x)/c) + ((x*x*x*x*x*x*x*x*x)/d);
y = (l/2)*p;
if(x === 0)
{
ctx.moveTo(w/2+xp,l/2-y);
}
else
{
ctx.lineTo(w/2+xp,l/2-y);
}
ctx.stroke();
ctx.strokeStyle=gradient;
ctx.lineWidth=2;
x=x+0.1;
}
}
function cosine()
{
var x;
var c=document.getElementById("myCanvas");
var ctx=c.getContext("2d");
c.width = c.width;
ctx.font="20px NewTimesRoman";
var gradient=ctx.createLinearGradient(0,0,c.width,0);
gradient.addColorStop("0","magenta");
gradient.addColorStop("0.5","blue");
gradient.addColorStop("1.0","red");
ctx.fillStyle=gradient;
ctx.fillText("Cosine plot",10,90);
var w = ctx.canvas.width;
var l = ctx.canvas.height;
ctx.moveTo(0, l/2);
ctx.lineTo(w,l/2);
ctx.moveTo(w/2,0);
ctx.lineTo(w/2,l);
ctx.moveTo(0, l);
for(x=-3.14; x<=3.20;)
{
var xp = x*(w/(2*Math.PI));
var a = 2*1;
var b = 4*3*2*1;
var c = 6*5*4*3*2*1;
var d = 8*7*6*5*4*3*2*1;
var e = 10*9*8*7*6*5*4*3*2*1;
var p;
p = 1- ((x*x)/a) + ((x*x*x*x)/b) - ((x*x*x*x*x*x)/c) + ((x*x*x*x*x*x*x*x)/d)- ((x*x*x*x*x*x*x*x*x*x)/e);
y = (l/2)*p;
if(x === 0)
{
ctx.moveTo(w/2+xp,l/2-y);
}
else
{
ctx.lineTo(w/2+xp,l/2-y);
}
ctx.stroke();
ctx.strokeStyle=gradient;
ctx.lineWidth=2;
x=x+0.1;
}
}
</script>
</head>
<body>
<form action="#" name="f1">
<canvas id="myCanvas" width="600" height="400" style="border:1px solid #d3d3d3;">
Your browser doesnot support HTML5 canas</canvas>
</br> <input type='text' id='numbers'/>
<input type= 'button' value= 'Submit' onclick="series()" />
</form>
<br><span id="outtab"></span>
</body>
</html>