Jump to content

javascript to autoit


 Share

Recommended Posts

// Calculate the offset to convert to Vana'diel time for the current time zone

// I, unfortunately, have no idea who originally came up with the following.

// Note that it has since been converted to GMT.

// Earth time: 2002/06/23 15:00:00 GMT

// Vana'diel time: 0898/02/01 00:00:00 (VST?)

var vanaTime = (898 * 360 + 30) * 24 * 60 * 60 / 25;

var baseDay = new Date();

baseDay.setUTCFullYear(2002, 5, 23); // Set date to 2002-06-23

baseDay.setUTCHours(15, 0, 0, 0); // Set time to 15:00:00.0000

vanadielOffset = Math.floor(baseDay.getTime() / 1000) - vanaTime;

function VanadielDate(time) {

// Vana'diel time runs 25 times faster than our time - this is the time

// in "Vana'diel milliseconds" actually.

if (time == null) {

time = new Date().getTime();

} else if (time instanceof Date) {

time = time.getTime();

}

// Calculate Vana'diel time - the +500 after time rounds this to the

// nearest second, making it less jittery.

this.time = (Math.floor((time + 500) / 1000) - vanadielOffset) * 25;

// We only display the day, hour, and minute in the little clock

this.day = Math.floor(this.time / 86400);

this.year = Math.floor(this.day / 360);

this.month = Math.floor((this.day % 360) / 30) + 1;

this.dayMonth = (this.day % 30) + 1;

this.dayWeek = this.day % 8;

this.hour = Math.floor(this.time / 3600) % 24;

this.minute = Math.floor(this.time / 60) % 60;

this.second = Math.floor(this.time) % 60;

// calculate the current moon phase - unlike the current

// day of the week, this isn't nice and happily rooted at 0

// moonphase = 0 - full moon

// moonphase = 42 - new moon

this.moonPhase = (this.day + 26) % 84;

// translate that value into a percentage value

this.moonPercent = ((42 - this.moonPhase) * 100) / 42;

// negative values are "waxing" and backwards

this.waxing = false;

if (this.moonPercent < 0) {

this.waxing = true;

this.moonPercent = Math.abs(this.moonPercent);

}

// Now make it an interger

this.moonPercent = Math.floor(this.moonPercent + 0.5);

// Translate the phase into one of the twelve phases.

if (this.moonPhase >= 38)

this.basicMoonPhase = Math.floor((this.moonPhase - 38) / 7);

else

this.basicMoonPhase = Math.floor((this.moonPhase + 46) / 7);

}

can this be EXACTLY coverted and used in Autoit, i love Autoit and dont wanna use anything else.

thanks

Edited by Aceguy
Link to comment
Share on other sites

Sure. Why don't you give it a try?

Free Internet Tools: DebugBar, AutoIt IE Builder, HTTP UDF, MODIV2, IE Developer Toolbar, IEDocMon, Fiddler, HTML Validator, WGet, curl

MSDN docs: InternetExplorer Object, Document Object, Overviews and Tutorials, DHTML Objects, DHTML Events, WinHttpRequest, XmlHttpRequest, Cross-Frame Scripting, Office object model

Automate input type=file (Related)

Alternative to _IECreateEmbedded? better: _IECreatePseudoEmbedded  Better Better?

IE.au3 issues with Vista - Workarounds

SciTe Debug mode - it's magic: #AutoIt3Wrapper_run_debug_mode=Y

Doesn't work needs to be ripped out of the troubleshooting lexicon. It means that what you tried did not produce the results you expected. It begs the questions 1) what did you try?, 2) what did you expect? and 3) what happened instead?

Reproducer: a small (the smallest?) piece of stand-alone code that demonstrates your trouble

Link to comment
Share on other sites

ok i have done it :)

except i cant translate this to autoit.... please help

* To see how the "phase counter" stacks up to a percent, run the following

* Perl 1-liner:

*

* perl -e 'for($p=0;$p<84;$p++){print "$p = ".int((abs((42-$p)*100/42)+0.5))."\% (wa".($p<42?"n":"x")."ing)\n";}'

*

* Simple, huh?

NO.!!! lol

Link to comment
Share on other sites

ok here is the full javascript.

/ * Contains methods for obtaining the current Vana'diel based on the

* current system time.

*/

// Name of Vana'diel days - note that these are simple text phrases and not English.

// This is so that you can later localize them.

var VanadielDays = [ "fire", "earth", "water", "wind", "ice", "thunder", "light", "dark" ];

// Name of moon phases, same note as the days

var VanadielMoonPhases = [ "new", "waxingcrescent.1", "waxingcrescent.2", "firstquarter", "waxinggibbous.1", "waxinggibbous.2", "full", "waninggibbous.1", "waninggibbous.2", "lastquarter", "waningcrescent.1", "waningcrescent.2" ];

// Offset in milliseconds between the starting Vana'diel epoch and the UNIX epoch

var vanadielOffset = 0;

{

// Calculate the offset to convert to Vana'diel time for the current time zone

// I, unfortunately, have no idea who originally came up with the following.

// Note that it has since been converted to GMT.

// Earth time: 2002/06/23 15:00:00 GMT

// Vana'diel time: 0898/02/01 00:00:00 (VST?)

var vanaTime = (898 * 360 + 30) * 24 * 60 * 60 / 25;

var baseDay = new Date();

baseDay.setUTCFullYear(2002, 5, 23); // Set date to 2002-06-23

baseDay.setUTCHours(15, 0, 0, 0); // Set time to 15:00:00.0000

vanadielOffset = Math.floor(baseDay.getTime() / 1000) - vanaTime;

}

/*

* Creates a new Vana'diel Date.

* If time is a non-null integer, than it will be used as the current Earth date

* to calculate Vana'diel time for.

*

* Once you've created the object, you can access the following properties on it

* to get the current Vana'diel time:

*

* time - number of Vana'diel seconds since the current Vana'diel epoch

* day - current number of days since the Vana'diel epoch - you

* probably want dayMonth

* year - current Vana'diel Year

* month - current Vana'diel Month

* dayMonth - current day of the month

* dayWeek - day of the week - convert to an elemental string with the

* VanadielDays array or create your own

* hour - current Vana'diel hour

* minute - current Vana'diel minutes

* second - current Vana'diel seconds

* moonPhase - moon phase "counter", more on this later

* moonPercent - moon phase as a percentage (always positive)

* waxing - true if the moon is currently waxing

* basicMoonPhase - a number 0 through 12 marking the simple moon phase

* positions - use the VanadielMoonPhases array to translate

* this to a specific phase

*

* The "moonPhase" variable is a number from 0 to 83 that represents which day

* in the moon phase we are currently in.

*

* To see how the "phase counter" stacks up to a percent, run the following

* Perl 1-liner:

*

* perl -e 'for($p=0;$p<84;$p++){print "$p = ".int((abs((42-$p)*100/42)+0.5))."\% (wa".($p<42?"n":"x")."ing)\n";}'

*

* Simple, huh?

*

* === MOON PHASES ===

* 80- 2 == 90%(Wax) - 95%(Wane) - Full

* 3-16 == 93%(Wane) - 62%(Wane) - Waning Gibbous

* 17-23 == 60%(Wane) - 45%(Wane) - Last Quarter

* 24-37 == 43%(Wane) - 12%(Wane) - Waning Crescent

* 38-44 == 10%(Wane) - 5%(Wax) - New Moon

* 45-58 == 7%(Wax) - 38%(Wax) - Waxing Crescent

* 59-65 == 40%(Wax) - 55%(Wax) - First Quarter

* 66-79 == 57%(Wax) - 88%(Wax) - Waxing Gibbous

*/

function VanadielDate(time) {

// Vana'diel time runs 25 times faster than our time - this is the time

// in "Vana'diel milliseconds" actually.

if (time == null) {

time = new Date().getTime();

} else if (time instanceof Date) {

time = time.getTime();

}

// Calculate Vana'diel time - the +500 after time rounds this to the

// nearest second, making it less jittery.

this.time = (Math.floor((time + 500) / 1000) - vanadielOffset) * 25;

// We only display the day, hour, and minute in the little clock

this.day = Math.floor(this.time / 86400);

this.year = Math.floor(this.day / 360);

this.month = Math.floor((this.day % 360) / 30) + 1;

this.dayMonth = (this.day % 30) + 1;

this.dayWeek = this.day % 8;

this.hour = Math.floor(this.time / 3600) % 24;

this.minute = Math.floor(this.time / 60) % 60;

this.second = Math.floor(this.time) % 60;

// calculate the current moon phase - unlike the current

// day of the week, this isn't nice and happily rooted at 0

// moonphase = 0 - full moon

// moonphase = 42 - new moon

this.moonPhase = (this.day + 26) % 84;

// translate that value into a percentage value

this.moonPercent = ((42 - this.moonPhase) * 100) / 42;

// negative values are "waxing" and backwards

this.waxing = false;

if (this.moonPercent < 0) {

this.waxing = true;

this.moonPercent = Math.abs(this.moonPercent);

}

// Now make it an interger

this.moonPercent = Math.floor(this.moonPercent + 0.5);

// Translate the phase into one of the twelve phases.

if (this.moonPhase >= 38)

this.basicMoonPhase = Math.floor((this.moonPhase - 38) / 7);

else

this.basicMoonPhase = Math.floor((this.moonPhase + 46) / 7);

}

so ,no, i dont know what perl is

Link to comment
Share on other sites

because in making my own game time clock in auto it.

so i can make my own times for airships, but have found the code to do it but its in perl code, which means nothig to me.

this is why i have ask the autoit people for some help.

im still just a beginner, alothough i have managed to get the clock working properly.

now need to add a moon phase calculator.

Link to comment
Share on other sites

Hello,

the perl thing would look like this:

For $p = 0 To 83
    ConsoleWrite("$p=" & int((abs((42-$p)*100/42)+0.5)) & "% (wa")
    If $p < 42 Then
        ConsoleWrite("n")
    Else
        ConsoleWrite("x")
    EndIf
    ConsoleWrite("ing)" & @LF)
Next

ciao

Xandl

Link to comment
Share on other sites

I finally did it. :) thanks to all that helped. (the moonphase is still incomplete but working)

#include <GUIConstants.au3>
#include <date.au3>

Global $d3
$Form1 = GUICreate("Form1", 300, 100, 200, 200,-1,BitOR($WS_EX_TOOLWINDOW, $WS_EX_WINDOWEDGE,$WS_EX_TOPMOST ) )

$Label1 = GUICtrlCreateLabel("Label1", 10, 50, 400, 60)
GUICtrlSetFont(-1,24)



$Label2 = GUICtrlCreateLabel("label2",150,5,150,30)
GUICtrlSetFont(-1,18)
GUISetState(@SW_SHOW)

$Label3=GUICtrlCreateLabel('',5,5,140,25)

$vanaTime  = (898 * 360 + 30) * 24 * 60 * 60  /25
$d1=  _DateDiff( 's',"1970/01/01 00:0:00", "2002/06/23 15:0:00")
$vanadielOffset=$d1-$vanaTime



do      
$time=floor((_DateDiff( 's',"1970/01/01 00:0:00", @year&"/"&@MON&"/"&@MDAY&" "&@HOUR&":"&@MIN&":"&@SEC)+0.5-$vanadielOffset)*25)




    $day = floor($time / 86400);
    $year = floor($day / 360);
    $month = floor((mod($day , 360) / 30)) + 1;
    $dayMonth = mod($day , 30) + 1;
    $dayWeek = mod($day , 8);
    $hour = floor(mod(($time / 3600),24));
    $minute = floor(mod(($time / 60) , 60));
    $second = floor(mod($time , 60));


if $hour <10 Then
    $hour = '0'& $hour
    EndIf
if $minute < 10 then 
    $minute = '0'& $minute
EndIf

;MsgBox(0,"",$day,0)
$Find = Find($day-373930+3)
;MsgBox(0,"",$Find,0)
if $Find='a' then 
    $Find='Firesday'
    GUICtrlSetColor($Label2,0xFF0000)
elseif $Find='b' then 
    $Find='Earthsday'
    GUICtrlSetColor($Label2,0xAAAA00)
elseif $Find='c' then 
    $Find='Watersday'
    GUICtrlSetColor($Label2,0x0000DD)
elseif $Find='d' then 
    $Find='Windsday'
    GUICtrlSetColor($Label2,0x00AA22)
elseif $Find='e' then 
    $Find='Iceday'
    GUICtrlSetColor($Label2,0x7799FF)
elseif $Find='f' then 
    $Find='Lightningday'
    GUICtrlSetColor($Label2,0xAA00AA)
elseif $Find='g' then 
    $Find='Lightsday'
    GUICtrlSetColor($Label2,0xAAAAAA)
elseif $Find='h' then 
    $Find='Darksday'
    GUICtrlSetColor($Label2,0x333333)
EndIf

$moonPhase = mod(($day + 26),  84);

$moonPercent = ((42 - $moonPhase) * 100) / 42

$moonPercent=Floor($moonPercent+0.5)

$waxing = false
    if $moonPercent < 0 Then
    $waxing = true
    $moonPercent = abs($moonPercent)
EndIf

 if $moonPhase >= 38 Then
    $basicMoonPhase = floor(($moonPhase - 38) / 7)
   else
    $basicMoonPhase = floor(($moonPhase + 46) / 7)
    EndIf
    
if $basicMoonPhase =0 Then
    $mp='New Moon'
ElseIf $basicMoonPhase =1 Then
    $mp='Waxing Crescent'
ElseIf $basicMoonPhase =2 Then
    $mp='First Quarter'
ElseIf $basicMoonPhase =3 Then
    $mp='Waxing Gibbous'
EndIf

GUICtrlSetData($Label3,$moonPercent&"% "&$mp)

GUICtrlSetData($Label2,$Find)


GUICtrlSetData($Label1,$dayWeek&"/"&$month&"/"&$year&"  "&$hour&":"&$minute)

sleep(1000)
until 1 = 0


Func Find($Num)
    Local $Count = 0, $Var
    For $i = 1 To $Num
        $Count += 1
        If $Count = 9 Then $Count = 1
        $Var = Chr(96 + $Count)
   Next
    Return $Var
EndFunc
Link to comment
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now
 Share

  • Recently Browsing   0 members

    • No registered users viewing this page.
×
×
  • Create New...