forked from nozomi199/qimen_star
-
Notifications
You must be signed in to change notification settings - Fork 0
/
simple.html
400 lines (393 loc) · 17.1 KB
/
simple.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
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
<!DOCTYPE html>
<html>
<head>
<title>奇門遁甲</title>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<script language="JavaScript" src="_js/sprintf.min.js"></script>
<style type="text/css">
body {position: relative;padding:0;margin:0}
div {position: relative}
table {position: relative}
form {position: relative}
tr {position: relative;height: 7mm}
td {position: relative;padding:0}
input, select {position: relative;top:0;left:0;right:0;bottom:0;width:100%;height:100%;border:0;padding:0}
</style>
<script language="javascript" src="_js/jquery.min.js"></script>
<script language="javascript" src="_js/jiqi.js"></script>
<script language="JavaScript" src="_js/lunar.js"></script>
<script language="JavaScript" src="_js/qimen_min.js"></script>
<script language="javascript">
"use strict";
var gbl_date = new Date();
String.prototype.replaceAt=function(index, character) {
return this.substr(0, index) + character + this.substr(index+character.length);
};
function gui_check_input_date(id) {
"use strict";
var patt1=/^[0-9]{4}[0-9]{2}[0-9]{2}-[0-9]{2}[0-9]{2}[0-9]{2}$/i;
if(!id.match(patt1)) {
return false;
}
var daysInMonth = [0,31,28,31,30,31,30,31,31,30,31,30,31];
// If evenly divisible by 4 and not evenly divisible by 100,
// or is evenly divisible by 400, then a leap year
var y = (id.substr(0,4))*1;
var m = (id.substr(4,2))*1;
var d = (id.substr(6,2))*1;
var h = (id.substr(9,2))*1;
var i = (id.substr(11,2))*1;
var s = (id.substr(13,2))*1;
//console.log(y,m,d,h,i,s);
if ( (!(y % 4) && y % 100) || !(y % 400)) {
daysInMonth[2] = 29;
}
if(m < 1 || m > 12) return false;
if(d < 1 || d > daysInMonth[m]) return false;
if(h < 0 || h > 23) return false;
if(i < 0 || i > 59) return false;
if(s < 0 || s > 59) return false;
return true;
}
function calc(){
var id = $('input[name=txtDate]').val();
if(gui_check_input_date(id) == false){
alert('error format'); return;
}
var y = (id.substr(0,4))*1;
var m = (id.substr(4,2))*1;
var d = (id.substr(6,2))*1;
var h = (id.substr(9,2))*1;
var i = (id.substr(11,2))*1;
var s = (id.substr(13,2))*1;
gbl_date = new Date(y,m-1,d,h,i,s);
// cal qimen;
calc_qimen();
}
function calc_now() {
gbl_date = null;
gbl_date = new Date();
calc_qimen();
}
function tuneDate(btn){
var intxt = $(btn).val();
var act = intxt[0];
var idx = "年月日時分秒".indexOf(intxt[1]);
if(!gbl_date) return;
//
if(act == '+') {
if(idx == 0) { gbl_date.setDate(gbl_date.getDate() + 365);; }
if(idx == 1) { gbl_date.setDate(gbl_date.getDate() + 30);; }
if(idx == 2) { gbl_date.setDate(gbl_date.getDate() + 1);; }
if(idx == 3) { gbl_date.setTime(gbl_date.getTime() + 3600000);; }
if(idx == 4) { gbl_date.setTime(gbl_date.getTime() + 60000);; }
if(idx == 5) { gbl_date.setTime(gbl_date.getTime() + 1000);; }
} else {
if(idx == 0) { gbl_date.setDate(gbl_date.getDate() - 365);; }
if(idx == 1) { gbl_date.setDate(gbl_date.getDate() - 30);; }
if(idx == 2) { gbl_date.setDate(gbl_date.getDate() - 1);; }
if(idx == 3) { gbl_date.setTime(gbl_date.getTime() - 3600000);; }
if(idx == 4) { gbl_date.setTime(gbl_date.getTime() - 60000);; }
if(idx == 5) { gbl_date.setTime(gbl_date.getTime() - 1000);; }
}
calc_qimen();
}
function calc_qimen() {
var d = new Date(gbl_date);
var jiqi = QIMEN_STAR.jiqi.GetJiqiInfo(
d.getFullYear(),d.getMonth()+1,d.getDate(),d.getHours(),d.getMinutes(),d.getSeconds(),0);
//console.log(jiqi);
//var out = sprintf("%s\r\n",QIMEN_STAR.jiqi.JTime(jiqi.julian));
var out = sprintf("%s%03d\r\n",QIMEN_STAR.jiqi.JTime(jiqi.julian),d.getMilliseconds());
(function() {
var lunar = QIMEN_STAR.Solar2Lunar(d.getFullYear(),d.getMonth()+1,d.getDate(),d.getHours(),d.getMinutes(),d.getSeconds());
// 計當下月將
var _arrGen = new Array;
for(var i = 2; i < 25; i+=2) {
_arrGen.push(jiqi.wholeYear[i-1]);
}
var _gen = 11;
for(var i = 0; i < 12; i++) {
////console.log(jiqi.jq0[(11-i)*2+1]);
if(jiqi.julian > _arrGen[11 - i]) {
_gen = 11 - i;
break;
}
}
// 計算日期
var ldate = lunar.substring(lunar.indexOf('月')+1,lunar.indexOf('日'));
ldate = parseInt(ldate);
var ldate2 = sprintf("%02d%02d%02d",parseInt(ldate),d.getHours(),d.getMinutes());ldate2 = parseInt(ldate2);
var idxLst = (function(ld) {
var lst = [0,21730,50430,71530,100230,121330,150030,171130,192230,220930,242030,270330,291830];
var idx = 0;
for(var i = 13; i > 0; i--) if(lst[i] < ld) { idx = i; break }
var astro = "亥戌酉申未午巳辰卯寅丑子亥戌酉申未午巳辰卯寅丑子".substr(_gen,12);
return sprintf("%s:%d",astro[idx%12],idx % 12);
})(ldate2);
//
out += sprintf("%s, %s\r\n",lunar,idxLst);
})();
var cjiqi = jiqi.currentJiqiIdx - 1; if(cjiqi < 0) cjiqi = 23;
out += sprintf("當前節氣: %s, %s\r\n",jiqi.jiqi[cjiqi],QIMEN_STAR.jiqi.JTime(jiqi.wholeYear[cjiqi]));
// 排四柱
var tcol0 = new Array;
var dcol0 = new Array;
for(var i = 6; i > -1 ; i -= 2) tcol0.push(jiqi.bazi[i]);
for(var i = 7; i > -1 ; i -= 2) dcol0.push(jiqi.bazi[i]);
//
// 計時家奇門三元
var idx1 = "甲乙丙丁戊己庚辛壬癸".indexOf(jiqi.bazi[4]);
var idx2 = "子丑寅卯辰巳午未申酉戌亥".indexOf(jiqi.bazi[5]);
idx2 = idx2 - idx1 % 5;
if(idx2 < 0) idx2 += 12;
idx2 = idx2 % 3;
if(idx2 > 0) {
idx2 = (idx2 == 1)? 2 : 1;
}
out += jiqi.jiqi[cjiqi]+"上中下".charAt(idx2)+"元 ";
// 計算當前局數
// 計陰陽遁
var dun_type = 2; // 0為陰遁, 1為陽遁, 其餘為錯誤
var kook = [8,9,1,3,4,5,4,5,6,9,8,7,2,1,9,7,6,5,6,5,4,1,2,3]; // 局數
var using_kook = kook[cjiqi]; //局數
//console.log(jtoday, jqTime[21], jqTime[9]);
if( jiqi.julian > jiqi.wholeYear[9] && jiqi.julian < jiqi.wholeYear[21]) {
// 陰遁
dun_type = 0;
for(var i = 0; i < idx2; i++) {
using_kook -= 6;
while(using_kook < 1) using_kook += 9;
}
} else {
// 陽遁
dun_type = 1;
for(var i = 0; i < idx2; i++) {
using_kook += 6;
while(using_kook > 9) using_kook -= 9;
}
}
if($('#cboDun').val() < 2) dun_type = $('#cboDun').val();
if($('#cboKook').val() > 0) using_kook = $('#cboKook').val();
//console.log("using_kook",using_kook);
out += "陰陽".charAt(dun_type)+"遁"+" 一二三四五六七八九".charAt(using_kook)+"局"+"\r\n";
// 輸出柱名
out += " ";
//for(var i = 0; i < jiqi.bazi.length; i+=2) {
for(var i = 0; i < 12; i+=2) {
out += " "+" 年 月 日 時 分 秒毫秒不知未明疑問".substr(i,2);
} out += "\r\n";
// 輸出八字
out += ("八字:");
//for(var i = 0; i < jiqi.bazi.length; i += 2) out+=(" "+jiqi.bazi.substr(i, 2));
for(var i = 0; i < 12; i += 2) out+=(" "+jiqi.bazi.substr(i, 2));
out+=("\r\n");
// 計空亡
out += ("空亡:");
for(var i = 0; i < 12; i += 2) {
var chun_sau = "子丑寅卯辰巳午未申酉戌亥".indexOf(jiqi.bazi[i+1]) - "甲乙丙丁戊己庚辛壬癸".indexOf(jiqi.bazi[i]);
if(chun_sau < 0) chun_sau += 12;
var hung_mon = chun_sau - 2;
if(hung_mon < 0) hung_mon += 12;
out += (" "+"子丑寅卯辰巳午未申酉戌亥".substr(hung_mon, 2));
}
out += ("\r\n");
// ---
// 計算時家奇門遁甲
// ---
var ot = $('#tpltable').text().split("\n");
var q1 = QIMEN_STAR.qimenCalc(dun_type,using_kook,jiqi.bazi.substr(6,2));
//var q2 = QIMEN_STAR.minQimen(d.getHours(),d.getMinutes(),d.getSeconds());
out += sprintf("值符:天%s\r\n", q1['info']['符']);
//out += sprintf("秒家:干支:%s, %s遁%s局\r\n", q2['info']['干支'],q2['info']['遁'],q2['info']['局']);
// setup info
$('#info').html(out);
//
var gn = {'符':'值符','蛇':'騰蛇','陰':'太陰','合':'六合','白':'白虎','玄':'玄武','地':'九地','天':'九天'};
var idx = [[12,7],[2,12],[7,2],[2,2],[7,7],[12,12],[7,12],[12,2],[2,7]];
for(var i = 0; i < 9; i++) {
var sy = idx[i][0], sx = idx[i][1];
// 時家奇門
ot[sy+3] = ot[sy+3].replaceAt(sx+3,q1['地'][i+1]);
if(i == 4) continue;
ot[sy+0] = ot[sy+0].replaceAt(sx+2,'門');
ot[sy+0] = ot[sy+0].replaceAt(sx+1,q1['門'][i+1]);
if(i != 4)ot[sy+1] = ot[sy+1].replaceAt(sx+1,gn[q1['神'][i+1]]);
ot[sy+2] = ot[sy+2].replaceAt(sx+1,'天');
ot[sy+2] = ot[sy+2].replaceAt(sx+2,q1['星'][i+1]);
ot[sy+2] = ot[sy+2].replaceAt(sx+3,q1['天'][i+1]);
/**
// 秒家奇門
ot[sy+2] = ot[sy+2].replaceAt(sx+1,q2['門'][i+1]);
ot[sy+2] = ot[sy+2].replaceAt(sx+2,q2['神'][i+1]);
ot[sy+2] = ot[sy+2].replaceAt(sx+3,q2['天'][i+1]);
ot[sy+3] = ot[sy+3].replaceAt(sx+2,q2['星'][i+1]);
ot[sy+3] = ot[sy+3].replaceAt(sx+3,q2['地'][i+1]);
**/
}
// 建立空亡符號
(function() {
var abc = jiqi.bazi.substr(6,2)
var chun_sau = "子丑寅卯辰巳午未申酉戌亥".indexOf(abc[1]) - "甲乙丙丁戊己庚辛壬癸".indexOf(abc[0]);
if(chun_sau < 0) chun_sau += 12;
var hung_mon = chun_sau - 2;
if(hung_mon < 0) hung_mon += 12;
// 建立空亡符號
var idx = [[12,7],[2,12],[7,2],[2,2],[7,7],[12,12],[7,12],[12,2],[2,7]];
var a = "077233811655".charAt(hung_mon);
var sy = idx[a][0], sx = idx[a][1];
ot[sy+0] = ot[sy+0].replaceAt(sx+0,'O');
var a = "077233811655".charAt(hung_mon+1);//console.log(a)
var sy = idx[a][0], sx = idx[a][1];
ot[sy+0] = ot[sy+0].replaceAt(sx+0,'O');
})();
// 計貴人
(function() {
// 計當下月將
var _arrGen = new Array;
for(var i = 2; i < 25; i+=2) {
_arrGen.push(jiqi.wholeYear[i-1]);
}
var _gen = 11;
for(var i = 0; i < 12; i++) {
////console.log(jiqi.jq0[(11-i)*2+1]);
if(jiqi.julian > _arrGen[11 - i]) {
_gen = 11 - i;
break;
}
}
// 月將加時
var _ginmon = "子丑寅卯辰巳午未申酉戌亥".indexOf("亥戌酉申未午巳辰卯寅丑子".charAt(_gen)); // 找月將index
var _gmonth = "子丑寅卯辰巳午未申酉戌亥".indexOf(dcol0[0]); //月將加時index
var _gg = _ginmon - _gmonth;
if(_gg < 0) _gg+= 12;
var gnm = "子丑寅卯辰巳午未申酉戌亥子丑寅卯辰巳午未申酉戌亥".substr(_gg,12); // 月將加時天盤
var _gen_text = "亥戌酉申未午巳辰卯寅丑子".charAt(_gen);
var _dnt = gnm.indexOf(_gen_text);
var day_night_tin = "卯辰巳午未申酉戌亥子丑寅";
var day_night_tin = day_night_tin.indexOf("子丑寅卯辰巳午未申酉戌亥".charAt(_dnt));
var tin_idx = "甲乙丙丁戊己庚辛壬癸".indexOf(tcol0[1]);
var help_man;
if(day_night_tin < 6) { // 日貴人
var help_man = "丑子亥亥丑子丑午巳巳".charAt(tin_idx);
} else { //夜貴人
var help_man = "未申酉酉未申未寅卯卯".charAt(tin_idx);
}
var help_man2;
var _tmp = gnm.indexOf(help_man); //console.log(gnm.charAt(_tmp));
var _tmp2 = "子丑寅卯辰巳午未申酉戌亥".charAt(_tmp);
var day_night_dei = "亥子丑寅卯辰巳午未申酉戌".indexOf(_tmp2);//console.log(_tmp2,":",day_night_dei);
var _start_at = 12 - _tmp; if(_start_at == 0) _start_at = 12;
//console.log(day_night_dei,': ',_start_at);
if(day_night_dei < 6) { // 順貴人
var help_man2 = "貴蛇朱合勾青空白常玄陰后貴蛇朱合勾青空白常玄陰后貴蛇朱合勾青空白常玄陰后".substr(_start_at, 12);
} else { //逆貴人
var help_man2 = "后陰玄常白空青勾合朱蛇貴后陰玄常白空青勾合朱蛇貴后陰玄常白空青勾合朱蛇貴".substr(_start_at-1, 12);
}
// dump 貴人
//console.log('天盤:',gnm);
//console.log('貴人:',help_man2);
var xy = [[17,8],[17,3],[13,0],[8,0],[3,0],[0,3],[0,8],[0,13],[3,17],[8,17],[13,17],[17,13]];
for(var i = 0; i< 12; i++) {
var x = xy[i][1], y = xy[i][0];
ot[y] = ot[y].replaceAt(x, gnm[i]);
}
var xy = [[17,9],[17,4],[14,0],[9,0],[4,0],[0,4],[0,9],[0,14],[4,17],[9,17],[14,17],[17,14]];
for(var i = 0; i< 12; i++) {
var x = xy[i][1], y = xy[i][0];
ot[y] = ot[y].replaceAt(x, help_man2[i]);
}
})();
$('#output').html(ot.join("\n"));
}
$(document).ready(calc_qimen);
</script>
</head>
<body>
<div>
<form onsubmit="return false">
<table border="0" cellpadding="0" cellspacing="0" width="100%" style="display:none" id='frmInput'>
<tr>
<td colspan="4">
<input type="text" name="txtDate" style='border:1' />
</td>
<td>
<input type="button" value="當下" onclick="$('#cboDun :nth-child(1)').prop('selected', true);$('#cboKook :nth-child(1)').prop('selected', true);calc_now()" />
</td>
<td>
<input type="button" value="計算" onclick="calc()" />
</td>
</tr>
<tr>
<td colspan='2'><select id='cboDun' style='height:100%;width:100%'>
<option value='2' selected>自動遁數</option>
<option value='0'>陰遁</option>
<option value='1'>陽遁</option>
</select>
</td>
<td colspan='2'><select id='cboKook' style='height:100%;width:100%'>
<option value='0' selected>自動局數</option>
<option value='1'>一局</option>
<option value='2'>二局</option>
<option value='3'>三局</option>
<option value='4'>四局</option>
<option value='5'>五局</option>
<option value='6'>六局</option>
<option value='7'>七局</option>
<option value='8'>八局</option>
<option value='9'>九局</option>
</select>
</td>
<td colspan='2'><input type='button' style='height:100%;width:100%' value='重算' onclick='calc_qimen();'>
</td>
</tr>
<tr>
<script language="JavaScript">
(function() {
var a = ['年','月','日','時','分','秒'];
for(var i in a) {
document.write(
sprintf('<td><input type="button" value="+%s" onclick="tuneDate(this)" /></td>',a[i])
);
}
})();
</script>
</tr>
<tr>
<script language="JavaScript">
(function() {
var a = ['年','月','日','時','分','秒'];
for(var i in a) {
document.write(
sprintf('<td><input type="button" value="-%s" onclick="tuneDate(this)" /></td>',a[i])
);
}
})();
</script>
</tr>
</table>
<div onclick="$('#frmInput').toggle()"><pre id="info"></pre></div>
<div><pre id="output"></pre></div>
<pre style="visibility:hidden" id="tpltable">+ | | +
+----+----+----+
| | | |
| | | |
| | | |
| | | |
-+----+----+----+-
| | | |
| | | |
| | | |
| | | |
-+----+----+----+-
| | | |
| | | |
| | | |
| | | |
+----+----+----+
+ | | +</pre>
</form>
</div>
</body>
</html>