Jump to content

Leaderboard

Popular Content

Showing content with the highest reputation on 01/17/2014 in all areas

  1. trancexx, You make pointed comments like that - you can expect to get pointed responses. And please moderate your language in future - there is absoutely no need to use such terms in a programming forum. M23
    2 points
  2. Ascend4nt

    GUI Fun!

    Updated 2014-01-17: - New _LineTraverser UDF with floating point math to replace the old (now renamed _LineTraverserB) - Added Pacman examples 2014-01-17 'Hotfix': - Fixed majorly borked Atan2() code Lakes, thanks but I've about had enough of the PacGUI! haha.. Ah, and here's the final Pacman animated GUI example. The 'final' dot doesn't seem to always line up, and squares happen to draw better than ellipses so you'll have to make do - or improve it as you wish *Edit: Note, this example will eat up memory quickly. This is due to a bug in Windows where it doesn't properly dispose of previous Regions that have been applied to a Window. Unfortunately, there's no way to get at the region once Window takes over it either... In the future I may create a versoin with the 3 different 'animations' as 3 different GUI's and try swapping them in and out. It should alleviate the memory leak problem.. Pacman (Animated) Line-Traversing GUI, The Final Act #include "_LineTraverser.au3" #include "_GUIShapes.au3" #include <WinAPI.au3> ; ======================================================================================================== ; <LineTraverserPacmanExample.au3> ; ; Simple Example of using the <_LineTraverser.au3> and <_GuiShapes.au3> UDF's ; ; A little red-ball displays, while a 'Pacman' GUI moves towards it along a line ; An actual line is drawn onscreen to show the path from 'Pacman' to the red-ball target GUI, ; and then the PacGUI moves to it in $iStep increments. ; ; Additional Functions: ; _DrawPlainOldLine() ; Draws a line on the screen ; _DrawPacmanDottedLine() ; Draws a special Pacman-Dotted line ; _GUIApplyPacman() ; Converts a square GUI into a Pacman-shaped GUI. Regions are recreated ; ; each time, based on the input ; Atan2_Radians() ; An 'atan2()' vfunction ; ; Author: Ascend4nt ; ======================================================================================================== Global Const $iStep = 2 Local $hPacMan, $hDestCircle, $iExt, $iStepsTaken = 0, $iMode = 0, $fLineAngleRads = 0 Local $iXTarget, $iYTarget, $aLineTraverser ; Create the Pacman GUI and apply shape to it $hPacMan = GUICreate("", 81, 81, Random(0, @DesktopWidth - 20, 1), Random(0, @DesktopHeight - 20, 1), 0x80000000, 0x08000080 + 0x20) GUISetBkColor(Random(0x111111, 0xFFFFFF, 1), $hPacMan) _GUIApplyPacman($hPacMan, 0) ; Pink-dot GUI $hDestCircle = _CircleGUICreate(1, 1, 17, 0, 17, 0xDE8394) ; Set initial target point $iXTarget = Random(0, @DesktopWidth - 20, 1) $iYTarget = Random(0, @DesktopHeight - 20, 1) ; Source/Target are same to start off with $aLineTraverser = _LineTraverserCreate($iXTarget, $iYTarget, $iXTarget, $iYTarget) ; Move windows to start positions WinMove($hPacMan, '', $aLineTraverser[0], $aLineTraverser[1]) ; + Center of hollow circle, - half of target circle WinMove($hDestCircle, '', $iXTarget + 40 - 8, $iYTarget + 40 - 8) ; Transparency on 'seeker' circle WinSetTrans($hPacMan, '', 150) ; Show both GUIs, and put on top of all windows WinSetState($hDestCircle, '', @SW_SHOWNOACTIVATE) WinSetState($hPacMan, '', @SW_SHOWNOACTIVATE) WinSetOnTop($hPacMan, '', 1) WinSetOnTop($hDestCircle, '', 1) While 1 ; Exit on 'ESC' keypress (in down state) If BitAND(_WinAPI_GetAsyncKeyState(0x1B), 0x8000) Then ExitLoop ; < 10 ms sleep with an API call ;DllCall("kernel32.dll",'none','Sleep','dword',4) ; Slower allows to see mouth transitions better Sleep(10) If Not _LineTraverserStep($aLineTraverser, $iStep) Then $iExt = @extended ; Was there movement? Then moooove If $iExt Then WinMove($hPacMan, '', $aLineTraverser[0], $aLineTraverser[1]) EndIf $aPos = WinGetPos($hPacMan) ; Debug check. Should never be hit, so long as Window is moved to each step (including any last steps - see @extended) If $iXTarget <> $aPos[0] Or $iYTarget <> $aPos[1] Then ConsoleWrite("Mismatch: TargetX:" & $iXTarget & ", TraverserX:" & $aLineTraverser[0] & ", Current X:" & $aPos[0] & _ ", TargetY:" & $iYTarget & ", TraverserY:" & $aLineTraverser[1] & ", Current Y:" & $aPos[1] & ", @extended:" & $iExt & @CRLF) EndIf ; A little extra sleep to make it clear we've reached our destination. DllCall("kernel32.dll", 'none', 'Sleep', 'dword', 6) ; Now we'll set a new destination (with a visible line) Dim $iXTarget = Random(0, @DesktopHeight - 20, 1), $iYTarget = Random(0, @DesktopHeight - 20, 1) ;ConsoleWrite("New target: X: " & $iXTarget & ", Y: " & $iYTarget & ", FROM X: " & $aLineTraverser[0] & ", Y: " & $aLineTraverser[1] & @CRLF) ; Create a new Line-Traverser (no need to explicitly destroy the last one, it was just an array of numbers) $aLineTraverser = _LineTraverserCreate($aLineTraverser[0], $aLineTraverser[1], $iXTarget, $iYTarget) ; + Center of hollow circle, - center of target circle WinMove($hDestCircle, '', $iXTarget + 40 - 8, $iYTarget + 40 - 8) ; Apply Pacman GUI with calculated angle of line it should point towards $fLineAngleRads = Atan2_Radians($iYTarget - $aLineTraverser[1], $iXTarget - $aLineTraverser[0]) _GUIApplyPacman($hPacMan, $fLineAngleRads) ; Draw the line on-screen to give a visual indicator of the path that the hollow circle should take ; (note that the line will be overwritten by ANY screen activity, but that's fine for the example) ; Add 40 for the center of the hollow circle GUI _DrawPacmanDottedLine($aPos[0] + 40 - 1, $aPos[1] + 40 - 1, $iXTarget + 40 - 1, $iYTarget + 40 - 1) ; Or ;~ _DrawPlainOldLine($aPos[0] + 40 - 1, $aPos[1] + 40 - 1, $iXTarget + 40 - 1, $iYTarget + 40 - 1) Else $iStepsTaken += 1 If $iStepsTaken > 7 Then $iMode += 1 ;If $iMode > 2 Then $iMode = 0 ; Function masks off the needed bits _GUIApplyPacman($hPacMan, $fLineAngleRads, $iMode) $iStepsTaken = 0 EndIf WinMove($hPacMan, '', $aLineTraverser[0], $aLineTraverser[1]) EndIf WEnd Exit ; ================================================================================================================= ; Func _DrawPlainOldLine($iX1, $iY1, $iX2, $iY2) ; ; Draws a white line on the screen ; ; Author: Ascend4nt ; ================================================================================================================= Func _DrawPlainOldLine($iX1, $iY1, $iX2, $iY2) Local $hDC, $hPen, $hPenOld, $hBrush, $hBrushOld ; Get DC to screen $hDC = _WinAPI_GetDC(0) ; Create Pen (outline) [PS_SOLID = 0, PS_DASH = 1, PS_DOT = 2, PS_DASHDOT = 3, PS_DASHDOTDOT = 4, PS_NULL = 5] ; Seems no styles other than PS_SOLID work even if Width is <= 1, at least on the desktop DC in Win7 $hPen = _WinAPI_CreatePen(0, 3, 0xFFFFFF) ; Alternatively, get a Stock Pen.. (width 1 unfortunately) ; WHITE_PEN = 6, BLACK_PEN = 7, NULL_PEN = 8 ;$hPen = _WinAPI_GetStockObject(6) ; Create (or Get) Brush (fill) ; Doesn't seem to make a difference for Lines actually ; WHITE_BRUSH = 0, BLACK_BRUSH = 4, HOLLOW_BRUSH = 5 $hBrush = _WinAPI_GetStockObject(0) ; BS_SOLID = 0, BS_HOLLOW = 1, BS_HATCHED = 2 ;~ $hBrush = _WinAPI_CreateBrushIndirect(1, 0xFFFFFF, 0) ; Select Pen and Brush (saving old) $hPenOld = _WinAPI_SelectObject($hDC, $hPen) $hBrushOld = _WinAPI_SelectObject($hDC, $hBrush) _WinAPI_DrawLine($hDC, $iX1, $iY1, $iX2, $iY2) ; Select the old Brush and Pen back _WinAPI_SelectObject($hDC, $hBrushOld) _WinAPI_SelectObject($hDC, $hPenOld) ; Clean up pen & brush and then release DC _WinAPI_DeleteObject($hPen) ; _WinAPI_DeleteObject($hBrush) ; No need to delete Stock Objects _WinAPI_ReleaseDC(0, $hDC) Return True EndFunc ;==>_DrawPlainOldLine ; ================================================================================================================= ; Func _DrawPacmanDottedLine($iX1, $iY1, $iX2, $iY2) ; ; Draws a series of 'dots' on a given line. ; ; Unfortunately, in my tests, the Ellipse creates a bunch of artifacts, so the Rectangle is used to plot ; the dots. Some versions of Pacman look like they use squares anyway.. ; ; Author: Ascend4nt ; ================================================================================================================= Func _DrawPacmanDottedLine($iX1, $iY1, $iX2, $iY2) Local $hDC, $hPen, $hPenOld, $hBrush, $hBrushOld Local $aLineTraverser ; Line traverser for plotting Pac dots.. $aLineTraverser = _LineTraverserCreate($iX1, $iY1, $iX2, $iY2) ; Get DC to screen $hDC = _WinAPI_GetDC(0) ; Create Pen (outline) [PS_SOLID = 0, PS_DASH = 1, PS_DOT = 2, PS_DASHDOT = 3, PS_DASHDOTDOT = 4, PS_NULL = 5] $hPen = _WinAPI_CreatePen(5, 3, 0x00FFFF) ; Create (or Get) Brush (fill) ; [BS_SOLID = 0, BS_HOLLOW = 1, BS_HATCHED = 2] ; {Hatch Styles} HS_HORIZONTAL = 0, HS_VERTICAL = 1, HS_FDIAGONAL = 2, ; HS_BDIAGONAL = 3, HS_CROSS = 4, HS_DIAGCROSS = 5, HS_API_MAX = 12 $hBrush = _WinAPI_CreateBrushIndirect(0, 0xFFFF00, 0) ; Select Pen and Brush (saving old) $hPenOld = _WinAPI_SelectObject($hDC, $hPen) $hBrushOld = _WinAPI_SelectObject($hDC, $hBrush) ; We try to avoid drawing on the target circle While _LineTraverserStepsRemaining($aLineTraverser) > 30 ; Steps of 20 _LineTraverserStep($aLineTraverser, 20) ;~ _WinAPI_Ellipse($hDC, _WinAPI_CreateRect($aLineTraverser[0] - 5, $aLineTraverser[1] - 5, $aLineTraverser[0] + 5, $aLineTraverser[1] + 5)) _WinAPI_Rectangle($hDC, _WinAPI_CreateRect($aLineTraverser[0] - 5, $aLineTraverser[1] - 5, $aLineTraverser[0] + 5, $aLineTraverser[1] + 5)) WEnd ; Select the old Brush and Pen back _WinAPI_SelectObject($hDC, $hBrushOld) _WinAPI_SelectObject($hDC, $hPenOld) ; Clean up pen & brush and then release DC _WinAPI_DeleteObject($hPen) _WinAPI_DeleteObject($hBrush) _WinAPI_ReleaseDC(0, $hDC) Return True EndFunc ;==>_DrawPacmanDottedLine ; ================================================================================================================= ; Func _GUIApplyPacman($hGUI, $fAngleInRads, $nMouthMode = 0) ; ; Takes a GUI and applies a 'Pacman' shape to it. The angle of Pacman's mouth is based upon the $fAngleinRads ; variable. It also has 3 modes - mouth closed, partially open, or open to 90 degrees (rotated to face given angle) ; ; Parameters: ; $hGUI = GUI that will have a 'Pacman' Region applied to it ; $fAngleInRads = The Angle which the 'mouth' should center on, given in Radians (Degrees * PI / 180) ; $iMouthMode = 'Mode' of mouth: 0 (default) = 90 degree span, 1 = 40 degree span, 2 = closed (basic circle Region) ; ; Returns: ; Success: 1, @error = 0 ; Failure: 0, @error set ; ; Author: Ascend4nt ; ================================================================================================================= Func _GUIApplyPacman($hGUI, $fAngleInRads, $iMouthMode = 0) Local $aPos, $aVertices, $hEllipseRgn = 0, $hPieRegion = 0 Local $iCenterXY, $fMouthAngleRad $aPos = WinGetPos($hGUI) If @error Then Return SetError(1, 0, 0) $iCenterXY = $aPos[2] / 2 $iMouthMode = BitAND($iMouthMode, 3) Switch $iMouthMode Case 1 ; 20 Degrees $fMouthAngleRad = 0.34906585 Case 2 ; No adjustment necessary, we're using a full circle $fMouthAngleRad = 0 Case Else ; 45 Degrees $fMouthAngleRad = 0.78539816 EndSwitch Do ; Create a Basic Elliptical region $hEllipseRgn = _WinAPI_CreateEllipticRgn(_WinAPI_CreateRect(0, 0, $aPos[2], $aPos[3])) If $hEllipseRgn = 0 Then SetError(10) ExitLoop EndIf ; Everything OTHER than Mode 2 gets a 'mouth' applied If $iMouthMode <> 2 Then #cs ;; -------------- ; Vertices array: ; --------------- ; These vertices make up the mouth. ; Note that the multipler should typically be Radius, not $aPos[2] as here, if we were creating a line ; to the circumference of the circle. However, that would cause a weird triangle-inside-a-circle effect ; when combining Regions (leaving whats known as a 'Chord' behind). So we overextend it and let ; Windows clip the line at the GUI borders, which does its job of covering up the outer parts of the circle ; ----------------------------------------------------------------------------------------------------- #ce Dim $aVertices[3][2] = [ _ [$iCenterXY, $iCenterXY], _ ; We over-extend the lines here ($aPos[2] is way longer than the radius) [$iCenterXY + $aPos[2] * Cos($fAngleInRads - $fMouthAngleRad), $iCenterXY + $aPos[2] * Sin($fAngleInRads - $fMouthAngleRad)], _ [$iCenterXY + $aPos[2] * Cos($fAngleInRads + $fMouthAngleRad), $iCenterXY + $aPos[2] * Sin($fAngleInRads + $fMouthAngleRad)] _ ] ; Create the Pacman Pie area $hPieRegion = _WinAPI_CreatePolygonRgn($aVertices, 0, -1, 1) If $hPieRegion = 0 Then SetError(12) ExitLoop EndIf ; Combine, put resulting region in $hEllipseRgn. (RGN_AND = 1, RGN_OR = 2, RGN_XOR = 3, RGN_DIFF = 4) If Not _WinAPI_CombineRgn($hEllipseRgn, $hEllipseRgn, $hPieRegion, 4) Then SetError(14) ExitLoop EndIf ; Don't need this anymore (already combined with the Region injected into the GUI) _WinAPI_DeleteObject($hPieRegion) EndIf ; Set the region into the GUI. (GUI will then own it so there's no need to delete it) If Not _WinAPI_SetWindowRgn($hGUI, $hEllipseRgn, True) Then SetError(16) ExitLoop EndIf Return 1 Until 1 Local $iErr = @error, $iExt = @extended ; Cleanup _WinAPI_DeleteObject($hEllipseRgn) _WinAPI_DeleteObject($hPieRegion) Return SetError($iErr, $iExt, 0) EndFunc ;==>_GUIApplyPacman ; ================================================================================================================= ; Func Atan2_Radians($fY, $fX) ; ; Atan2() implementation, based on Wikipedia description. See notes ; ; atan2() differs from atan() in that it maps atan(Y/X) to correct Quadrants ; ; References: ; https://en.wikipedia.org/wiki/Atan2 ; https://en.wikipedia.org/wiki/Radian ; https://en.wikipedia.org/wiki/Cosine#Unit-circle_definitions ; ; Returns: Atan2() result in radians (for the flipped counterclockwise system) ; ; Author: Ascend4nt ; ================================================================================================================= Func Atan2_Radians($fY, $fX) Local Const $f_PI = 3.14159265 Local Const $f_PIHalf = $f_PI / 2 ;~ ConsoleWrite("Atan2 entry, $fY = " & $fY & ", $fX = " & $fX & @CRLF) If $fX = 0 Then ; Technically 'undefined' If $fY = 0 Then Return 0.0 If $fY < 0 Then Return -$f_PIHalf Else ; $fY >= 0 Return $f_PIHalf EndIf EndIf Local $fTmp = ATan($fY / $fX) If $fX < 0 Then If $fY < 0 Then Return $fTmp - $f_PI Else Return $fTmp + $f_PI EndIf Else ; $fX > 0 ; already checked == 0 at start Return $fTmp EndIf EndFunc ;==>Atan2_Radians
    2 points
  3. BASS Function Library This library is a wrapper for the powerful Bass.DLL and add-ons (which increase the functionality of Bass.DLL). Bass.DLL is ideal for use in your applications and scripts if you want an easy way to play a vast range of music and sound files formats while keeping dependency on just Bass.dll and it's add-ons (which in turn maximizes compatibility and minimizes extra requirements for your software to run.), while retaining a small file size. The UDFs included with the release are: Bass The basic Bass library. Required with all (most) add-on libraries. Provides playback of many sound files (and streams). BassASIO (By eukalyptus) BASSASIO is basically a wrapper for ASIO drivers, with the addition of channel joining, format conversion and resampling. BassCD Allows for digital streaming and ripping of audio CDs along with analog playback support. BassFX (By eukalyptus/BrettF) An extension providing several effects, including tempo & pitch control. BassEnc (By eukalyptus) An extension that allows BASS channels to be encoded using any command-line encoder with STDIN support (LAME/OGGENC/etc), or any ACM codec. Also features Shoutcast and Icecast stream sourcing, and PCM/WAV file writing. BassSFX Provides a complete set of functions to include support for winamp, sonique, bassbox, and Windows Media Player visualization plugins. BassTags Provides a simple way to retrieve ID3 tags from stream handles. BassCB/Bass_EXT (ProgAndy) This is for advanced users. BassCB allows the playback of streams in AutoIt. BassVST Allows use of VST effect plugins. Download The download includes all of the wrapper and constants, the original download, examples for all of the previously mentioned add-ons, sample audio files (6 channel audio files also included), sample visualization plugins for BassSFx and more. Current Version: 9 Size: 7360KB AutoIt Version Required: 3.3.2.0 Changelog: /> Fixed _BassRecordGetInputName (updated production versions) +> Added Memory Examples of Bass (Thanks ProgAndy and UEZ) +> Added BassVST (Not 100% complete) +> Added BassFX Examples showing use of most functions: Pitch.au3 Reverse.au3 Tempo.au3 /> Fixed error with calling _BASS_ErrorGetCode in BASSCD.au3 /> Fixed startup functions return the wrong value (Thanks ProgAndy!) +> Added helper functions _BASS_ChannelSetVolume, _BASS_ChannelGetVolume (Thanks ProgAndy) Download Link: https://www.autoitscript.com/forum/files/file/493-basszip/ Previous versions are not supported. Patches: Patch 1 "BASS_ASIO" Fixes issues with BASS ASIO and examples. Patch 2 "BASS_FX/BASS" Fixes issues with BASS FX and BASS.
    1 point
  4. Here is the rewritten version of this UDF. See my comments HERE. Please test the shit out of this thing. It was a major headache, and I want to make sure I didn't miss something. Thanks! Update 2013/05/28 - Fixed missing @error return in _Zip_ItemExists - Clarified a few @error return value meanings - Added an additional check and @error code to _Zip_DeleteItem - Clarified some of the header notes, esp regarding behavior on XP Update 2011/12/08 - Fixed recursion in ListAll function Update 2011/12/07 - Fixed recursion error in CountAll function - updated objects to conform to new COM syntax (parenthesis req'd for methods) Update 2011/07/01 - Reverted change to AddItem function - **Adding an item directly to a sub folder on XP will FAIL Update 2011/06/30 - Fixed traversing namespaces on Windows XP - Added note that overwrite fails on XP Update 2011/01/13 - Fixed bug adding items to a subfolder that doesn't exist yet Update 2010/08/27 - Fixed bug with trailing 's Update 2010/07/16 - Better error reporting in _Zip_AddItem function Update 2010/07/02 - Added credits. - Added trancexxx's suggestion to remove any left over temporary directories. - Replaced some StringTrim calls with cleaner StringRegExpReplace calls. - Moved a few repetitive lines of code into functions. - Moved a few repetitive lines of code into functions. - Moved a few repetitive lines of code into functions. =========================== _Zip.au3
    1 point
  5. Function Reference _GUIResourcePic.au3 Functions related to the image control in the GUI. Sintax: _GUICtrlPic_Create( FileName, Left, Top [, Width [, Height [, Style [, ExStyle ]]]]]] ) _GUICtrlPic_SetImage( controlID, FileName [, FixSize ]]) _GUICtrlPic_Delete( controlID ) _GUICtrlPic_Release( controlID ) _GUICtrlPic_SetState( controlID, state ) _GUICtrlPic_GetInfo( FileName or Control ID ) Supports: ; Images in the format: .bmp, .jpg, .png, .gif {animated} and other formats of files for resources (.exe, .dll, .ocx, .cpl...). ; For the "resources", use the "FileName" in this format: "MyFile.ext|RessourceName|ResourceType". ; It can be a URL path as well! Download: Version: 1.8.2012.2600b _GUIResourcePic_(RedirectLink).html 17.0k (Previous downloads: 140) Example_Include_HD_GIF_(RedirectLink).html 36.08k (Previous downloads: 135) Note: Added new function! I've made significant changes in the code, including the syntax of some functions! Now uses GDI+ to render the images. Example of use is included! Sample: CPU in 0,60%. http://www.youtube.com/watch?v=NZZB-G9C1Kg Direct download: _GUIResourcePic.mp4 Fixes: $GUI_GIFSTART ; If image is GIF animated, start/resume animation! $GUI_GIFSTOP ; If image is GIF animated, stop/pause animation! ;----> Style (GIS = Gif Image Styles) $GIS_ASPECTRATIOFIX ; Fix the image size based on aspect ratio. $GIS_HALFTRANSPARENCY ; The images are rendered with the window background color. This Style is default. $GIS_FULLTRANSPARENCY ; The frames are rendered in full transparency independent of the background color of the window! Note: This Style consumes more CPU because the exstyle $WS_EX_TRANSPARENT is added to each frame in real time! Not valid if the image does not have transparency! ;----> Default Style to _GUICtrlPic_Create()! $GIS_SS_DEFAULT_PIC = BitOR($GIS_HALFTRANSPARENCY, $SS_NOTIFY) ;----> ExStyle (GIS_EX = Gif Image Extended Styles) $GIS_EX_DEFAULTRENDER ; To use _GUIImageList_Draw in rendering of images, use less CPU. This ExStyle is default! $GIS_EX_CTRLSNDRENDER ; The frames is render using GUICtrlSendMsg, but consumes much more CPU!!! Note: If you use this ExStyle, only $GRP_FULLTRANSPARENCY is used for rendering images! 1.02b 09/05/2012 -> After updating the code, the images with transparency were not being shown as they should, changed code again!09/05/2012 -> Fixes in the _GUICtrlPic_SetImage() function, the measures were not being updated according to the parameter FixSiz , identified by @Belini, thank you!Regards, João Carlos.
    1 point
  6. New release. 19 June 2013 (1.0.0.4) There is a relation with this topic SQLite ListView and BLOB demo but I decided to start a completely new Topic because the approach is considerably different from the two previous examples which were only kick-offs to this demo. This example shows how binary objects can be recognized natively in a database BLOB field without having to link to other fields that may contain information of the data object. In the demo I used 2 approaches for native recognition 1. For multi-type binary objects, the file name is added in the header of the BLOB Multi-type object can be images or any other kind of file. Because of the object header data, there is no need to identify the object in the binary code 2. Objects without header data, this works only for images, an algorithm will identify the type of image. The demo shows what happens whit objects which are not identifiable, see example 5. Credits to: 1. trancexx: GIFAnimation.au3 '?do=embed' frameborder='0' data-embedContent>> 2. smashly: _ImageResize() Resizes and converts different graphicformats 3. rover: Customize Draw of Listview rows Optimizations of WS_NOTIFY I also thank rover for giving a second method to resolve the image space issue. I implemented the one proposed by KaFu, because very simple to implement 4. KaFu: Solved the Listview issue with image space in Columns one. 5. jchd: For some hints and background info on SQLite 6. Yashied: WinAPIEx.au3 '?do=embed' frameborder='0' data-embedContent>> new release. Version 1.0.0.4 What's new: - added fully generic Add, Edit, Add/Copy, Delete and Find buttons. With fully generic I mean, you don't have to bother about the table content, GUI field inputs will populate accoring to the table definition. - Added Field validation, also according to how the columns were defined in the table. (see GUI dynamic input validation for more information) tested a thousand times... on W7 and WXP 32/64 For a working example you have to download 2 files (see links in between the horizontal lines: SQLite GreenCan_demo BLOB in Listview 1.0.0.4.zip GreenCan_demo2.zip (if you already did, don't mind downloading it again) Note: For the Edit GUI, you will notice that sometimes one field is not editable, marked as (*PK) in the description. The field is a 'Primary Key autoincrement'. When appending the row, the PK will automatically increment, therefore it is not allowed to edit the field. Other fields mared (*) cannot be empty, you can only save the row if these fields contain data. In the case (*PK) is editable, you have to put unique data for the Primary key. If you do a copy/add without changing the field content, you will get a not unique Error. Special case: I don't allow empty primary key (NULL), while SQLite does, but it's pretty useless anyhow because you can only have 1 NULL in a Primary key. I have also included a very small non BLOB database, for example 0, to show that the generic edit/add works also here. SQLite GreenCan_demo BLOB in Listview 1.0.0.4.zip and don't forget to download this zip file to complete the required files for the demo http://users.telenet.be/GreenCan/AutoIt/GreenCan_demo2.zip I let you explore the demo and please give me feedback. GreenCan
    1 point
  7. tim292stro

    Solar Position UDF

    Hi, I've been building up an AutoIt home automation script over the past months and one script I just finished this weekend I thought I'd share. This function allows you to calculate your sun-rise, sun-set, and solar-noon times for a given latitude and longitude - plus it allows you to calculate the current relative position of the sun to your position. The original code was JavaScrip from a NOAA website, they have graciously allowed me to convert it to AutoIt Script, so long as I reference the website that I obtained the code from which is: http://www.esrl.noaa.gov/gmd/grad/solcalc/ I will make the same disclaimer that NOAA makes regarding accuracy: “this calculator function is for ‘entertainment only’ – the author’s cannot be held accountable for accuracy issues and bugs in critical systems” Here is the UDF (select all and save as "SunPosition.au3" in your include folder...): #include-once #include <array.au3> #include <Math.au3> #include <Date.au3> ; #INDEX# ======================================================================================================================= ; Title .........: SunPosition ; AutoIt Version : 3.3.6++ ; Language ......: English ; Description ...: Function that allows the sun's postion to be calculated relative to a geographical position (lat/long) ; ; Author(s) .....: Tim Strommen (tim292stro), original Javascript source from NOAA "http://www.esrl.noaa.gov/gmd/grad/solcalc/" ; Dll(s) ........: N/A ; =============================================================================================================================== ; #CONSTANTS# =================================================================================================================== Global Const $Pi = 4 * ATan(1) Global Const $MonthLength[12] = [31, 28, 31, 30, 31, 30, 31, 31, 30, 31, 30, 31] Global Const $MonthFullName[12] = ["January", "February", "March", "April", "May", "June", "July", "August", "September", "October", "November", "December"] Global Const $MonthAbrev[12] = ["Jan", "Feb", "Mar", "Apr", "May", "Jun", "Jul", "Aug", "Sep", "Oct", "Nov", "Dec"] ; =============================================================================================================================== ; #CURRENT# ===================================================================================================================== ;_GetSolarAstronimicalData ; =============================================================================================================================== ; #FUNCTION# ==================================================================================================================== ; Name...........: _GetSolarAstronimicalData ; Description ...: Calculate the position of the sun relative to a position on earth for a given time/date. ; Syntax.........: _GetSolarAstronimicalData ( $Latitude, $Longitude, $Month, $MDay, $Year, $TimeZone, $Hour, $Minute, $Second, $DST ) ; Parameters ....: $Latitude - The Latitude portion of the earth position to calculate the sun's position relative to (float) ; $Longitude - The Latitude portion of the earth position to calculate the sun's position relative to (float) ; $Month - The month of the year you are calculating for (numeric-string: "1-12") ; $MDay - The day of the month you are calculating for (numeric-string: "1-31") ; $Year - The year you are calculating for (numeric-string: "-2000 to 3000") ; $TimeZone - The time zone you are calculating for (numeric-string: "-11 to 12") ; $Hour - Optional! The hour you are calculating for in 24-hrs (numeric-string: "0-23") ; $Minute - Optional! The minute you are calculating for (numeric-string: "00-59") ; $Second - Optional! The second you are calculating for (numeric-string: "00-59") ; $DST - Optional! Is Daylight Saving's Time in effect? (boolean) ; Return values .: Success - Returns an array with the following values: ; 0 = Element count. If count = 3, then only items 1-3 available. If count = 6, then all elements available) ; 1 = Sunrise time "07:12" 24-hr time, or "07:12 Jul 17" if position is near international date line ; 2 = Solar Noon "13:16:46" 24-hr time with seconds. Higest point of sun in sky. ; 3 = Sunset time "19:22" 24-hr time, or "19:22 Jul 19" if position is near international date line ; 4 = Sun Azimuth in degrees relative to computed position (0deg = true north, 180deg = true south, 90deg = East, 270 = West) ; 5 = Sun Elevation is degrees relative to computed position at sea-level ; 6 = Ambient light disposition (possibilities: Day, Civil Twilight, Nautical Twilight, Astronomical Twilight, Night) ; Author ........: Tim Strommen (tim292stro) ; Modified.......: ; Remarks .......: Again, special thanks to NOAA for allowing re-use of their code!! See: "http://www.esrl.noaa.gov/" ; Related .......: ; Link ..........: ; Example .......: Yes ; =============================================================================================================================== Func _GetSolarAstronimicalData ( $AstroLat = "", $AstroLong = "", $AstroMonth = "", $AstroDay = "", $AstroYear = "", $AstroTimeZone = "", $AstroHour = "", $AstroMinute = "", $AstroSecond = "", $AstroDST = False ) Local $AstroBeginAT, $AstroBeginNT, $AstroBeginCT, $AstroSunrise, $AstroSolarNoon, $AstroSunset, $AstroEndCT, $AstroEndNT, $AstroEndAT, $AstroSolarElevation, $AstroSolarAzimuth If ( $AstroLat = "" ) OR ( $AstroLong = "" ) Then ; Return current Greenwich, UK basic times with current solar position $AstroLat = "51.48" $AstroLong = "0.000000001" $AstroTimeZone = "0" $AstroMonth = @MON $AstroDay = @MDAY $AstroYear = @YEAR $AstroHour = @HOUR $AstroMinute = @MIN $AstroSecond = @SEC $RetunedArray = _SolarCalculate ( $AstroLat, $AstroLong, $AstroMonth, $AstroDay, $AstroYear, $AstroTimeZone, $AstroHour, $AstroMinute, $AstroSecond, $AstroDST, True ) Return $RetunedArray ElseIf $AstroHour = "" Then ; Just return the specified day's basic times, no current solar position $AstroHour = "12" $AstroMinute = "00" $AstroSecond = "00" $RetunedArray = _SolarCalculate ( $AstroLat, $AstroLong, $AstroMonth, $AstroDay, $AstroYear, $AstroTimeZone, $AstroHour, $AstroMinute, $AstroSecond, $AstroDST, False ) Return $RetunedArray Else ; Return both the basic times, plus the current solar position $RetunedArray = _SolarCalculate ( $AstroLat, $AstroLong, $AstroMonth, $AstroDay, $AstroYear, $AstroTimeZone, $AstroHour, $AstroMinute, $AstroSecond, $AstroDST, True ) Return $RetunedArray EndIf EndFunc ;==>_GetSolarAstronimicalData #cs ********** Developer Notice!!! ********** The following are the original NOAA Javascripts with minor modifications to support programmatic query instead of web-form query. The original Javascript text preceeds the AutoIt-v3 conversion and are provided with gracious permission from NOAA. The original webform and calculator is located at: "http://www.esrl.noaa.gov/gmd/grad/solcalc/" Thank you again NOAA!! -Tim S. <script type="text/javascript"> function calcTimeJulianCent(jd) { var T = (jd - 2451545.0)/36525.0 return T } #ce Func _CalcTimeJulianCent( $jd = 0 ) Local $Time = ( $jd - 2451545.0 ) / 36525.0 Return $Time EndFunc #cs function calcJDFromJulianCent(t) { var JD = t * 36525.0 + 2451545.0 return JD } #ce Func _CalcJDFromJulianCent ( $t = 0 ) Local $JD = $t * 36525.0 + 2451545.0 Return $JD EndFunc #cs function isLeapYear(yr) { return ((yr % 4 == 0 && yr % 100 != 0) || yr % 400 == 0); } #ce Func _isLeapYear ( $yr = 0 ) Return ( ( Mod ( $yr, 4 ) And Mod ($yr, 100 ) ) Or ( Mod ( $yr, 400 ) = 0 ) ) EndFunc #cs function calcDoyFromJD(jd) { var z = Math.floor(jd + 0.5); var f = (jd + 0.5) - z; if (z < 2299161) { var A = z; } else { alpha = Math.floor((z - 1867216.25)/36524.25); var A = z + 1 + alpha - Math.floor(alpha/4); } var B = A + 1524; var C = Math.floor((B - 122.1)/365.25); var D = Math.floor(365.25 * C); var E = Math.floor((B - D)/30.6001); var day = B - D - Math.floor(30.6001 * E) + f; var month = (E < 14) ? E - 1 : E - 13; var year = (month > 2) ? C - 4716 : C - 4715; var k = (isLeapYear(year) ? 1 : 2); var doy = Math.floor((275 * month)/9) - k * Math.floor((month + 9)/12) + day -30; return doy; } #ce Func _calcDoyFromJD ( $jd = 0 ) Local $z = Floor ( $jd + 0.5 ) Local $f = ( $jd + 0.5 ) - $z Local $A, $alpha, $B, $C, $D, $doy, $E, $day, $month, $year, $K If $z < 2299161 Then $A = $z Else $alpha = Floor ( ( $z - 1867216.25 ) / 36524.25 ) $A = $z + 1 + $alpha - Floor ( $alpha / 4 ) EndIf $B = $A + 1524 $C = Floor ( ( $B - 122.1 ) / 365.25 ) $D = Floor ( 365.25 * $C ) $E = Floor ( ( $B - $D ) / 30.6001 ) $day = $B - $D - Floor ( 30.6001 * $E ) + $f If $E < 14 Then $month = $E - 1 Else $month = $E - 13 EndIf If $month > 2 Then $year = $C - 4716 Else $year = $C - 4715 EndIf If _isLeapYear ( $year ) Then $K = 1 Else $K = 2 EndIf $doy = Floor ( ( 275 * $month ) / 9 ) - $K * Floor ( ( $month + 9 ) / 12 ) + $day - 30 Return $doy EndFunc #cs function radToDeg(angleRad) { return (180.0 * angleRad / Math.PI); } #ce Func _radToDeg ( $AngleRad = 0 ) Return 180.0 * $AngleRad / $Pi EndFunc #cs function degToRad(angleDeg) { return (Math.PI * angleDeg / 180.0); } #ce Func _degToRad ( $AngleDeg = 0 ) Return $Pi * $AngleDeg / 180.0 EndFunc #cs function calcGeomMeanLongSun(t) { var L0 = 280.46646 + t * (36000.76983 + t*(0.0003032)) while(L0 > 360.0) { L0 -= 360.0 } while(L0 < 0.0) { L0 += 360.0 } return L0 // in degrees } #ce Func _calcGeomMeanLongSun ( $t = 0 ) Local $L0 = 280.46646 + $t * ( 36000.76983 + $t * (0.0003032) ) While $L0 > 360.0 $L0 -= 360.0 WEnd While $L0 < 0.0 $L0 += 360.0 WEnd Return $L0 ; in degrees EndFunc #cs function calcGeomMeanAnomalySun(t) { var M = 357.52911 + t * (35999.05029 - 0.0001537 * t); return M; // in degrees } #ce Func _calcGeomMeanAnomalySun ( $t = 0 ) Local $M = 357.52911 + $t * (35999.05029 - 0.0001537 * $t ) Return $M ; in degrees EndFunc #cs function calcEccentricityEarthOrbit(t) { var e = 0.016708634 - t * (0.000042037 + 0.0000001267 * t); return e; // unitless } #ce Func _calcEccentricityEarthOrbit ( $t = 0 ) Local $e = 0.016708634 - $t * ( 0.000042037 + 0.0000001267 * $t ) Return $e ; unitless EndFunc #cs function calcSunEqOfCenter(t) { var m = calcGeomMeanAnomalySun(t); var mrad = degToRad(m); var sinm = Math.sin(mrad); var sin2m = Math.sin(mrad+mrad); var sin3m = Math.sin(mrad+mrad+mrad); var C = sinm * (1.914602 - t * (0.004817 + 0.000014 * t)) + sin2m * (0.019993 - 0.000101 * t) + sin3m * 0.000289; return C; // in degrees } #ce Func _calcSunEqOfCenter ( $t = 0 ) Local $m = _calcGeomMeanAnomalySun ( $t ) Local $mrad = _degToRad ( $m ) Local $sinm = Sin ( $mrad ) Local $sin2m = Sin ( $mrad + $mrad ) Local $sin3m = Sin ( $mrad + $mrad + $mrad ) Local $C = $sinm * ( 1.914602 - $t * ( 0.004817 + 0.000014 * $t ) ) + $sin2m * ( 0.019993 - 0.000101 * $t ) + $sin3m * 0.000289 Return $C EndFunc #cs function calcSunTrueLong(t) { var l0 = calcGeomMeanLongSun(t); var c = calcSunEqOfCenter(t); var O = l0 + c; return O; // in degrees } #ce Func _calcSunTrueLong ( $t = 0 ) Local $lo = _calcGeomMeanLongSun ( $t ) Local $c = _calcSunEqOfCenter ( $t ) Local $O = $lo + $c Return $O ; in degrees EndFunc #cs function calcSunTrueAnomaly(t) { var m = calcGeomMeanAnomalySun(t); var c = calcSunEqOfCenter(t); var v = m + c; return v; // in degrees } #ce Func _calcSunTrueAnomaly ( $t = 0 ) Local $m = _calcGeomMeanAnomalySun ( $t ) Local $c = _calcSunEqOfCenter ( $t ) Local $v = $m + $c Return $v EndFunc #cs function calcSunRadVector(t) { var v = calcSunTrueAnomaly(t); var e = calcEccentricityEarthOrbit(t); var R = (1.000001018 * (1 - e * e)) / (1 + e * Math.cos(degToRad(v))); return R; // in AUs } #ce Func _calcSunRadVector ( $t = 0 ) Local $v = _calcSunTrueAnomaly ( $t ) Local $e = _calcEccentricityEarthOrbit ( $t ) Local $R = ( 1.000001018 * ( 1 - $e * $e ) ) / ( 1 + $e * cos ( _degToRad ( $v ) ) ) Return $R ; in AUs EndFunc #cs function calcSunApparentLong(t) { var o = calcSunTrueLong(t); var omega = 125.04 - 1934.136 * t; var lambda = o - 0.00569 - 0.00478 * Math.sin(degToRad(omega)); return lambda; // in degrees } #ce Func _calcSunApparentLong ( $t = 0 ) Local $o = _calcSunTrueLong ( $t ) Local $omega = 125.04 - 1934.136 * $t Local $lambda = $o - 0.00569 - 0.00478 * Sin ( _degToRad ( $omega ) ) Return $lambda ; in degrees EndFunc #cs function calcMeanObliquityOfEcliptic(t) { var seconds = 21.448 - t*(46.8150 + t*(0.00059 - t*(0.001813))); var e0 = 23.0 + (26.0 + (seconds/60.0))/60.0; return e0; // in degrees } #ce Func _calcMeanObliquityOfEcliptic ( $t = 0 ) Local $seconds = 21.448 - $t * ( 46.8150 + $t * ( 0.00059 - $t * ( 0.001813 ) ) ) Local $e0 = 23.0 + ( 26.0 + ( $seconds / 60.0 ) ) / 60.0 Return $e0 ; in degrees EndFunc #cs function calcObliquityCorrection(t) { var e0 = calcMeanObliquityOfEcliptic(t); var omega = 125.04 - 1934.136 * t; var e = e0 + 0.00256 * Math.cos(degToRad(omega)); return e; // in degrees } #ce Func _calcObliquityCorrection ( $t = 0 ) Local $e0 = _calcMeanObliquityOfEcliptic ( $t ) Local $omega = 125.04 - 1934.136 * $t Local $e = $e0 + 0.00256 * Cos ( _degToRad ( $omega ) ) Return $e EndFunc #cs function calcSunRtAscension(t) { var e = calcObliquityCorrection(t); var lambda = calcSunApparentLong(t); var tananum = (Math.cos(degToRad(e)) * Math.sin(degToRad(lambda))); var tanadenom = (Math.cos(degToRad(lambda))); var alpha = radToDeg(Math.atan2(tananum, tanadenom)); return alpha; // in degrees } #ce Func _calcSunRtAscension ( $t = 0 ) Local $e = _calcObliquityCorrection ( $t ) Local $lambda = _calcSunApparentLong ( $t ) Local $tananum = ( Cos ( _degToRad ( $e ) ) * Sin ( _degToRad ( $lambda ) ) ) Local $tanadenom = ( Cos ( _degToRad ( $lambda ) ) ) Local $alpha = _radToDeg ( _atan2 ( $tananum, $tanadenom ) ) Return $alpha ; in degrees EndFunc #cs function calcSunDeclination(t) { var e = calcObliquityCorrection(t); var lambda = calcSunApparentLong(t); var sint = Math.sin(degToRad(e)) * Math.sin(degToRad(lambda)); var theta = radToDeg(Math.asin(sint)); return theta; // in degrees } #ce Func _calcSunDeclination ( $t = 0 ) Local $e = _calcObliquityCorrection ( $t ) Local $lambda = _calcSunApparentLong ( $t ) Local $sint = Sin ( _degToRad ( $e ) ) * Sin ( _degToRad ( $lambda ) ) Local $theta = _radToDeg ( ASin ( $sint ) ) return $theta ; in degrees EndFunc #cs function calcEquationOfTime(t) { var epsilon = calcObliquityCorrection(t); var l0 = calcGeomMeanLongSun(t); var e = calcEccentricityEarthOrbit(t); var m = calcGeomMeanAnomalySun(t); var y = Math.tan(degToRad(epsilon)/2.0); y *= y; var sin2l0 = Math.sin(2.0 * degToRad(l0)); var sinm = Math.sin(degToRad(m)); var cos2l0 = Math.cos(2.0 * degToRad(l0)); var sin4l0 = Math.sin(4.0 * degToRad(l0)); var sin2m = Math.sin(2.0 * degToRad(m)); var Etime = y * sin2l0 - 2.0 * e * sinm + 4.0 * e * y * sinm * cos2l0 - 0.5 * y * y * sin4l0 - 1.25 * e * e * sin2m; return radToDeg(Etime)*4.0; // in minutes of time } #ce Func _calcEquationOfTime ( $t = 0 ) Local $epsilon = _calcObliquityCorrection ( $t ) Local $l0 = _calcGeomMeanLongSun ( $t ) Local $e = _calcEccentricityEarthOrbit ( $t ) Local $m = _calcGeomMeanAnomalySun ( $t ) Local $y = Tan ( _degToRad ( $epsilon ) / 2.0 ) $y *= $y Local $sin2l0 = Sin ( 2.0 * _degToRad ( $l0 ) ) Local $sinm = Sin ( _degToRad ( $m ) ) Local $cos2l0 = Cos ( 2.0 * _degToRad ( $l0 ) ) Local $sin4l0 = Sin ( 4.0 * _degToRad ( $l0 ) ) Local $sin2m = Sin ( 2.0 * _degToRad ( $m ) ) Local $Etime = $y * $sin2l0 - 2.0 * $e * $sinm + 4.0 * $e * $y * $sinm * $cos2l0 - 0.5 * $y * $y * $sin4l0 - 1.25 * $e * $e * $sin2m Return _radToDeg ( $Etime ) * 4.0 ; in minutes of time EndFunc #cs function calcHourAngleSunrise(lat, solarDec) { var latRad = degToRad(lat); var sdRad = degToRad(solarDec); var HAarg = (Math.cos(degToRad(90.833))/(Math.cos(latRad)*Math.cos(sdRad))-Math.tan(latRad) * Math.tan(sdRad)); var HA = Math.acos(HAarg); return HA; // in radians (for sunset, use -HA) } #ce ;SunRise = Horizon+0.8333 Func _calcHourAngleSunrise( $lat, $solarDec ) Local $latRad = _degToRad ( $lat ) Local $sdRad = _degToRad ( $solarDec ) Local $HAarg = ( Cos ( _degToRad ( 90.833 ) ) / ( Cos ( $latRad ) * Cos ( $sdRad ) ) - Tan ( $latRad ) * Tan ( $sdRad ) ) Local $HA = ACos ( $HAarg ) Return $HA ; in radians for morning (for evening, use -HA) EndFunc ;CivilTwilight = (Horizon+6) < SunCenter < (Horizon+0.8333) Func _calcHourAngleCivilTwilight( $lat, $solarDec ) Local $latRad = _degToRad ( $lat ) Local $sdRad = _degToRad ( $solarDec ) Local $HAarg = ( Cos ( _degToRad ( 96.0 ) ) / ( Cos ( $latRad ) * Cos ( $sdRad ) ) - Tan ( $latRad ) * Tan ( $sdRad ) ) Local $HA = ACos ( $HAarg ) Return $HA ; in radians for morning (for evening, use -HA) EndFunc ;NauticalTwilight = (Horizon+12) < SunCenter < (Horizon+6) Func _calcHourAngleNauticalTwilight( $lat, $solarDec ) Local $latRad = _degToRad ( $lat ) Local $sdRad = _degToRad ( $solarDec ) Local $HAarg = ( Cos ( _degToRad ( 102.0 ) ) / ( Cos ( $latRad ) * Cos ( $sdRad ) ) - Tan ( $latRad ) * Tan ( $sdRad ) ) Local $HA = ACos ( $HAarg ) Return $HA ; in radians for morning (for evening, use -HA) EndFunc ;AstronimicalTwilight = (Horizon+18) < SunCenter < (Horizon+12) Func _calcHourAngleAstronimicalTwilight( $lat, $solarDec ) Local $latRad = _degToRad ( $lat ) Local $sdRad = _degToRad ( $solarDec ) Local $HAarg = ( Cos ( _degToRad ( 108.0 ) ) / ( Cos ( $latRad ) * Cos ( $sdRad ) ) - Tan ( $latRad ) * Tan ( $sdRad ) ) Local $HA = ACos ( $HAarg ) Return $HA ; in radians for morning ( for evening, use -HA ) EndFunc #cs function isNumber(inputVal) { var oneDecimal = false; var inputStr = "" + inputVal; for (var i = 0; i < inputStr.length; i++) { var oneChar = inputStr.charAt(i); if (i == 0 && (oneChar == "-" || oneChar == "+")) { continue; } if (oneChar == "." && !oneDecimal) { oneDecimal = true; continue; } if (oneChar < "0" || oneChar > "9") { return false; } } return true; } #ce Func _isNumber ( $inputval ) Return ( IsFloat ( $inputval ) Or IsNumber ( $inputval ) Or IsInt ( $inputval ) ) EndFunc #cs function zeroPad(n, digits) { n = n.toString(); while (n.length < digits) { n = '0' + n; } return n; } #ce Func _zeroPad ( $n, $digits ) $n = String ( $n ) While StringLen ( $n ) < $digits $n = "0" & $n WEnd Return $n EndFunc #cs function month(name, numdays, abbr) { this.name = name; this.numdays = numdays; this.abbr = abbr; } var monthList = new Array(); var i = 0; monthList[i++] = new month("January", 31, "Jan"); monthList[i++] = new month("February", 28, "Feb"); monthList[i++] = new month("March", 31, "Mar"); monthList[i++] = new month("April", 30, "Apr"); monthList[i++] = new month("May", 31, "May"); monthList[i++] = new month("June", 30, "Jun"); monthList[i++] = new month("July", 31, "Jul"); monthList[i++] = new month("August", 31, "Aug"); monthList[i++] = new month("September", 30, "Sep"); monthList[i++] = new month("October", 31, "Oct"); monthList[i++] = new month("November", 30, "Nov"); monthList[i++] = new month("December", 31, "Dec"); #ce ; Global variable defined at top of file... #cs function getJD() { var docmonth = document.getElementById("mosbox").selectedIndex + 1 var docday = document.getElementById("daybox").selectedIndex + 1 var docyear = readTextBox("yearbox", 5, 1, 0, -2000, 3000, 2009) if ( (isLeapYear(docyear)) && (docmonth == 2) ) { if (docday > 29) { docday = 29 document.getElementById("daybox").selectedIndex = docday - 1 } } else { if (docday > monthList[docmonth-1].numdays) { docday = monthList[docmonth-1].numdays document.getElementById("daybox").selectedIndex = docday - 1 } } if (docmonth <= 2) { docyear -= 1 docmonth += 12 } var A = Math.floor(docyear/100) var B = 2 - A + Math.floor(A/4) var JD = Math.floor(365.25*(docyear + 4716)) + Math.floor(30.6001*(docmonth+1)) + docday + B - 1524.5 return JD } #ce Func _getJD ( $CompJDMon = "", $CompJDDay = "", $CompJDYear = "" ) If ( ( _isLeapYear ( $CompJDYear ) ) And ( $CompJDMon = 2 ) ) Then If $CompJDDay > 29 Then $CompJDDay = 29 EndIf Else If $CompJDDay > $MonthLength[$CompJDMon] Then $CompJDDay = $MonthLength[$CompJDMon] EndIf EndIf If $CompJDMon <= 2 Then $CompJDYear -= 1 $CompJDMon += 12 EndIf Local $A = Floor ( $CompJDYear / 100 ) Local $B = 2 - $A + Floor ( $A / 4 ) Local $JD = Floor ( 365.25 * ( $CompJDYear + 4716 ) ) + Floor ( 30.6001 * ( $CompJDMon + 1 ) ) + $CompJDDay + $B - 1524.5 Return $JD EndFunc #cs function getTimeLocal() { var dochr = readTextBox("hrbox", 2, 1, 1, 0, 23, 12) var docmn = readTextBox("mnbox", 2, 1, 1, 0, 59, 0) var docsc = readTextBox("scbox", 2, 1, 1, 0, 59, 0) var docpm = document.getElementById("pmbox").checked var docdst = document.getElementById("dstCheckbox").checked if ( (docpm) && (dochr < 12) ) { dochr += 12 } if (docdst) { dochr -= 1 } var mins = dochr * 60 + docmn + docsc/60.0 return mins } #ce Func _getTimeLocal ( $CompHour = "", $CompMin = "", $CompSec = "", $CompDST = False ) If ( $CompDST ) Then $CompHour -= 1 EndIf Local $mins = $CompHour * 60 + $CompMin + $CompSec / 60.0 Return $mins EndFunc #cs function calcAzEl(output, T, localtime, latitude, longitude, zone) { var eqTime = calcEquationOfTime(T) var theta = calcSunDeclination(T) if (output) { document.getElementById("eqtbox").value = Math.floor(eqTime*100 +0.5)/100.0 document.getElementById("sdbox").value = Math.floor(theta*100+0.5)/100.0 } var solarTimeFix = eqTime + 4.0 * longitude - 60.0 * zone var earthRadVec = calcSunRadVector(T) var trueSolarTime = localtime + solarTimeFix while (trueSolarTime > 1440) { trueSolarTime -= 1440 } var hourAngle = trueSolarTime / 4.0 - 180.0; if (hourAngle < -180) { hourAngle += 360.0 } var haRad = degToRad(hourAngle) var csz = Math.sin(degToRad(latitude)) * Math.sin(degToRad(theta)) + Math.cos(degToRad(latitude)) * Math.cos(degToRad(theta)) * Math.cos(haRad) if (csz > 1.0) { csz = 1.0 } else if (csz < -1.0) { csz = -1.0 } var zenith = radToDeg(Math.acos(csz)) var azDenom = ( Math.cos(degToRad(latitude)) * Math.sin(degToRad(zenith)) ) if (Math.abs(azDenom) > 0.001) { azRad = (( Math.sin(degToRad(latitude)) * Math.cos(degToRad(zenith)) ) - Math.sin(degToRad(theta))) / azDenom if (Math.abs(azRad) > 1.0) { if (azRad < 0) { azRad = -1.0 } else { azRad = 1.0 } } var azimuth = 180.0 - radToDeg(Math.acos(azRad)) if (hourAngle > 0.0) { azimuth = -azimuth } } else { if (latitude > 0.0) { azimuth = 180.0 } else { azimuth = 0.0 } } if (azimuth < 0.0) { azimuth += 360.0 } var exoatmElevation = 90.0 - zenith // Atmospheric Refraction correction if (exoatmElevation > 85.0) { var refractionCorrection = 0.0; } else { var te = Math.tan (degToRad(exoatmElevation)); if (exoatmElevation > 5.0) { var refractionCorrection = 58.1 / te - 0.07 / (te*te*te) + 0.000086 / (te*te*te*te*te); } else if (exoatmElevation > -0.575) { var refractionCorrection = 1735.0 + exoatmElevation * (-518.2 + exoatmElevation * (103.4 + exoatmElevation * (-12.79 + exoatmElevation * 0.711) ) ); } else { var refractionCorrection = -20.774 / te; } refractionCorrection = refractionCorrection / 3600.0; } var solarZen = zenith - refractionCorrection; if ((output) && (solarZen > 108.0) ) { document.getElementById("azbox").value = "dark" document.getElementById("elbox").value = "dark" } else if (output) { document.getElementById("azbox").value = Math.floor(azimuth*100 +0.5)/100.0 document.getElementById("elbox").value = Math.floor((90.0-solarZen)*100+0.5)/100.0 if (document.getElementById("showae").checked) { showLineGeodesic("#ffff00", azimuth) } } return (azimuth) } #ce Func _calcAzEl ( $output, $T, $localtime, $latitude, $longitude, $zone ) Local $SolarReturnAzEl[1] = [0] Local $SolarLightStatus, $SolarEquationOfTime, $SolarDeclination Local $eqTime = _calcEquationOfTime ( $T ) Local $theta = _calcSunDeclination ( $T ) If $output Then $SolarEquationOfTime = Floor ( $eqTime * 100 + 0.5 ) / 100.0 $SolarDeclination = Floor ( $theta * 100 + 0.5 ) / 100.0 EndIf Local $solarTimeFix = $eqTime + 4.0 * $longitude - 60.0 * $zone Local $earthRadVec = _calcSunRadVector ( $T ) Local $trueSolarTime = $localtime + $solarTimeFix While $trueSolarTime > 1440 $trueSolarTime -= 1440 WEnd Local $hourAngle = $trueSolarTime / 4.0 - 180.0; If $hourAngle < -180 Then $hourAngle += 360.0 EndIf Local $haRad = _degToRad ( $hourAngle ) Local $csz = Sin ( _degToRad ( $latitude ) ) * Sin ( _degToRad ( $theta ) ) + Cos ( _degToRad ( $latitude ) ) * Cos ( _degToRad ( $theta ) ) * Cos ( $haRad ) If $csz > 1.0 Then $csz = 1.0 ElseIf $csz < -1.0 Then $csz = -1.0 EndIf Local $zenith = _radToDeg ( ACos ( $csz ) ) Local $azDenom = ( Cos ( _degToRad ( $latitude ) ) * Sin ( _degToRad ( $zenith ) ) ) If Abs ( $azDenom ) > 0.001 Then $azRad = ( ( Sin ( _degToRad ( $latitude ) ) * Cos ( _degToRad ( $zenith ) ) ) - Sin ( _degToRad ( $theta ) ) ) / $azDenom If Abs ( $azRad ) > 1.0 Then If $azRad < 0 Then $azRad = -1.0 Else $azRad = 1.0 EndIf EndIf Local $azimuth = 180.0 - _radToDeg ( ACos ( $azRad ) ) If $hourAngle > 0.0 Then $azimuth = -$azimuth EndIf Else If $latitude > 0.0 Then $azimuth = 180.0 Else $azimuth = 0.0 EndIf EndIf If $azimuth < 0.0 Then $azimuth += 360.0 EndIf Local $exoatmElevation = 90.0 - $zenith ; Atmospheric Refraction correction If $exoatmElevation > 85.0 Then Local $refractionCorrection = 0.0 Else Local $te = Tan ( _degToRad ( $exoatmElevation ) ) If $exoatmElevation > 5.0 Then Local $refractionCorrection = 58.1 / $te - 0.07 / ( $te * $te * $te ) + 0.000086 / ( $te * $te * $te * $te * $te ) ElseIf $exoatmElevation > -0.575 Then Local $refractionCorrection = 1735.0 + $exoatmElevation * ( -518.2 + $exoatmElevation * ( 103.4 + $exoatmElevation * ( -12.79 + $exoatmElevation * 0.711) ) ) Else Local $refractionCorrection = -20.774 / $te EndIf $refractionCorrection = $refractionCorrection / 3600.0 EndIf Local $solarZen = $zenith - $refractionCorrection If $solarZen > 108.0 Then $SolarLightStatus = "Night" ElseIf ( ( 108.0 > $solarZen ) And ( $solarZen >= 102.0 ) ) Then $SolarLightStatus = "Astronomical Twilight" ElseIf ( ( 102.0 > $solarZen ) And ( $solarZen >= 96.0 ) ) Then $SolarLightStatus = "Nautical Twilight" ElseIf ( ( 96.0 > $solarZen ) And ( $solarZen >= 90.8333 ) ) Then $SolarLightStatus = "Civil Twilight" Else $SolarLightStatus = "Day" EndIf _ArrayAdd ( $SolarReturnAzEl, Floor ( ( ( $azimuth * 100 ) + 0.5 ) / 100.0 ) ) _ArrayAdd ( $SolarReturnAzEl, Floor ( ( 90.0 - $solarZen ) * 100 + 0.5) / 100.0 ) _ArrayAdd ( $SolarReturnAzEl, $SolarLightStatus ) _ArrayDelete ( $SolarReturnAzEl, 0 ) Return ( $SolarReturnAzEl ) EndFunc #cs function calcSolNoon(jd, longitude, timezone, dst) { var tnoon = calcTimeJulianCent(jd - longitude/360.0) var eqTime = calcEquationOfTime(tnoon) var solNoonOffset = 720.0 - (longitude * 4) - eqTime // in minutes var newt = calcTimeJulianCent(jd + solNoonOffset/1440.0) eqTime = calcEquationOfTime(newt) solNoonLocal = 720 - (longitude * 4) - eqTime + (timezone*60.0)// in minutes if(dst) solNoonLocal += 60.0 document.getElementById("noonbox").value = timeString(solNoonLocal, 3) } #ce Func _calcSolNoon ( $jd, $longitude, $timezone, $dst ) Local $tnoon = _calcTimeJulianCent ( $jd - $longitude / 360.0 ) Local $eqTime = _calcEquationOfTime ( $tnoon ) Local $solNoonOffset = 720.0 - ( $longitude * 4 ) - $eqTime ; in minutes Local $newt = _calcTimeJulianCent ( $jd + $solNoonOffset / 1440.0 ) $eqTime = _calcEquationOfTime ( $newt ) $solNoonLocal = 720 - ( $longitude * 4 ) - $eqTime + ( $timezone * 60.0 ) ; in minutes If $dst Then $solNoonLocal += 60.0 Return _timeString ( $solNoonLocal, 3 ) EndFunc #cs function dayString(jd, next, flag) { // returns a string in the form DDMMMYYYY[ next] to display prev/next rise/set // flag=2 for DD MMM, 3 for DD MM YYYY, 4 for DDMMYYYY next/prev if ( (jd < 900000) || (jd > 2817000) ) { var output = "error" } else { var z = Math.floor(jd + 0.5); var f = (jd + 0.5) - z; if (z < 2299161) { var A = z; } else { alpha = Math.floor((z - 1867216.25)/36524.25); var A = z + 1 + alpha - Math.floor(alpha/4); } var B = A + 1524; var C = Math.floor((B - 122.1)/365.25); var D = Math.floor(365.25 * C); var E = Math.floor((B - D)/30.6001); var day = B - D - Math.floor(30.6001 * E) + f; var month = (E < 14) ? E - 1 : E - 13; var year = ((month > 2) ? C - 4716 : C - 4715); if (flag == 2) var output = zeroPad(day,2) + " " + monthList[month-1].abbr; if (flag == 3) var output = zeroPad(day,2) + monthList[month-1].abbr + year.toString(); if (flag == 4) var output = zeroPad(day,2) + monthList[month-1].abbr + year.toString() + ((next) ? " next" : " prev"); } return output; } #ce Func _dayString ( $jd, $next, $flag ) ; returns a string in the form DDMMMYYYY[ next] to display prev/next rise/set ; flag=2 for DD MMM, 3 for DD MM YYYY, 4 for DDMMYYYY next/prev If ( $jd < 900000 ) Or ( $jd > 2817000 ) Then Local $output = "error" Else Local $z = Floor ( $jd + 0.5 ) Local $f = ( $jd + 0.5 ) - $z If $z < 2299161 Then $A = $z Else Local $alpha = Floor ( ( $z - 1867216.25 ) / 36524.25 ) $A = $z + 1 + $alpha - Floor ( $alpha / 4 ) EndIf Local $B = $A + 1524 Local $C = Floor ( ( $B - 122.1 ) / 365.25 ) Local $D = Floor ( 365.25 * $C ) Local $E = Floor ( ( $B - $D ) / 30.6001 ) Local $day = $B - $D - Floor ( 30.6001 * $E ) + $f Local $month If $E < 14 Then $month = $E - 1 Else $month = $E - 13 EndIf Local $year If $month > 2 Then $year = $C - 4716 Else $year = $C - 4715 EndIf If $flag = 2 Then Local $output = _zeroPad ( $day, 2 ) & " " & $MonthAbrev[$month-1] ElseIf $flag = 3 Then Local $output = _zeroPad ( $day, 2 ) & $MonthAbrev[$month-1] & String ( $year ) ElseIf $flag = 4 Then If $next Then Local $output = _zeroPad ( $day, 2 ) & $MonthAbrev[$month-1] & String ( $year ) & " next" Else Local $output = _zeroPad ( $day, 2 ) & $MonthAbrev[$month-1] & String ( $year ) & " prev" EndIf EndIf EndIf Return $output EndFunc #cs function timeDateString(JD, minutes) { var output = timeString(minutes, 2) + " " + dayString(JD, 0, 2); return output; } #ce Func _TimeDateString ( $JD, $minutes ) Local $output = _timeString ( $minutes, 2 ) & " " & _dayString ( $JD, 0, 2 ) Return $output EndFunc #cs function timeString(minutes, flag) // timeString returns a zero-padded string (HH:MM:SS) given time in minutes // flag=2 for HH:MM, 3 for HH:MM:SS { if ( (minutes >= 0) && (minutes < 1440) ) { var floatHour = minutes / 60.0; var hour = Math.floor(floatHour); var floatMinute = 60.0 * (floatHour - Math.floor(floatHour)); var minute = Math.floor(floatMinute); var floatSec = 60.0 * (floatMinute - Math.floor(floatMinute)); var second = Math.floor(floatSec + 0.5); if (second > 59) { second = 0 minute += 1 } if ((flag == 2) && (second >= 30)) minute++; if (minute > 59) { minute = 0 hour += 1 } var output = zeroPad(hour,2) + ":" + zeroPad(minute,2); if (flag > 2) output = output + ":" + zeroPad(second,2); } else { var output = "error" } return output; } #ce Func _timeString ( $minutes, $flag ) ; timeString returns a zero-padded string (HH:MM:SS) given time in minutes ; flag=2 for HH:MM, 3 for HH:MM:SS If ( ( $minutes >= 0 ) And ( $minutes < 1440 ) ) Then Local $floatHour = $minutes / 60.0 Local $hour = Floor ( $floatHour ) Local $floatMinute = 60.0 * ( $floatHour - Floor ( $floatHour) ) Local $minute = Floor ( $floatMinute ) Local $floatSec = 60.0 * ( $floatMinute - Floor ( $floatMinute ) ) Local $second = Floor ( $floatSec + 0.5 ) If ( $second > 59) Then $second = 0 $minute += 1 EndIf If ( ( $flag = 2 ) And ( $second >= 30 ) ) Then $minute += 1 If ( $minute > 59 ) Then $minute = 0 $hour += 1 EndIf Local $output = _zeroPad ( $hour, 2 ) & ":" & _zeroPad ( $minute, 2 ) If $flag > 2 Then $output = $output & ":" & _zeroPad ( $second, 2 ) Else $output = "error" EndIf Return $output EndFunc #cs function calcSunriseSetUTC(rise, JD, latitude, longitude) { var t = calcTimeJulianCent(JD); var eqTime = calcEquationOfTime(t); var solarDec = calcSunDeclination(t); var hourAngle = calcHourAngleSunrise(latitude, solarDec); //alert("HA = " + radToDeg(hourAngle)); if (!rise) hourAngle = -hourAngle; var delta = longitude + radToDeg(hourAngle); var timeUTC = 720 - (4.0 * delta) - eqTime; // in minutes return timeUTC } #ce Func _calcSunriseSetUTC ( $rise, $JD, $latitude, $longitude ) Local $t = _calcTimeJulianCent ( $JD ) Local $eqTime = _calcEquationOfTime ( $t ) Local $solarDec = _calcSunDeclination ( $t ) Local $RiseSetAngle = _calcHourAngleSunrise ( $latitude, $solarDec ) If Not $rise Then $RiseSetAngle = -$RiseSetAngle Local $delta = $longitude + _radToDeg ( $RiseSetAngle ) Local $timeUTCRS = 720 - ( 4.0 * $delta ) - $eqTime Return $timeUTCRS ; in minutes EndFunc #cs function calcSunriseSet(rise, JD, latitude, longitude, timezone, dst) // rise = 1 for sunrise, 0 for sunset { var id = ((rise) ? "risebox" : "setbox") var timeUTC = calcSunriseSetUTC(rise, JD, latitude, longitude); var newTimeUTC = calcSunriseSetUTC(rise, JD + timeUTC/1440.0, latitude, longitude); if (isNumber(newTimeUTC)) { var timeLocal = newTimeUTC + (timezone * 60.0) if (document.getElementById(rise ? "showsr" : "showss").checked) { var riseT = calcTimeJulianCent(JD + newTimeUTC/1440.0) var riseAz = calcAzEl(0, riseT, timeLocal, latitude, longitude, timezone) showLineGeodesic(rise ? "#66ff00" : "#ff0000", riseAz) } timeLocal += ((dst) ? 60.0 : 0.0); if ( (timeLocal >= 0.0) && (timeLocal < 1440.0) ) { document.getElementById(id).value = timeString(timeLocal,2) } else { var jday = JD var increment = ((timeLocal < 0) ? 1 : -1) while ((timeLocal < 0.0)||(timeLocal >= 1440.0)) { timeLocal += increment * 1440.0 jday -= increment } document.getElementById(id).value = timeDateString(jday,timeLocal) } } else { // no sunrise/set found var doy = calcDoyFromJD(JD) if ( ((latitude > 66.4) && (doy > 79) && (doy < 267)) || ((latitude < -66.4) && ((doy < 83) || (doy > 263))) ) { //previous sunrise/next sunset if (rise) { // find previous sunrise jdy = calcJDofNextPrevRiseSet(0, rise, JD, latitude, longitude, timezone, dst) } else { // find next sunset jdy = calcJDofNextPrevRiseSet(1, rise, JD, latitude, longitude, timezone, dst) } document.getElementById(((rise)? "risebox":"setbox")).value = dayString(jdy,0,3) } else { //previous sunset/next sunrise if (rise == 1) { // find previous sunrise jdy = calcJDofNextPrevRiseSet(1, rise, JD, latitude, longitude, timezone, dst) } else { // find next sunset jdy = calcJDofNextPrevRiseSet(0, rise, JD, latitude, longitude, timezone, dst) } document.getElementById(((rise)? "risebox":"setbox")).value = dayString(jdy,0,3) } } } #ce Func _calcSunriseSet ( $rise, $JD, $latitude, $longitude, $timezone, $dst ) ; rise = 1 for sunrise, 0 for sunset Local $timeUTC = _calcSunriseSetUTC ( $rise, $JD, $latitude, $longitude ) Local $newTimeUTC = _calcSunriseSetUTC ( $rise, $JD + $timeUTC / 1440.0, $latitude, $longitude ) If isNumber ( $newTimeUTC ) Then Local $timeLocal = $newTimeUTC + ( $timezone * 60.0 ) If $rise Then Local $riseT = _calcTimeJulianCent ( $JD + $newTimeUTC / 1440.0 ) Local $riseAz = _calcAzEl ( 0, $riseT, $timeLocal, $latitude, $longitude, $timezone ) EndIf If $dst Then $timeLocal += 60.0 Else $timelocal += 0.0 EndIf If ( ( $timeLocal >= 0.0) And ( $timeLocal < 1440.0) ) Then Return _timeString ( $timeLocal, 2 ) Else Local $jday = $JD Local $increment If $timeLocal < 0 Then $increment = 1 Else $increment = -1 EndIf While ( ( $timeLocal < 0.0 ) Or ( $timeLocal >= 1440.0 ) ) $timeLocal += $increment * 1440.0 $jday -= $increment WEnd Return _timeDateString ( $jday, $timeLocal ) EndIf Else Local $doy = _calcDoyFromJD ( $JD ) If ( ( ( $latitude > 66.4 ) And ( $doy > 79 ) And ( $doy < 267 ) ) Or ( ( $latitude < -66.4 ) And ( ( $doy < 83 ) Or ( $doy > 263 ) ) ) ) Then If ( $rise ) Then $jdy = _calcJDofNextPrevRiseSet ( 0, $rise, $JD, $latitude, $longitude, $timezone, $dst ) Else $jdy = _calcJDofNextPrevRiseSet ( 1, $rise, $JD, $latitude, $longitude, $timezone, $dst ) EndIf ;Return _dayString ( $jdy, 0, 3 ) Else If ( $rise ) Then $jdy = _calcJDofNextPrevRiseSet ( 1, $rise, $JD, $latitude, $longitude, $timezone, $dst ) Else $jdy = _calcJDofNextPrevRiseSet ( 0, $rise, $JD, $latitude, $longitude, $timezone, $dst ) EndIf ;Return _dayString ( $jdy, 0, 3 ) EndIf EndIf EndFunc #cs function calcJDofNextPrevRiseSet(next, rise, JD, latitude, longitude, tz, dst) { var julianday = JD; var increment = ((next) ? 1.0 : -1.0); var time = calcSunriseSetUTC(rise, julianday, latitude, longitude); while(!isNumber(time)){ julianday += increment; time = calcSunriseSetUTC(rise, julianday, latitude, longitude); } var timeLocal = time + tz * 60.0 + ((dst) ? 60.0 : 0.0) while ((timeLocal < 0.0) || (timeLocal >= 1440.0)) { var incr = ((timeLocal < 0) ? 1 : -1) timeLocal += (incr * 1440.0) julianday -= incr } return julianday; } #ce Func _calcJDofNextPrevRiseSet ( $next, $rise, $JD, $latitude, $longitude, $tz, $dst ) Local $julianday = $JD Local $increment If $next Then $increment = 1.0 Else $increment = -1.0 EndIf Local $time = _calcSunriseSetUTC ( $rise, $julianday, $latitude, $longitude ) While Not isNumber ( $time ) $julianday += $increment $time = _calcSunriseSetUTC ( $rise, $julianday, $latitude, $longitude ) WEnd Local $timeLocal If $dst Then $timeLocal = $time + $tz * 60.0 + 60.0 Else $timeLocal = $time + $tz * 60.0 EndIf While ( ( $timeLocal < 0.0 ) Or ( $timeLocal >= 1440.0 ) ) Local $incr If $timeLocal < 0 Then $incr = 1 Else $incr = -1 EndIf $timeLocal += ( $incr * 1440.0 ) $julianday -= $incr WEnd Return $julianday EndFunc #cs function calculate() { //refreshMap() //clearOutputs() //map.clearOverlays() //showMarkers() var jday = getJD() var tl = getTimeLocal() var tz = readTextBox("zonebox", 5, 0, 0, -14, 13, 0) var dst = document.getElementById("dstCheckbox").checked var total = jday + tl/1440.0 - tz/24.0 var T = calcTimeJulianCent(total) var lat = parseFloat(document.getElementById("latbox").value.substring(0,9)) var lng = parseFloat(document.getElementById("lngbox").value.substring(0,10)) calcAzEl(1, T, tl, lat, lng, tz) calcSolNoon(jday, lng, tz, dst) var rise = calcSunriseSet(1, jday, lat, lng, tz, dst) var set = calcSunriseSet(0, jday, lat, lng, tz, dst) //alert("JD " + jday + " " + rise + " " + set + " ") } #ce ;( $AstroLat, $AstroLong, $AstroMonth, $AstroDay, $AstroYear, $AstroTimeZone, $AstroHour, $AstroMinute, $AstroSecond, $AstroDST ) Func _SolarCalculate ( $CalcLat, $CalcLong, $CalcMonth, $CalcDay, $CalcYear, $CalcTz, $CalcHour, $CalcMinute, $CalcSecond, $CalcDST, $CalcCurrent ) Local $SolarCalculateResult[1] = [0] Local $jday = _getJD ( $CalcMonth, $CalcDay, $CalcYear ) Local $tl = _getTimeLocal ( $CalcHour, $CalcMinute, $CalcSecond, $CalcDST ) Local $tz If $CalcTz = "" Then $tz = Int ( $CalcLong / 15 ) Else $tz = $CalcTz EndIf Local $total = $jday + $tl / 1440.0 - $tz / 24.0 Local $T = _calcTimeJulianCent ( $total ) Local $CalcSolNoon = _calcSolNoon ( $jday, $CalcLong, $tz, $CalcDST ) ; Returns String: "HH:MM:SS" ;MsgBox ( 0, "Solar Noon:", $CalcSolNoon ) Local $rise = _calcSunriseSet ( 1, $jday, $CalcLat, $CalcLong, $tz, $CalcDST ) ; Returns String: "HH:MM" or "HH:MM DD Mon" ;MsgBox ( 0, "Sun Rise:", $rise ) Local $set = _calcSunriseSet ( 0, $jday, $CalcLat, $CalcLong, $tz, $CalcDST ) ; Returns String: "HH:MM" or "HH:MM DD Mon" ;MsgBox ( 0, "Sun Set:", $set ) _ArrayAdd ( $SolarCalculateResult, $rise ) _ArrayAdd ( $SolarCalculateResult, $CalcSolNoon ) _ArrayAdd ( $SolarCalculateResult, $set ) $SolarCalculateResult[0] += 3 If $CalcCurrent Then Local $CalcAzEl = _calcAzEl ( 1, $T, $tl, $CalcLat, $CalcLong, $tz ) ; Returns Array: 0 - Azimuth, 1 - Elevation, 2 - Illumination-Disposition _ArrayConcatenate ( $SolarCalculateResult, $CalcAzEl ) $SolarCalculateResult[0] += 3 EndIf Return $SolarCalculateResult EndFunc #cs </SCRIPT> #ce Here is an example usage script: #include <SunPosition.au3> #include <GUIConstantsEx.au3> #include <WindowsConstants.au3> Global $MyLat = "37.818599" Global $MyLong = "-122.478418" $SunPosition_Window = GUICreate ( "Sun Position", 220, 180 ) GUICtrlCreateLabel ( "Sun Rise:", 10, 12 ) $Rise_Time = GUICtrlCreateInput("", 100, 10 ) GUICtrlCreateLabel ( "Solar Noon:", 10, 32 ) $Noon_Time = GUICtrlCreateInput("", 100, 30 ) GUICtrlCreateLabel ( "Sun Set:", 10, 52 ) $Set_Time = GUICtrlCreateInput("", 100, 50 ) GUICtrlCreateLabel ( "Azimuth:", 10, 72 ) $Sun_Azimuth = GUICtrlCreateInput("", 100, 70 ) GUICtrlCreateLabel ( "Elevation:", 10, 92 ) $Sun_Elevation = GUICtrlCreateInput("", 100, 90 ) GUICtrlCreateLabel ( "Illum Disp.:", 10, 112 ) $Light_Disposition = GUICtrlCreateInput("", 100, 110, 110 ) GUICtrlCreateLabel ( "Dimmer Lvl:", 10, 135 ) $Light_Level_Control = GUICtrlCreateLabel ( "", 70, 135, 23, 17 ) GUICtrlCreateLabel ( "Switched Lts:", 100, 135 ) $Light_Switch_Control = GUICtrlCreateLabel ( "", 170, 135, 23, 17 ) $Dummy = GUICtrlCreateInput("", 100, 210 ) GUICtrlCreateLabel ( "Light Blocking Curtians:", 10, 155 ) $Privacy_Curtain_Control = GUICtrlCreateLabel ( "", 125, 155, 23, 17 ) GUISetState(@SW_SHOW) Global $RefreshCounter = 0 Global $Light_Level_Register = 0 Global $Curtain_Opening_Register = 0 Global $CalcLightMagnatude = 0 While 1 Sleep ( 2 ) $msg = GUIGetMsg() Switch $msg Case $GUI_EVENT_CLOSE ExitLoop Case "" $RefreshCounter += 1 If $RefreshCounter >=25 Then $TestVector = _GetSolarAstronimicalData ( $MyLat, $MyLong, @MON, @MDAY, @YEAR, Int ( $MyLong / 15 ), @HOUR, @MIN, @SEC, True ) GUICtrlSetData ( $Rise_Time, $TestVector[1] ) GUICtrlSetData ( $Noon_Time, $TestVector[2] ) GUICtrlSetData ( $Set_Time, $TestVector[3] ) GUICtrlSetData ( $Sun_Azimuth, $TestVector[4] ) GUICtrlSetData ( $Sun_Elevation, $TestVector[5] ) GUICtrlSetData ( $Light_Disposition, $TestVector[6] ) ; 0.8333 add to actual elevation for lights ; 1.722233333 subtract from actual elevation for lights ; 1.722233333 x 3 = 5.166699999 Max for Light control $Light_Level_Register = $TestVector[5] + 0.8333 $Light_Level_Register -= 3.444466666 $Light_Level_Register *= -1 If $Light_Level_Register < 0 Then $Light_Level_Register = 0 ElseIf $Light_Level_Register > 5.166699999 Then $Light_Level_Register = 255 Else $Light_Level_Register = $Light_Level_Register / 5.166699999 $Light_Level_Register = int ( 255 * $Light_Level_Register ) EndIf $CalcLightMagnatude = 0 $CalcLightMagnatude = ( $Light_Level_Register * 65536 ) + ( $Light_Level_Register * 256 ) + Round ( ( $Light_Level_Register * 0.75 ), 0 ) GUICtrlSetBkColor ( $Light_Level_Control, $CalcLightMagnatude ) GUICtrlSetData ( $Light_Level_Control, $Light_Level_Register ) If $Light_Level_Register < 191 Then GUICtrlSetColor ( $Light_Level_Control, 0xffffff ) Else GUICtrlSetColor ( $Light_Level_Control, 0x000000 ) EndIf GUICtrlSetState( $Dummy, $GUI_FOCUS) If $Light_Level_Register > 95 Then GUICtrlSetData ( $Light_Switch_Control, " On" ) GUICtrlSetBkColor ( $Light_Switch_Control, 0x00ff00 ) Else GUICtrlSetData ( $Light_Switch_Control, " Off" ) GUICtrlSetBkColor ( $Light_Switch_Control, 0xff0000 ) EndIf ; 0.8333 + 3.444466666 = 4.277766666 add to actual elevation for curtains ; 1.722233333 x 2 = 3.444466666 Max for Curtain control $Curtain_Opening_Register = $TestVector[5] + 4.277766666 $Curtain_Opening_Register *= -1 If $Curtain_Opening_Register < 0 Then $Curtain_Opening_Register = 0 ElseIf $Curtain_Opening_Register > 3.444466666 Then $Curtain_Opening_Register = 255 Else $Curtain_Opening_Register = $Curtain_Opening_Register / 3.444466666 $Curtain_Opening_Register = int ( 255 * $Curtain_Opening_Register ) EndIf $Curtain_Opening_Register = 255 - $Curtain_Opening_Register GUICtrlSetData ( $Privacy_Curtain_Control, $Curtain_Opening_Register ) $RefreshCounter = 0 EndIf EndSwitch WEnd GUIDelete() I personally believe this data can be used for pointing solar panels or, in home automation, opening and closing blinds/curtains to avoid over-exposure of a room. It could also be used for scheduling lights, etc… Have fun with it! -Tim
    1 point
  8. You're using SciTE Lite not SciTE4AutoIt3.
    1 point
  9. Melba23

    PixelGetColor speed issues

    trancexx, You flatter yourself - nothing would please me more than never having to have anything to do with you ever again. So you stop causing me to be called into threads to moderate and then I will have no reason to be there. Your choice. M23
    1 point
  10. Melba23

    PixelGetColor speed issues

    trancexx, Absolutely no chance. M23
    1 point
  11. It's discussed in this thread and the one I linked on how to add an icon.
    1 point
  12. I think you are not understanding what is being suggested. Write script 1, then use FileInstall to include it in script 2, as has been suggested: FileInstall("C:\Script2.au3", @TempDir & "\Script2.au3") Then call that script1 with the syntax jdelaney gave you in post 12. Whole lot easier than writing the thing on the fly.
    1 point
  13. oops, misunderstood (didn't read) the requirements. TIme for bed just about. ::heh::
    1 point
  14. As promised: This suits my needs at the moment, but I plan to add some other things to it as well, but it's at least usable now. The slider at the bottom sets the level the microphone must detect in order to detect it as a "clap". By default, I have the setting set to nearly deafening... I have twin three year old girls who enjoy screaming and running around while I'm trying to cook, so I have it set to where I need to clap very loudly to activate the next step. That's also the reason for requiring 3 sequential claps (to cut down on false positives). While they were napping, 2 worked just fine. I've included a few of our family's favorite recipes just as an example, but they're just glorified text files. If you dive into the AU3 instead of just using the exe, some basic configuration settings are near the top since I haven't gotten around to making a GUI settings window yet. I'm open to suggestions on how to improve it, as well as any constructive criticism anyone has to offer about the code itself. I'm always eager to grow! FlashCook.rar
    1 point
  15. TechCoder

    Where to begin?

    well, there you go! One of the (oh, so very few, IMHO) 'useful' docs put out by 'the horse'.... that link goes into my bookmarks.
    1 point
  16. JLogan3o13

    Where to begin?

    I prefer this one, straight from the horse's mouth so to speak. Goes up through Windows 8 and Server 2012. http://technet.microsoft.com/en-us/library/cc754340.aspx
    1 point
  17. An example #include <GuiEdit.au3> #include <GUIConstantsEx.au3> #include <WindowsConstants.au3> Global $hEdit Example() Func Example() ; Create GUI GUICreate("Edit Char From Pos", 400, 200, -1, -1, $WS_BORDER) GUICtrlCreateEdit("Kc and Kp are the equilibrium constants of gaseous mixtures. " & @CRLF & @CRLF & _ "However, the difference between the two constants is that Kc is defined by molar concentrations," & @CRLF & @CRLF & _ "whereas Kp is defined by the partial pressures of the gasses inside a closed system." & @CRLF & @CRLF & _ "The equilibrium constants do not include the concentrations of single components such as liquids and solid, and they do not have any units.", 2, 2, 394, 168, 0) $hEdit = GUICtrlGetHandle(-1) GUISetState(@SW_SHOW) For $i = 1 To 50 Sleep(500) If _WinAPI_GetFocus() = $hEdit Then ToolTip(Hover_WordDetect()) Else ToolTip("") EndIf Next GUIDelete() EndFunc ;==>Example Func Hover_WordDetect() Local $aCharPos[2], $iMousePos[2] $aCharPos = _GUICtrlEdit_CharFromPos($hEdit, _WinAPI_GetMousePosX(True, $hEdit), _WinAPI_GetMousePosY(True, $hEdit)) Local Const $sLine = _GUICtrlEdit_GetLine($hEdit, $aCharPos[1]) $aCharPos[0] -= _GUICtrlEdit_LineIndex($hEdit, $aCharPos[1]) Local $aWords = StringSplit($sLine, " "), $iCount = 0 For $i = 1 To $aWords[0] Switch $aCharPos[0] Case $iCount To $iCount + StringLen($aWords[$i]) ;~ ConsoleWrite($aWords[$i] & @CRLF) Return $aWords[$i] Case Else ;~ ConsoleWrite("From: " & $iCount & " to: " & $iCount + StringLen($aWords[$i]) & @TAB & $aCharPos[0] & @CRLF) $iCount += StringLen($aWords[$i]) + 1 EndSwitch Next ;~ ConsoleWrite("" & @CRLF) Return "" EndFunc ;==>Hover_WordDetect Regards
    1 point
  18. Absolutely. A day of polishing will do it well, though. It's far from being pretty and at the moment is merely functional.
    1 point
  19. 1 point
  20. TechCoder

    Where to begin?

    I used to have a bookmark for dos command prompt commands, though can't seem to find it - haven't used it in a long ( L O N G ) time...... but a quick search on Google came up with dozens of 'how to' links. first one I looked at seems about as 'standard' as any (you really should try those searches - loads of great data and by reading several sites, you will always get your own 'best' knowledge - some sites may have wrong or missing data, but you hit 4-5 of them and you will find the 'common thread' of information. Doing a bit of reading on each site will get you tons of knowledge fast. And, you may find one that just happens to have a new command you never saw (though DOS has been out so long with no changes it is very well documented) - that is how I learned to program php years ago - and still constantly search for various ways to do things. want more direct info? then formulate an idea of what you want to achieve (not just 'learn about CMD' - that is very vague....) - then ask yourself a question about getting it done. put that question in the search engine - you will be amazed......
    1 point
  21. If its your own GUI you can set it as an attribute. $WS_EX_TOPMOST tippfehler
    1 point
  22. Here you are: #include <ie.au3> $oIE = _IECreate("http://www.fiercewireless.com/jobs/post/") _IELoadWait($oIE, 1000) $tags = $oIE.document.GetElementsByTagName("IFRAME") $x = 0 For $tag In $tags If $x = 0 Then $tag.contentWindow.document.body.innerHTML = "got you!" ExitLoop EndIf Next
    1 point
  23. Look at using the new #pragma directive for the version number assignment. Oh, and look at AutoIt3WrapperToPragma (signature) to convert AutoItWrapper directives to pragma for you in one click. #pragma
    1 point
  24. jchd

    AutoIt Snippets

    A different approach: Func _RegExpStringBetween(Const $test, $start_pattern, Const $end_pattern) $start_pattern = StringRegExpReplace($start_pattern, "((?:\\\\)*)(\\Q.*?\\E)", "\1") StringRegExpReplace($start_pattern, "(?x) (?:\\\\)* \K (?<!\\) ( \( (?= \?< | \?' | \?P< ) | \( (?! \* | \? [-:\|>#\w=!+&(] | \? <= | \? <! | \? P= | \? P> ) )", "") Local $group = @extended Local $string_between = StringRegExp($test, $start_pattern & '(.*?)' & $end_pattern, 1) If @error Then Return SetError(1, 0, False) Else Return $string_between[$group] EndIf EndFunc
    1 point
  25. Perfect example of how writing your code for someone else to read, can easily wind up being self educational. Thanks.
    1 point
  26. Did some research on that too... and failed , thanks for the hint! LOL, okay, got it , thanks a lot for your help, works as intended now! Thanks to all other repliers too! Best Regards #include <GUIConstantsEx.au3> #include <WindowsConstants.au3> #include <GDIPlus.au3> #include <winapi.au3> _GDIPlus_Startup() Local $msg Global Const $STM_SETIMAGE = 0x0172 Global Const $IMAGE_BITMAP = 0 $hImage = _GDIPlus_ImageLoadFromFile(@ScriptDir & '\test.jpg') $iX_ImageDisplay = _GDIPlus_ImageGetWidth($hImage) $iY_ImageDisplay = _GDIPlus_ImageGetHeight($hImage) ConsoleWrite($iX_ImageDisplay & " x " & $iY_ImageDisplay & @CRLF) $iFactor_ImageDisplay = 1 If $iX_ImageDisplay > @DesktopWidth Or $iY_ImageDisplay > @DesktopHeight Then $iX_ImageDisplay = $iX_ImageDisplay * (@DesktopHeight / $iY_ImageDisplay) $iFactor_ImageDisplay = @DesktopHeight / $iY_ImageDisplay $iY_ImageDisplay = @DesktopHeight If $iX_ImageDisplay > @DesktopWidth Then $iY_ImageDisplay = $iY_ImageDisplay * (@DesktopWidth / $iX_ImageDisplay) $iFactor_ImageDisplay = @DesktopWidth / $iX_ImageDisplay $iX_ImageDisplay = @DesktopWidth EndIf EndIf $iX_ImageDisplay = Int($iX_ImageDisplay) $iY_ImageDisplay = Int($iY_ImageDisplay) $gui_image_display = GUICreate("My GUI", $iX_ImageDisplay,$iY_ImageDisplay, @DesktopWidth /2 - $iX_ImageDisplay /2 ,@DesktopHeight /2 - $iY_ImageDisplay /2 , $WS_POPUP); will create a dialog box that when displayed is centered $pic_image_display = GUICtrlCreatePic("", 0, 0, $iX_ImageDisplay, $iY_ImageDisplay) ConsoleWrite($iX_ImageDisplay & @TAB & $iY_ImageDisplay & @CRLF) $hBMP = _GDIPlus_BitmapCreateHBITMAPFromBitmap($hImage) _WinAPI_DeleteObject(GUICtrlSendMsg($pic_image_display, $STM_SETIMAGE, $IMAGE_BITMAP, $hBMP)) _GDIPlus_ImageDispose($hImage) _WinAPI_DeleteObject($hBMP) _GDIPlus_Shutdown() GUICtrlSetPos($pic_image_display, 0, 0, $iX_ImageDisplay, $iY_ImageDisplay) GUIRegisterMsg(522, "_ResizePic"); WM_MOUSEWHEEL GUICtrlSetPos($pic_image_display, 0, 0, $iX_ImageDisplay-1, $iY_ImageDisplay-1) GUICtrlSetPos($pic_image_display, 0, 0, $iX_ImageDisplay, $iY_ImageDisplay) GUISetState(@SW_SHOW); will display an empty dialog box ; Run the GUI until the dialog is closed While 1 $msg = GUIGetMsg() If $msg = $GUI_EVENT_CLOSE Then ExitLoop WEnd GUIDelete() Func _ResizePic($hWnd, $iMsg, $wParam, $lParam) If BitShift($wParam, 16) > 0 Then $iX_ImageDisplay *= 1.1 $iY_ImageDisplay *= 1.1 Else $iX_ImageDisplay /= 1.1 $iY_ImageDisplay /= 1.1 EndIf WinMove($gui_image_display,"",@DesktopWidth /2 - $iX_ImageDisplay /2 ,@DesktopHeight /2 - $iY_ImageDisplay /2 ,$iX_ImageDisplay,$iY_ImageDisplay) GUICtrlSetPos($pic_image_display, 0, 0, $iX_ImageDisplay, $iY_ImageDisplay) ;ConsoleWrite($iX_ImageDisplay & @TAB & $iY_ImageDisplay & @CRLF) ConsoleWrite(@DesktopWidth /2 - $iX_ImageDisplay /2 & ";" & @DesktopHeight /2 - $iY_ImageDisplay /2 & @tab & @tab & $iX_ImageDisplay & @TAB & $iY_ImageDisplay & @crlf) EndFunc ;==>_ResizePic
    1 point
  27. rasim

    Join two bitmap images?

    Hi! Example: #include <GDIPlus.au3> _BMPJoin(@ScriptDir & "\01.bmp", @ScriptDir & "\02.bmp", @ScriptDir & "\result.bmp") Func _BMPJoin($sFile1, $sFile2, $sResult) Local $hSourceIMG1, $hSourceIMG2, $iWidth, $iHeight, $hBitmap, $hImage, $hGraphic _GDIPlus_Startup() $hSourceIMG1 = _GDIPlus_ImageLoadFromFile($sFile1) $hSourceIMG2 = _GDIPlus_ImageLoadFromFile($sFile2) $iWidth = _GDIPlus_ImageGetWidth($hSourceIMG1) $iHeight = _GDIPlus_ImageGetHeight($hSourceIMG1) $hBitmap = _CreateBMP($iWidth * 2, $iHeight) $hImage = _GDIPlus_BitmapCreateFromHBITMAP($hBitmap) $hGraphic = _GDIPlus_ImageGetGraphicsContext($hImage) _GDIPlus_GraphicsDrawImageRectRect($hGraphic, $hSourceIMG1, 0, 0, $iWidth, $iHeight, 0, 0, $iWidth, $iHeight) _GDIPlus_GraphicsDrawImageRectRect($hGraphic, $hSourceIMG2, 0, 0, $iWidth, $iHeight, $iWidth, 0, $iWidth, $iHeight) _GDIPlus_ImageSaveToFile($hImage, $sResult) _WinAPI_DeleteObject($hBitmap) _WinAPI_DeleteObject($hImage) _GDIPlus_GraphicsDispose($hGraphic) _GDIPlus_ImageDispose($hSourceIMG1) _GDIPlus_ImageDispose($hSourceIMG2) _GDIPlus_Shutdown() EndFunc ;==>_BMPJoin Func _CreateBMP($sWidth, $sHeight) Local $hWnd, $hDC, $hBMP $hWnd = _WinAPI_GetDesktopWindow() $hDC = _WinAPI_GetDC($hWnd) $hBMP = _WinAPI_CreateCompatibleBitmap($hDC, $sWidth, $sHeight) _WinAPI_ReleaseDC($hWnd, $hDC) Return $hBMP EndFunc ;==>_CreateBMP about: I hope you make this himself.
    1 point
  28. ProgAndy

    Image Resize, How?

    Use something like this: ; Load Image $oldImage = _GDIPlus_ImageLoadFromFile() ;Create New image $GC = _GDIPlus_ImageGetGraphicsContext($oldImage) $newBmp = _GDIPlus_BitmapCreateFromGraphics($newW,$newH,$GC) $newGC = _GDIPlus_ImageGetGraphicsContext($newBmp) ;Draw _GDIPlus_GraphicsDrawImageRect($newGC,$oldImage,0,0,$newW,$newH) _GDIPlus_ImageSaveToFile($newBmp,$newFileName) ;Clenaup _GDIPlus_GraphicsDispose($GC) _GDIPlus_GraphicsDispose($newGC) _GDIPlus_BitmapDispose($newBmp) _GDIPlus_ImageDispose($oldImage)
    1 point
×
×
  • Create New...