-
Notifications
You must be signed in to change notification settings - Fork 0
/
SinAndCos.html
58 lines (52 loc) · 1.11 KB
/
SinAndCos.html
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
<!DOCTYPE html>
<html>
<head>
<meta charset="utf-8"/>
<script type="application/javascript">
function draw() {
var canvas = document.getElementById("canvas");
if (canvas.getContext) {
var ctx = canvas.getContext("2d");
// establish a new origin
ctx.translate(100,100) ;
//draw axis
ctx.beginPath() ;
ctx.moveTo(0,-100);
ctx.lineTo(0,100);
ctx.moveTo(-100,0);
ctx.lineTo(100,0);
ctx.strokeStyle = "black";
ctx.stroke() ;
// plot sin(x)
ctx.beginPath();
for(var i=-100;i<100;i++){
yy=Math.sin(i*.1)*50;
ctx.lineTo(i,yy);
}
ctx.strokeStyle = "green";
ctx.stroke() ;
// plot cos(x)
ctx.beginPath();
for(var i=-100;i<100;i++){
yy=Math.cos(i*.1)*50;
ctx.lineTo(i,yy);
}
ctx.strokeStyle = "blue";
ctx.stroke() ;
// plot sin(x) against cos(x)
ctx.beginPath();
for(var i=0;i<64;i++){
yy=Math.sin(i*.1)*50;
xx=Math.cos(i*.1)*50;
ctx.lineTo(xx,yy);
}
ctx.strokeStyle = "red";
ctx.stroke() ;
}
}
</script>
</head>
<body onload="draw();">
<canvas id="canvas" width="200" height="200"></canvas>
</body>
</html>