-
Notifications
You must be signed in to change notification settings - Fork 0
/
index.html
187 lines (161 loc) · 4.62 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
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
186
187
<!DOCTYPE html>
<meta charset="utf-8">
<style>
.ticks {
font: 10px sans-serif;
}
.track,
.track-inset,
.track-overlay {
stroke-linecap: round;
}
.track {
stroke: #000;
stroke-opacity: 0.3;
stroke-width: 10px;
}
.track-inset {
stroke: #ddd;
stroke-width: 8px;
}
.track-overlay {
pointer-events: stroke;
stroke-width: 50px;
stroke: transparent;
cursor: crosshair;
}
.handle {
fill: #fff;
stroke: #000;
stroke-opacity: 0.5;
stroke-width: 1.25px;
}
</style>
<svg width="960" height="500"></svg>
<script src="https://d3js.org/d3.v4.js"></script>
<script src="http://cdnjs.cloudflare.com/ajax/libs/mathjs/3.14.2/math.min.js"></script>
<script>
var svg = d3.select("svg"),
margin = {right: 50, left: 50}
width = +svg.attr("width") - margin.left - margin.right,
height = +svg.attr("height");
var hbar = 4.135667662e-15; //eV*s
var c = 299792458;
var pi = math.pi;
var n = 1.52;
var a = 100; //px
var brillouinZone = a;
var centerY = height / 2;
var centerX = width / 4;
var energyMax = 25;
var cx = [centerX-a,centerX,centerX+a];
var cy = [centerY-a,centerY,centerY+a];
var xy = [];
for(var i = 0; i < cx.length; i++) {
for(var j = 0; j < cy.length; j++) {
xy.push([cx[i],cy[j]]);
}
}
var zone = svg.selectAll("rect")
.data([0])
.enter().append("rect")
.attr("x", centerX - brillouinZone/2)
.attr("y", centerY - brillouinZone/2)
.attr("height",brillouinZone)
.attr("width",brillouinZone)
.attr("fill","none")
.attr("stroke","orange");
var circle1 = svg.selectAll("circle")
.data([10,10,10,10,10,10,10,10,10])
.enter().append("circle")
.attr("fill","none")
.attr("stroke","black")
.attr("cy",function(d,i) {return cy[Math.floor(i/3)];})
.attr("cx", function(d,i) {return cx[i%3];})
.attr("r", function(d) { return d; });
var r2 = 5
var circle2 = [r2,r2,r2,r2,r2,r2,r2,r2,r2].forEach(function(d,i) {
var x = cx[i%3];
var y = cy[Math.floor(i/3)];
svg.append("circle")
.attr("cx",x)
.attr("cy",y)
.attr("r",d)
.attr("fill","red");
});
var E = d3.scaleLinear()
.domain([0, energyMax])
.range([0, width / 2])
.clamp(true);
var slider = svg.append("g")
.attr("class","slider")
.attr("transform","translate(" + margin.left + ", " + (height - 50) + ")");
slider.append("line")
.attr("class", "track")
.attr("x1", E.range()[0])
.attr("x2", E.range()[1])
.select(function() { return this.parentNode.appendChild(this.cloneNode(true)); })
.attr("class", "track-inset")
.select(function() { return this.parentNode.appendChild(this.cloneNode(true)); })
.attr("class", "track-overlay")
.call(d3.drag()
.on("start.interrupt", function() { slider.interrupt(); })
.on("start drag", function() { k_r(E.invert(d3.event.x)); }));
slider.insert("g", ".track-overlay")
.attr("class", "ticks")
.attr("transform","translate(0," + 18 + ")")
.selectAll("text")
.data(E.ticks(10))
.enter().append("text")
.attr("x", E)
.attr("text-anchor", "middle")
.text(function(d) { return d + "eV"; });
var handle = slider.insert("circle", ".track-overlay")
.attr("class", "handle")
.attr("r", 9);
slider.transition() //gratuituos, copied intro
.duration(1000)
.tween("E", function(){
var i = d3.interpolate(0,10)
return function(t) { k_r(i(t)); };
});
function k_r(energy) {
handle.attr("cx", E(energy));
r1 = (n*energy)/(hbar*c);
circle1.attr("r", energy*10);
}
var kSep = a/50
var kx = Array.from(new Array(50), (x,i) => i*kSep - 25*kSep) + Array.from(new Array(50), (x,i) => i*0);
var ky = Array.from(new Array(50), (x,i) => i*0) + Array.from(new Array(50), (x,i) => i*kSep + 25*kSep);
function dist(xy1,xy2) {
var d = Math.sqrt( Math.pow((xy2[0] - xy1[0]),2) + Math.pow((xy2[1] - xy1[1]),2) );
return d;
}
function eV(k) {
var E_eV = (k*c*hbar)/n;
return E_eV;
}
var x = d3.scaleLinear()
.rangeRound([width / 2, width]);
var y = d3.scaleLinear()
.rangeRound([height,0]);
var lineGen = d3.line()
.x(function(k) { return x(k); })
.y(function(k) { return y(eV(k)); })
xy.forEach( function(coords) {
svg.append("paths")
.attr("d",lineGen( k_range(coords) ) )
.attr('stroke', function(d, j) {
return "hsl(" + Math.random() * 360 + ",100%,50%)";
})
.attr("stroke-width",2)
.attr("fill", "none");
});
function k_range(xy) {
out = [];
for(var i = 0; i < kx.length; i++){
out.push( dist(xy,[kx[i],ky[i]]) );
};
return out;
}
</script>