-
Notifications
You must be signed in to change notification settings - Fork 2
/
Copy pathstation_simulation.html
92 lines (84 loc) · 3.67 KB
/
station_simulation.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
<!doctype html>
<html>
<head>
<meta charset="utf-8">
<title>HiSPARC - jSparc - Station simulation</title>
<link rel="shortcut icon" href="images/favicon.ico">
<link rel="stylesheet" href="styles/common.css">
<script>
"use strict";
var i = 0;
var scale = 0.5;
var canvas, context;
function initCanvas() {
canvas = document.getElementById('station_layout');
context = canvas.getContext('2d');
context.translate(300,500);
context.save();
makeCanvas();}
function scatter_particles() {
if(i !== 0) {
clearCanvas();
makeCanvas();}
var number = document.getElementById("density").value,
canvaswidth = document.getElementById("station_layout").width,
canvasheight = document.getElementById("station_layout").height;
var size = canvaswidth * canvasheight / (100 * 100 * scale * scale);
var number_of_particles = size * number;
for (i = 0; i < number_of_particles; i++) {
var x = (600 * Math.random()),
y = (600 * Math.random());
drawParticle(context, x, y);}}
function radians(degrees) {
return degrees * Math.PI / 180;}
function drawStation(ctx, r, alpha, beta, color) {
var detector_width = 50 * scale;
var detector_height = 100 * scale;
r = -r * 100 * scale;
ctx.rotate(radians(alpha));
ctx.translate(0, r);
ctx.rotate(-radians(alpha));
ctx.rotate(radians(beta));
ctx.fillStyle = color;
ctx.fillRect(-detector_width / 2, -detector_height / 2,
detector_width, detector_height);
ctx.restore();
ctx.save();}
function drawParticle(ctx, x, y) {
ctx.fillStyle = 'black';
ctx.fillRect(x-301, y-501, 2, 2);
ctx.restore();
ctx.save();}
function clearCanvas() {
// Store the current transformation matrix
context.save();
// Use the identity matrix while clearing the canvas
context.setTransform(1, 0, 0, 1, 0, 0);
context.clearRect(0, 0, canvas.width, canvas.height);
// Restore the transform
context.restore();}
function makeCanvas(){
context.fillStyle = 'blue';
context.fillRect(-2.5, -2.5, 5, 5);
drawStation(context, 8.66, 0, 0, 'gray');
drawStation(context, 2.66, 0, 0, 'red');
drawStation(context, 5, -90, 90, 'lightgreen');
drawStation(context, 5, 90, 90, 'lightblue');}
</script>
</head>
<body onload="initCanvas()">
<div id="container">
<div id="header"><div id="pageHeader"></div></div>
<div id="doc_link">
<a href="https://docs.hisparc.nl/infopakket/pdf/air_showers.pdf" target="jsparc_doc">➔ Werkblad</a>
<a href="index.html">➔ jSparc</a>
</div>
<p>
Particle density in [m<sup>-2</sup>]:
<input type="text" id="density" value="2">
<button onclick="scatter_particles()">Start simulation</button>
</p>
<canvas id="station_layout" width="600" height="600"></canvas>
</div>
</body>
</html>