-
Notifications
You must be signed in to change notification settings - Fork 0
/
index.html
85 lines (72 loc) · 3.38 KB
/
index.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
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
<!DOCTYPE HTML>
<html>
<head>
<script src="math.js"></script>
<script src="phys.js"></script>
<script src="tools.js"></script>
<script src="draw.js"></script>
<script>
window.onload = function() {
canvas = document.getElementById("myCanvas");
context = canvas.getContext("2d");
width = 640;
height = 480;
var objects = [
new phys.Reflector([
new math.Segment(10, 10, 10, height - 10),
new math.Segment(width - 10, 10, width - 10, height - 10),
new math.Segment(10, 10, width -10, 10),
new math.Segment(10, height - 10, width - 10, height - 10),
]),
/* new phys.Reflector([
new math.Circle (width / 2, height / 2, 50)
]),*/
];
var n = 5;
var delta = 2*Math.PI/n;
var r = 100;
for (var i = 0; i < n; i++){
objects.push(new phys.Lens(new math.Segment (width / 2 + r * Math.cos(i * delta),
height / 2 + r * Math.sin(i * delta),
width / 2 + r * Math.cos((i + 1) * delta),
height / 2 + r * Math.sin((i + 1) * delta)), 0.01));
}
var points = [];
var gen = new LineGenerator(new math.Segment (20, 220, 20, 260), 1000, 10);
function proceedPoints(){
for (var i = 0; i < points.length; i++){
for (var j = 0; j < objects.length; j++) {
var pt = objects[j].collide(points[i]);
if (pt) {
points[i].vector = pt;
points[i].x += points[i].vector.x;
points[i].y += points[i].vector.y;
}
}
points[i].x += points[i].vector.x;
points[i].y += points[i].vector.y;
}
}
setInterval(function(){
var p = gen.generate(-1, 10);
if (p.length > 0){
points = points.concat(p);
}
canvas.width = canvas.width;
context.fillText(points.length, 320, 240);
gen.draw('blue');
proceedPoints();
for (var i = 0; i < objects.length; i++){
objects[i].draw('red');
}
for (var i = 0; i < points.length; i++){
points[i].draw('black');
}
}, 1);
};
</script>
</head>
<body>
<canvas id="myCanvas" width="640" height="480"></canvas>
</body>
</html>