-
Notifications
You must be signed in to change notification settings - Fork 0
/
script.js
67 lines (54 loc) · 1.63 KB
/
script.js
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
$(function(){
$('input[name=distancia], select').change(function(){
$(this).parent().removeClass('has-error');
});
$('form').submit(function(){
sensor = $(this).find('select');
distancia = $(this).find('input[name=distancia]');
is_valid = true;
/* Validação básica do formulário */
if(sensor.val() == ''){
is_valid = false;
sensor.parent().addClass('has-error');
}
if(distancia.val() == ''){
is_valid = false;
distancia.parent().addClass('has-error');
} else {
distancia = parseInt(distancia.val());
}
/* Calculando a brincadeira */
if(is_valid){
full_frame_width = 36;
full_frame_height = 24;
diagonal = Math.sqrt(Math.pow(full_frame_width, 2)+Math.pow(full_frame_height, 2));
switch(sensor.val()){
case 'canon':
diagonal = diagonal / 1.6;
break;
case 'nikon':
diagonal = diagonal / 1.5;
break;
}
angle = (Math.atan((diagonal/2) / distancia) * 180 / Math.PI) * 2;
human_angle = degToDms(angle);
$('h3.angle').html(human_angle.deg+"° "+human_angle.min+"' "+human_angle.sec+'"');
generateViewPreview(angle);
}
return false;
});
});
function generateViewPreview(angulo){
$('.view-angle').html('<div class="angle-demo"></div>');
preview_width = $('.view-angle').width() / 2;
normaliza = angulo / 90;
preview_height = preview_width * normaliza;
$('.angle-demo').css('border-width', (preview_height/2)+"px "+preview_width+"px "+(preview_height/2)+"px 0");
}
function degToDms(dd){
deg = dd | 0;
frac = Math.abs(dd - deg);
min = (frac * 60) | 0;
sec = frac * 3600 - min * 60;
return {deg: deg, min: min, sec: Math.ceil(sec)};
}