ActionScript 3.0 for the Lunder Algorithm

package com.feiruo.Calendar.LunderCalendar
{

/*
*@ClassName: package:com.feiruo.Calendar.LunderCalendar::LunarDate
*@INTRO: Calculating lunar and solar terms and other settings.
*@Author: feiruo
*@Language: ActionScript 3.0
*@SDKVersion: Flash Player 11.2
*@Date: 2015.08.24
*/

public class LunarDate
{
private var num_info:Array =
                                         [0x4bd8, 0x4ae0, 0xa570, 0x54d5, 0xd260, 0xd950,
                                          0x5554, 0x56af, 0x9ad0, 0x55d2, 0x4ae0, 0xa5b6,
                                          0xa4d0, 0xd250, 0xd255, 0xb54f, 0xd6a0, 0xada2,
                                          0x95b0, 0x4977, 0x497f, 0xa4b0, 0xb4b5, 0x6a50,
                                          0x6d40, 0xab54, 0x2b6f, 0x9570, 0x52f2, 0x4970,
                                          0x6566, 0xd4a0, 0xea50, 0x6a95, 0x5adf, 0x2b60,
                                          0x86e3, 0x92ef, 0xc8d7, 0xc95f, 0xd4a0, 0xd8a6,
                                          0xb55f, 0x56a0, 0xa5b4, 0x25df, 0x92d0, 0xd2b2,
                                          0xa950, 0xb557, 0x6ca0, 0xb550, 0x5355, 0x4daf,
                                          0xa5b0, 0x4573, 0x52bf, 0xa9a8, 0xe950, 0x6aa0,
                                          0xaea6, 0xab50, 0x4b60, 0xaae4, 0xa570, 0x5260,
                                          0xf263, 0xd950, 0x5b57, 0x56a0, 0x96d0, 0x4dd5,
                                          0x4ad0, 0xa4d0, 0xd4d4, 0xd250, 0xd558, 0xb540,
                                          0xb6a0, 0x95a6, 0x95bf, 0x49b0, 0xa974, 0xa4b0,
                                          0xb27a, 0x6a50, 0x6d40, 0xaf46, 0xab60, 0x9570,
                                          0x4af5, 0x4970, 0x64b0, 0x74a3, 0xea50, 0x6b58,
                                          0x5ac0, 0xab60, 0x96d5, 0x92e0, 0xc960, 0xd954,
                                          0xd4a0, 0xda50, 0x7552, 0x56a0, 0xabb7, 0x25d0,
                                          0x92d0, 0xcab5, 0xa950, 0xb4a0, 0xbaa4, 0xad50,
                                          0x55d9, 0x4ba0, 0xa5b0, 0x5176, 0x52bf, 0xa930,
                                          0x7954, 0x6aa0, 0xad50, 0x5b52, 0x4b60, 0xa6e6,
                                          0xa4e0, 0xd260, 0xea65, 0xd530, 0x5aa0, 0x76a3,
                                          0x96d0, 0x4afb, 0x4ad0, 0xa4d0, 0xd0b6, 0xd25f,
                                          0xd520, 0xdd45, 0xb5a0, 0x56d0, 0x55b2, 0x49b0,
                                          0xa577, 0xa4b0, 0xaa50, 0xb255, 0x6d2f, 0xada0,
                                          0x4b63, 0x937f, 0x49f8, 0x4970, 0x64b0, 0x68a6,
                                          0xea5f, 0x6b20, 0xa6c4, 0xaaef, 0x92e0, 0xd2e3,
                                          0xc960, 0xd557, 0xd4a0, 0xda50, 0x5d55, 0x56a0,
                                          0xa6d0, 0x55d4, 0x52d0, 0xa9b8, 0xa950, 0xb4a0,
                                          0xb6a6, 0xad50, 0x55a0, 0xaba4, 0xa5b0, 0x52b0,
                                          0xb273, 0x6930, 0x7337, 0x6aa0, 0xad50, 0x4b55,
                                          0x4b6f, 0xa570, 0x54e4, 0xd260, 0xe968, 0xd520,
                                          0xdaa0, 0x6aa6, 0x56df, 0x4ae0, 0xa9d4, 0xa4d0,
                                          0xd150, 0xf252, 0xd520];

private var solarMonth:Array = [31,28,31,30,31,30,31,31,30,31,30,31];
private var Gan:Array = ["甲","乙","丙","丁","戊","己","庚","辛","壬","癸"];

private var nStr1 = new Array(‘日‘,‘一‘,‘二‘,‘三‘,‘四‘,‘五‘,‘六‘,‘七‘,‘八‘,‘九‘,‘十‘);
private var nStr2 = new Array(‘初‘,‘十‘,‘廿‘,‘卅‘);

private var Zhi:Array = ["子","丑","寅","卯","辰","巳","午","未","申","酉","戌","亥"];
private var Animals:Array = ["猴","鸡","狗","猪","鼠","牛","虎","兔","龙","蛇","马","羊"];
private var monthName:Array = ["JAN","FEB","MAR","APR","MAY","JUN","JUL","AUG","SEP","OCT","NOV","DEC"];
private var solarTerm:Array = ["小寒","大寒","立春","雨水","惊蛰","春分","清明","谷雨","立夏","小满","芒种","夏至","小暑","大暑","立秋","处暑","白露","秋分","寒露","霜降","立冬","小雪","大雪","冬至"];
private var TermInfo:Array =                                                                     [0,21208,42467,63836,85337,107014,128867,150921,173149,195551,218072,240693,263343,285989,308563,331033,353350,375494,397447,419210,440795,462224,483532,504758];

private var cyear:Number;
private var cmonth:Number;
private var cday:Number;
private var isLeap:Boolean;
private var nianzhu:String;
private var yuezhu:String;
private var rizhu:String;
private var jie:String;
private var y:Number,m:Number,d:Number;

public function LunarDate(myDate:Date)
{
var leap:Number = 0;
var temp:Number = 0;

y = myDate.getFullYear();
m = myDate.getMonth();
d = myDate.getDate();

var offset=(Date.UTC(y,m,d)-Date.UTC(1900,0,31))/86400000;

for (var i = 1900; i<2100 && offset>0; i++)
{
temp = lYearDays(i);
offset -= temp;
}
if (offset<0)
{
offset += temp;
i--;
}

cyear = i;
leap = leapMonth(i);
isLeap = false;

for (var j = 1; j<13 && offset>0; j++)
{
if (leap>0 && j == (leap+1) && isLeap == false)
{
--j;
isLeap = true;
temp = leapDays(cyear);
}
else
{
temp = monthDays(cyear,j);
}
if (isLeap == true && j == (leap+1))
{
isLeap = false;
}
offset -= temp;
}
if (offset == 0 && leap>0 && j == leap+1)
{
if (isLeap)
{
isLeap = false;
}
else
{
isLeap = true;
--j;
}
}
if (offset<0)
{
offset += temp;
--j;
}
cmonth = j;
cday = offset + 1;

var cY,cM,cD;

m<2 ? cY = cyclical(y-1900+36-1) : cY = cyclical(y-1900+36);

cM = cyclical((y-1900)*12+m+12);

var tmp1 = sTerm(y,m * 2);
var tmp2 = sTerm(y,m * 2 + 1);

if (d == tmp1)
{
jie = solarTerm[m * 2];
}
else
{
if (d == tmp2)
{
jie = solarTerm[m * 2 + 1];
}
else
{
jie = "";
}
}
this.jie = jie;

var term2 = sTerm(y,2);
var firstNode = sTerm(y,m * 2);
if (m == 1 && d>=term2)
{
cY = cyclical(y-1900+36);
}

if ((d+1)>=firstNode)
{
cM = cyclical((y-1900)*12+m+13);
}
var dayCyclical = Date.UTC(y,m,1,0,0,0,0) / 86400000 + 25567 + 10;
cD = cyclical(dayCyclical+d-1);
nianzhu = cY;
yuezhu = cM;
rizhu = cD;
}
public function getAnimal():String
{
return Animals[cyear%12];
}
public function getLunarYear():Number
{
return cyear;
}
public function getLunarMonth():Number
{
return cmonth;
}
public function getLunarDay():Number
{
return cday;
}
public function get_Month():Number
{
return m + 1;
}
public function getJNianZhu():String
{
return nianzhu;
}
public function getYueZhu():String
{
return yuezhu;
}
public function getRiZhu():String
{
return rizhu;
}
public function getJieQi():String
{
return jie;
}
private function lYearDays(y):Number
{
var sum:Number = 348;

for (var i = 0x8000; i>0x8; i >>= 1)
{
sum += (num_info[y-1900] & i) ? 1 : 0;
}

return sum + leapDays(y);
}

//small month or big Month;
private function leapDays(y):int
{
if (leapMonth(y))
{
return num_info[y - 1899] & 0xf == 0xf?30:29;
}
else
{
return 0;
}
}
private function leapMonth(y):int
{
var lm = num_info[y - 1900] & 0xf;
return lm == 0xf?0:lm;
}
private function monthDays(y, m):int
{
return num_info[y - 1900] & 0x10000 >> m?30:29;
}
private function sTerm(y, n)
{
var offDate = new Date((31556925974.7*(y-1900)+TermInfo[n]*60000)+Date.UTC(1900, 0, 6, 2, 5));
return (offDate.getUTCDate());
}
private function solarDays(y, m):uint
{
if (m == 1)
{
return y % 4 == 0 && y % 100 != 0 || y % 400 == 0?29:28;
}
else
{
return solarMonth[m];
}
}
private function cyclical(num):String
{
return Gan[num % 10] + Zhi[num % 12];
}

}

}
时间: 2024-10-10 04:28:20

ActionScript 3.0 for the Lunder Algorithm的相关文章

在 Flash ActionScript 2.0 中调用 Javascript 方法

本篇文章由:http://xinpure.com/call-the-javascript-method-in-flash-actionscript-2-0/ 在 Flash ActionScript 2.0 中调用 Javascript 方法 最近在工作中,有个这样的需求: 要从 Flash ActionScript 2.0 中调用网页上的 Javascript 方法 这是一个关于 Flash 和 Javascript 交互的问题. 在 ActionScript 2.0 中调用外部 javasc

ActionScript 3.0日期与时间管理(Date类)

/*Flash中,Date类管理着日期和时间信息.要获取   当前日期,可以新建一个Date对象   */var now:Date =new Date();trace (now);     /*输出当前时间和日期,格式如:                  Sun Jul 27 19:45:57 GMT+0800 2014  */ /*以上代码中,Date对象中包括了当前的秒.分.小时.  星期数.日.月.年.时区等信息...如果仅需要返  回星期值和日期值,而不返回时间或时区,可以使用Date

ActionScript 3.0数组操作

var arr:Array=new Array();arr=["a","b","c"];  //赋初值,注意这里的即使单个字符赋值使用的是""trace(arr[1]);       //获取成员信息trace(arr.length);    //获取数组中所包含的元素的个数 //接下来使用for循环逐个输出数组的每一个元素,这也称为数组的遍历var loopTime:int=arr.length;for (var i:int

[ActionScript 3.0] 正则表达式

正则表达式: 正则表达式最早是由数学家Stephen Kleene在对自然语言的递增研究成果的基础上,于1956提出来的.具有完整语法的正则表达式,主要使用在字符串的格式的匹配方面上,后来也逐渐应用到信息技术领域.不同的编程语言对于正则表达式有细微的不同,ActionScript 3.0是按照ECMAScript第3版语言规范(ECMA-262)中的定义实现正则表达式. 熟悉windows操作系统读者,应该知道windows中是怎样查找文件的.不错,使用通配符“*”用来匹配任意字符,“?”用来匹

ActionScript 3.0 加载外部SWF素材资源MovieClip,SimpleButton不支持鼠标事件

我们用flash buidler加载素材一般有三种途径: 1.SWC,这种方式会增大SWF的大小 2.flash cs项目关联 3.SWF专门放素材资源通过Loader方式加载 今天发现通过SWF加载方式有个问题要加载的素材如下图: A:是一个MC,里面放了一个B:mc,C:SimpleButton 问题:加载进A后对A添加鼠标事件如CLICK事件,单击B或C时没有反映? 开始我的加载方式是这样的: 目录结构如图: 代码如下: 1 package 2 { 3 import flash.displ

[ActionScript 3.0] as3处理xml的功能和遍历节点

as3比as2处理xml的功能增强了N倍,获取或遍历节点非常之方便,类似于json对像的处理方式. XML 的一个强大功能是它能够通过文本字符的线性字符串提供复杂的嵌套数据.将数据加载到 XML 对象时,ActionScript 会分析数据并将其分层结构加载到内存(如果 XML 数据格式有误,它会发送运行时错误). 利用 XML 和 XMLList 对象的运算符和方法可以轻松遍历 XML 数据的结构. 1.读取外部 XML 文档 可以使用 URLLoader 类从 URL 加载 XML 数据.若

[ActionScript 3.0] 与js通信

AS3代码,可做文档类; 1 package { 2 import flash.display.Sprite; 3 import flash.events.*; 4 import flash.external.ExternalInterface; 5 import flash.text.TextField; 6 import flash.utils.Timer; 7 import flash.text.TextFieldType; 8 import flash.text.TextFieldAut

[ActionScript 3.0] flash中的颜色

在 Flash 中,颜色就是一串特殊的数字,一个颜色值可以是0到16,777,215中的任意数值,这就是24位(bit)色彩.也许大家会问,为什么有16,777,216(256*256*256)种颜色值,因为 Flash 使用 RGB 颜色值,意味着每个颜色都可以由红(red),绿(green),蓝(blue)三种颜色构成.这三种合成色的每一种都是一个从0到255中的数,所以,对于每个红黄蓝都有256种可能的深度,结果会有约1,678万种颜色. 这个系统之所以叫做24位颜色是因为要使用8位(0或

[ActionScript 3.0] AS3 深入理解Flash的安全沙箱Security Domains

简介 如果你还没有与复杂的的安全域(security domain)和应用程序域(application domain)问题打过交道,那么你真是个幸运的家伙.当你在加载外部内容(然后他们开始播放)的时候,默认的设置工作的很好,你甚至不知道他们的存在. 但是某些时候你可能需要控制默认设置以外的更多行为和功能,这样你就会遇到前面所说的问题.你也许会困扰于Security.allowDomain和crossdomain.xml文件的区别,又或者你想要深究关于安全性的最佳实践.如果是这样,那么这篇文章就