Five Prayer Times

Finally, today i decide to enter this month jfxstudio challenge, here is my submission:
Five Prayer times

Muslims are supposed to perform five prayers every day. Each prayer is given a certain prescribed time in which it must be performed. this application show current time & five prayer time for muslim specific for my current city (Bandung, latitude:6.54 & longitude: 107.36), with polar clock as visualization.

to compute prayer time, i use formula that described in this site http://tanzil.info/praytime/doc/calculation/.

source code:

number of characters: 2987 (without white spaces/characters ;) )
number of lines: 195
you can find more readable code at my blog

var h;
var m;
var s;
var date;
var day;
var month;
var year;
var cal;
var tm = Timeline{
    repeatCount:Timeline.INDEFINITE
    keyFrames:[
            KeyFrame{
                    time:100ms
                    action:function(){
                            cal = cc();
                            s = (cal.get(Calendar.SECOND) + (cal.get(Calendar.MILLISECOND) as Float)/1000)/60;
                            m = (cal.get(Calendar.MINUTE) + s)/60;
                            h = (cal.get(Calendar.HOUR) + m)/12
                    }
            }]
}

var sdf = new SimpleDateFormat("yyyy-MM-dd");
var to = sdf.format(Calendar.getInstance().getTime());
function cc(){
    var date = new Date();
    def c = Calendar.getInstance();
    c.setTime(new Date());c
}

def p = Math.PI;
class PC extends CustomNode{
    var cX = 10;
    var cY = 10;
    var sw = 11;
    var r = 50;
    var sl = 250;
    var ml = 90;
    var hl = 30;
    var t = "";

    override function create(){
    Group{
        opacity:0.85
        content:[
            Arc {
                centerX:cX, centerY:cY
                radiusX:r, radiusY:r
                startAngle:90 length:bind -sl + sw*360.0/(4*p*r)
                stroke:Color.GREEN
                fill:null
                strokeWidth:sw
            }

            Arc {
                centerX:cX centerY:cY
                radiusX:r-17 radiusY:r-17
                startAngle:90 length:bind -ml + sw*360.0/(4*p*r)
                stroke:Color.RED
                fill:null
                strokeWidth:sw
            }

            Arc {
                centerX:cX centerY:cY
                radiusX:r-34 radiusY:r-34
                startAngle:90 length:bind -hl + sw*360.0/(4*p*r)
                stroke:Color.BLUE
                fill:null
                strokeWidth:sw
            }

            Label {
                translateY:cY + r + 10
                translateX:cX-r/2;
                text:t
                textFill:Color.GOLD
                }
          ]
        }
    }
}
def JD = 2440588;
def d2r = p/180;
def r2d = 57.2957795;
var dt = DateTime{};
var jd = JD + Math.floor(dt.instant/(1000*60*60*24));
var D = jd-2451545.0;
var g = 357.529 + 0.98560028*D;
var q =  280.459 + 0.98564736* D;
var L = q + 1.915* sn(g) + 0.020*sn(2*g);
var R = 1.00014 - 0.01671*cs(g) - 1.4e-4*cs(2*g);
var e = 23.439 - 3.6e-7* D;
var RA = atn2(cs(e)*sn(L),cs(L))/15;
var d = asn(sn(e)*sn(L));
var EqT = q/15 - RA;
def TZ = 7;
def lat = 6.54;
def lng = 107.36;
var dz = fx(12 + TZ - lng/15 - EqT);
var dh = [th(Math.floor(dz)),t6((dz - Math.floor(dz))*60)];
var f = dz - T(18);
var fh = [th(Math.floor(f)),t6((f - Math.floor(f))*60)];
var i  = dz + T(17);
var ih = [th(Math.floor(i)),t6((i - Math.floor(i))*60)];
var a = dz + 1.0/15*acs((sn(actn(1.0 + tn(lat-d)))-(sn(lat)*sn(d)))/(cs(lat)*cs(d)));
var ah = [th(Math.floor(a)),t6((a - Math.floor(a))*60)];
var mg = dz + T(0.8333);
var mh = [th(Math.floor(mg)),t6((mg - Math.floor(mg))*60)];

function T(a) { 1.0/15*acs(-sn(a*1.0)-sn(lat)*sn(d)/cs(lat)*cs(d)) }
function fx(a:Float){
    var b = a - 24.0 * Math.floor(a / 24.0);
    if (b < 0) b =  b + 24.0;
    b
}
function th (h:Integer) { if (h>12) h-12 else h }
function t6(m:Integer) { if(m>60) m-60 else m }
function sn (a) { Math.sin(a*d2r)}
function cs (a) { Math.cos(a*d2r)}
function tn (a) { Math.tan(a*d2r)}
function actn (a){ Math.atan(1.0/a)*r2d }
function acs(a) { Math.acos(a*1.0)*r2d}
function asn(a) { Math.asin(a*1.0)*r2d}
function atn(a) { Math.atan(a*1.0)*r2d}
function atn2 (y,x) { Math.atan2(y*1.0, x*1.0)*r2d }

public function run () {
    tm.play();
    var scene = Scene {
        width: 500
        height: 500
        fill: Color.BLACK

        content: [
            ImageView {
                image: Image {
                    url: "http://iwidget.googlecode.com/files/m.png"
                }
            }

            PC{
                r:120
                cX: 150
                cY: 160
                sw:15
                sl:bind 360*s
                ml: bind 360*m
                hl:bind 360*h
                t: to
            }

            PC{
                cX: 340
                cY: 60
                ml: fh[1]*6
                hl: fh[0]*30
                t: "Fajr: {fh[0]}:{fh[1]} am"
            }

            PC{
                cX: 340
                cY: 200
                ml: dh[1]*6
                hl: dh[0]*30
                t: "Dzuhr: {dh[0]}:{dh[1]} am"
            }

            PC{
                r:70
                cX: 340
                cY: 360
                ml: ah[1]*6
                hl: ah[0]*30
                t: "Ashr: {ah[0]}:{ah[1]} pm"
            }

            PC{
                cX: 190
                cY: 400
                ml: mh[1]*6
                hl: mh[0]*30
                t: "Maghrib: {mh[0]}:{mh[1]} pm"
            }

            PC{
                cX: 70
                cY: 400
                ml: ih[1]*6
                hl: ih[0]*30
                t: "Isya: {ih[0]}:{ih[1]} pm"
            }]
    }
    def stage =  Stage {scene: scene}stage.visible = true;
}

Posted in animation, challenge

Go to Source

Leave a Reply

You must be logged in to post a comment.