-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathFields.html
95 lines (74 loc) · 1.96 KB
/
Fields.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
86
87
88
89
90
91
92
93
94
95
<!DOCTYPE html>
<html>
<head>
<title>Fields</title>
<meta charset="utf-8">
<style>
body {
background-color: #323232;
}
canvas {
position: absolute;
left: 50%;
top:50%;
transform: translate(-50%, -50%);
background-color: white;
}
</style>
</head>
<body>
<script src="./lib/playground.js"></script>
<script type="text/javascript">
let scene = new Scene(800, 600);
document.body.appendChild(scene.canvas);
let graph = new GraphNode(100, 75, {min:0, max:100}, {min:-1, max:1});
graph.setPosition(700, 0);
let fieldNode;
let a;
let b;
let t = 0;
let listener;
let v = 50;
let f1 = 5.5;
let gamma1 = v/f1;
let f2 = 5;
let gamma2 = v/f2;
window.onload = function() {
init();
render();
}
function init() {
fieldNode = new FieldNode(new ScalarField(800, 600));
a = new ShapeNode(new Point());
a.setPosition(scene.width/2, scene.height/2);
b = new ShapeNode(new Point());
b.setPosition(scene.width/2, scene.height/2);
listener = new ShapeNode(new Circle(3), "red");
a.setPhysicsBody(new PhysicsBody(a.shape));
b.setPhysicsBody(new PhysicsBody(b.shape));
graph.values.push([]);
for (let i = 0; i < graph.rangeX.max; i++) {
graph.values[0].push(0);
}
scene.addChild(fieldNode);
scene.addChild(a);
scene.addChild(b);
scene.addChild(listener);
scene.addChild(graph);
}
function render() {
let ap = a.position;
let bp = b.position;
let op = new Vector(0, 0);
listener.setPosition(scene.mouse.x, scene.mouse.y);
fieldNode.field.setValue((p) => {return Math.cos((p.distanceTo(ap)-t*v)/gamma1*Math.PI)*50/(p.distanceTo(ap))});
fieldNode.field.addValue((p) => {return Math.cos((p.distanceTo(bp)-t*v)/gamma2*Math.PI)*50/(p.distanceTo(bp))});
t += 1/30;
graph.values[0].push(fieldNode.field.value[listener.position.y][listener.position.x]);
graph.values[0].shift();
scene.update();
window.requestAnimationFrame(render);
}
</script>
</body>
</html>