Jump to content
Sign in to follow this  
Fever

Ray casting with AutoIt

Recommended Posts

Fever

Hi.
 
Been very interested in game development and wanted to write my own Wolf 3D on AutoIt.
 
Here what i got for today:
 

#include <GUIConstantsEx.au3>
#include <WindowsConstants.au3>
#include <GDIPlus.au3>
#include <Misc.au3>

Opt("MustDeclareVars", 1)

Global _
    $bGameRunning = True

Global _
    $iWidth = 640, _
    $iHeight = 480, _
    $iTileSize = 64, _
    $iWallHeight = 64

;----------------------------------------------------
; GUI
;----------------------------------------------------
Global _
    $sTitle = "Ray casting", _
    $hGUI
;----------------------------------------------------

;----------------------------------------------------
; MATH CONSTANTS
;----------------------------------------------------
Global Const $MATH_PI = 3.14159265359
;----------------------------------------------------

;----------------------------------------------------
; ANGLES
;----------------------------------------------------
Global Const _
            $ANGLE_60 = $iWidth, _
            $ANGLE_30 = $ANGLE_60 / 2, _
            $ANGLE_15 = $ANGLE_30 / 2, _
            $ANGLE_90 = $ANGLE_30 * 3, _
            $ANGLE_180 = $ANGLE_90 * 2, _
            $ANGLE_270 = $ANGLE_90 * 3, _
            $ANGLE_360 = $ANGLE_60 * 6, _
            $ANGLE_0 = 0, _
            $ANGLE_5 = $ANGLE_30 / 6, _
            $ANGLE_10 = $ANGLE_5 * 2
;----------------------------------------------------

;----------------------------------------------------
; TRIGONOMETRIC TABLES
;----------------------------------------------------
Global _
        $aSinTable[$ANGLE_360 + 1], _
        $aISinTAble[$ANGLE_360 + 1], _
        $aCosTable[$ANGLE_360 + 1], _
        $aICosTable[$ANGLE_360 + 1], _
        $aTanTable[$ANGLE_360 + 1], _
        $aITanTable[$ANGLE_360 + 1], _
        $aFishTable[$ANGLE_60 + 1], _
        $aXStepTable[$ANGLE_360 + 1], _
        $aYStepTable[$ANGLE_360 + 1]
;----------------------------------------------------

Global _
    $aMap[12][12] = _
    [ _
    [1,1,1,1,1,1,1,1,1,1,1,1], _
    [1,0,0,0,0,0,0,0,0,0,0,1], _
    [1,1,1,1,1,0,0,1,0,0,0,1], _
    [1,0,0,0,0,1,0,0,0,0,0,1], _
    [1,0,0,0,1,1,1,0,0,0,0,1], _
    [1,0,0,0,1,0,1,0,0,0,0,1], _
    [1,0,0,0,0,0,0,0,0,0,0,1], _
    [1,0,0,0,0,1,0,0,0,0,0,1], _
    [1,0,0,0,0,0,0,0,0,0,0,1], _
    [1,0,0,0,0,0,0,0,0,0,0,1], _
    [1,0,0,0,0,0,0,0,0,0,0,1], _
    [1,1,1,1,1,1,1,1,1,1,1,1] _
    ], _
    $iMapWidth = 12, _
    $iMapHeight = 12

Global _
    $sMapIndex_Wall = "1", _
    $sMapIndex_Empty = "0"


;----------------------------------------------------
; PLAYER
;----------------------------------------------------

Global _
    $iPlayerArc = $ANGLE_0, _
    $iPlayerPosX = 100, _
    $iPlayerPosY = 90, _
    $iPlayerDistanceToTheProjectPlane = 277, _
    $iProjectionPlaneYCenter = $iHeight / 2, _
    $iProjectionPlaneYCenterMax = Int($iHeight / 1.2), _
    $iProjectionPlaneYCenterMin = $iHeight / 4, _
    $iProjectionPlaneYCenterDef = $iProjectionPlaneYCenter, _
    $iPlayerHeight = 32, _
    $iPlayerMovementSpeed = 16, _
    $iPlayerTurnSpeed = $ANGLE_5

    ;----------------------------------------------------
    ; PLAYER - ANIMATION
    ;----------------------------------------------------

    Global _
        $iPlayerAnimation_WalkIndex = 0

    ;----------------------------------------------------

;----------------------------------------------------

Global _
    $fPlayerDirX, _
    $fPlayerDirY

Global _
    $iTime = 0, _
    $iOldTime = 0

Global _
    $hGraphic, _
    $iFrameTime, _
    $aGraphic

Global $hSystemStartTimer

;----------------------------------------------------
; LOCAL
;----------------------------------------------------

;----------------------------------------------------
; _ENGINE_RENDER
;----------------------------------------------------

Global _
    $iGridVertical, $iGridHorizontal, _
    $iDistToNextVerticalGrid, $iDistToNextHorizontalGrid, _
    $fXIntersection, $fYIntersection, _
    $fDistToNextXIntersection, $fDistToNextYIntersection, _
    $iGridIndexX, $iGridIndexY, _
    $fDistToVerticalGridBeingHit, $fDistToHorizontalGridBeingHit, _
    $iCastArc, $iCastColumn, _
    $fScaleFactor, $fDist, _
    $iTopOfWall, $iBottomOfWall, _
    $iProjectedWallHeight

Global _
    $iXTemp, $iYTemp

;----------------------------------------------------

;----------------------------------------------------

$hGUI = GUICreate($sTitle, $iWidth, $iHeight, -1, -1)

GUICtrlSetColor(-1, 0xFF0000)

GUISetState()

Global $hLoopTimer = TimerInit()
Global $iNextTick = TimerDiff($hLoopTimer)

_Init()

While ($bGameRunning)
    _GUILoop()
    _KeysLoop()

    _Engine_Render()

    $iOldTime = $iTime
    $iTime = TimerDiff($hSystemStartTimer)

    $iFrameTime = ($iTime - $iOldTime) / 1000

    WinSetTitle($hGUI, "", $sTitle & " - FPS: " & Round(1 / $iFrameTime) & " X: " & $iPlayerPosX & " Y: " & $iPlayerPosY & " ARC: " & $iPlayerArc)
WEnd

_Shutdown()

Func _GUILoop()
    Switch GUIGetMsg()
        Case $GUI_EVENT_CLOSE
            _Shutdown()
    EndSwitch
EndFunc

Func _KeysLoop()
    If _IsPressed("25") Then
        $iPlayerArc -= $iPlayerTurnSpeed

        If $iPlayerArc < $ANGLE_0 Then
            $iPlayerArc += $ANGLE_360
        EndIf
    ElseIf _IsPressed("27") Then
        $iPlayerArc += $iPlayerTurnSpeed

        If $iPlayerArc >= $ANGLE_360 Then
            $iPlayerArc -= $ANGLE_360
        EndIf
    EndIf

    $fPlayerDirX = $aCosTable[$iPlayerArc]
    $fPlayerDirY = $aSinTable[$iPlayerArc]

    If _IsPressed("26") Then
        $iPlayerPosX += Int($fPlayerDirX * $iPlayerMovementSpeed)
        $iPlayerPosY += Int($fPlayerDirY * $iPlayerMovementSpeed)

        If $iPlayerAnimation_WalkIndex == 0 Then
            $iProjectionPlaneYCenter += 2

            If $iProjectionPlaneYCenter >= $iProjectionPlaneYCenterDef + 10 Then
                $iPlayerAnimation_WalkIndex = 1
            EndIf
        Else
            $iProjectionPlaneYCenter -= 2

            If $iProjectionPlaneYCenter <= $iProjectionPlaneYCenterDef - 10 Then
                $iPlayerAnimation_WalkIndex = 0
            EndIf
        EndIf

    ElseIf _IsPressed("28") Then
        $iPlayerPosX -= Int($fPlayerDirX * $iPlayerMovementSpeed / 2)
        $iPlayerPosY -= Int($fPlayerDirY * $iPlayerMovementSpeed / 2)

        If $iPlayerAnimation_WalkIndex == 0 Then
            $iProjectionPlaneYCenter += 1

            If $iProjectionPlaneYCenter >= $iProjectionPlaneYCenterDef + 10 Then
                $iPlayerAnimation_WalkIndex = 1
            EndIf
        Else
            $iProjectionPlaneYCenter -= 1

            If $iProjectionPlaneYCenter <= $iProjectionPlaneYCenterDef - 10 Then
                $iPlayerAnimation_WalkIndex = 0
            EndIf
        EndIf
    EndIf

    #cs
    If _IsPressed("57") Then
        If $iProjectionPlaneYCenter < $iProjectionPlaneYCenterMax Then
            $iProjectionPlaneYCenter += 10
        EndIf
    ElseIf _IsPressed("53") Then
        If $iProjectionPlaneYCenter > $iProjectionPlaneYCenterMin Then
            $iProjectionPlaneYCenter -= 10
        EndIf
    Else
        ;;If $iProjectionPlaneYCenter > $iProjectionPlaneYCenterDef Then
        ;;  $iProjectionPlaneYCenter = $iProjectionPlaneYCenterDef
        ;;Else
        ;;  $iProjectionPlaneYCenter = $iProjectionPlaneYCenterDef
        ;;EndIf
    EndIf
    #ce
EndFunc

Func _Init()
    Global $hGraphic, $aGraphic, $hPen, $hBitmap, $hBuffer

    $hSystemStartTimer = TimerInit()

    _GDIPlus_Startup()

    $hGraphic = _GDIPlus_GraphicsCreateFromHWND($hGUI)
    $hBitmap = _GDIPlus_BitmapCreateFromGraphics($iWidth, $iHeight, $hGraphic)
    $hBuffer = _GDIPlus_ImageGetGraphicsContext($hBitmap)
    _GDIPlus_GraphicsSetSmoothingMode($hBuffer, 0)

    $hPen = _GDIPlus_BrushCreateSolid()

    _GDIPlus_GraphicsClear($hBuffer, 0xFFFFFFFF)

    _CreateOptTables()
EndFunc

Func _Shutdown()
    _GDIPlus_GraphicsDispose($hGraphic)
    _GDIPlus_BrushDispose($hPen)
    _GDIPlus_Shutdown()

    Exit
EndFunc

;----------------------------------------------------
; HELPER
;----------------------------------------------------

Func _ArcToRad($iArcAngle)
    Return $iArcAngle * $MATH_PI / $ANGLE_180
EndFunc

Func _CreateOptTables()
    Local $i, $fRadian

    For $i = 0 To $ANGLE_360
        $fRadian = _ArcToRad($i) + 0.0001

        $aSinTable[$i] = Sin($fRadian)
        $aISinTable[$i] = 1 / $aSinTable[$i]
        $aCosTable[$i] = Cos($fRadian)
        $aICosTable[$i] = 1 / $aCosTable[$i]
        $aTanTable[$i] = Tan($fRadian)
        $aITanTable[$i] = 1 / $aTanTable[$i]

        If $i >= $ANGLE_90 And $i < $ANGLE_270 Then
            $aXStepTable[$i] = Round($iTileSize / $aTanTable[$i], 5)

            If $aXStepTable[$i] > 0 Then
                $aXStepTable[$i] = -$aXStepTable[$i]
            EndIf
        Else
            $aXStepTable[$i] = Round($iTileSize / $aTanTable[$i], 5)

            If $aXStepTable[$i] < 0 Then
                $aXStepTable[$i] = -$aXStepTable[$i]
            EndIf
        EndIf

        If $i >= $ANGLE_0 And $i < $ANGLE_180 Then
            $aYStepTable[$i] = Round($iTileSize * $aTanTable[$i], 5)

            If $aYStepTable[$i] < 0 Then
                $aYStepTable[$i] = -$aYStepTable[$i]
            EndIf
        Else
            $aYStepTable[$i] = Round($iTileSize * $aTanTable[$i], 5)

            If $aYStepTable[$i] > 0 Then
                $aYStepTable[$i] = -$aYStepTable[$i]
            EndIf
        EndIf
    Next

    For $i = -$ANGLE_30 To $ANGLE_30
        $fRadian = _ArcToRad($i)

        $aFishTable[$i + $ANGLE_30] = Round(1 / Cos($fRadian), 7)
    Next

EndFunc

;----------------------------------------------------

;----------------------------------------------------
; ENGINE
;----------------------------------------------------

;----------------------------------------------------
; ENGINE -> GRAPHIC
;----------------------------------------------------
Func _Engine_Graphic_DrawBackground()
    Local _
        $iC = 25, _
        $iR, $iF, _
        $iSkyLength = $iHeight - $iProjectionPlaneYCenter

    For $iR = 0 To $iSkyLength - 1 Step 10
        _GDIPlus_BrushSetSolidColor($hPen, "0xFF" & Hex($iC, 2) & Hex(125, 2) & Hex(225, 2))
        _GDIPlus_GraphicsFillRect($hBuffer, 0, $iR, $iWidth, 10, $hPen)

        $iC += 5
    Next

    $iC = 5

    For $iF = $iR To $iHeight - 1 Step 15
        _GDIPlus_BrushSetSolidColor($hPen, "0xFF" & Hex($iC, 2) & Hex(10, 2) & Hex(10, 2))
        _GDIPlus_GraphicsFillRect($hBuffer, 0, $iF, $iWidth, 15, $hPen)

        $iC += 5
    Next
EndFunc
;----------------------------------------------------

Func _Engine_Render()
    _GDIPlus_GraphicsClear($hBuffer, 0xFFFFFFFF)
    _Engine_Graphic_DrawBackground()

    $iCastArc = $iPlayerArc
    $iCastArc -= $ANGLE_30

    If $iCastArc < 0 Then
        $iCastArc = $ANGLE_360 + $iCastArc
    EndIf

    For $iCastColumn = 0 To $iWidth - 1 Step 5
        If $iCastArc > $ANGLE_0 And $iCastArc < $ANGLE_180 Then
            $iGridHorizontal = Int($iPlayerPosY / $iTileSize) * $iTileSize + $iTileSize

            $iDistToNextHorizontalGrid = $iTileSize

            $iXTemp = $aITanTable[$iCastArc] * ($iGridHorizontal - $iPlayerPosY)

            $fXIntersection = $iXTemp + $iPlayerPosX
        Else
            $iGridHorizontal = Int($iPlayerPosY / $iTileSize) * $iTileSize
            $iDistToNextHorizontalGrid = -$iTileSize

            $iXTemp = $aITanTable[$iCastArc] * ($iGridHorizontal - $iPlayerPosY)
            $fXIntersection = $iXTemp + $iPlayerPosX

            $iGridHorizontal -= 1
        EndIf

        If $iCastArc == $ANGLE_0 Or $iCastArc == $ANGLE_180 Then
            $fDistToHorizontalGridBeingHit = 9999999
        Else
            $fDistToNextXIntersection = $aXStepTable[$iCastArc]

            While True
                $iGridIndexX = Int($fXIntersection / $iTileSize)
                $iGridIndexY = Int($iGridHorizontal / $iTileSize)

                If $iGridIndexX >= $iMapWidth Or $iGridIndexY >= $iMapHeight Or $iGridIndexX < 0 Or $iGridIndexY < 0 Then
                    $fDistToHorizontalGridBeingHit = 9999999

                    ExitLoop
                ElseIf $aMap[$iGridIndexY][$iGridIndexX] <> $sMapIndex_Empty Then
                    $fDistToHorizontalGridBeingHit = ($fXIntersection - $iPlayerPosX) * $aICosTable[$iCastArc]

                    ExitLoop
                Else
                    $fXIntersection += $fDistToNextXIntersection
                    $iGridHorizontal += $iDistToNextHorizontalGrid
                EndIf
            WEnd
        EndIf

        If $iCastArc < $ANGLE_90 Or $iCastArc > $ANGLE_270 Then
            $iGridVertical = $iTileSize + Int($iPlayerPosX / $iTileSize) * $iTileSize
            $iDistToNextVerticalGrid = $iTileSize

            $iYTemp = $aTanTable[$iCastArc] * ($iGridVertical - $iPlayerPosX)
            $fYIntersection = $iYTemp + $iPlayerPosY
        Else
            $iGridVertical = Int($iPlayerPosX / $iTileSize) * $iTileSize
            $iDistToNextVerticalGrid = -$iTileSize

            $iYTemp = $aTanTable[$iCastArc] * ($iGridVertical - $iPlayerPosX)
            $fYIntersection = $iYTemp + $iPlayerPosY

            $iGridVertical -= 1
        EndIf

        If $iCastArc == $ANGLE_90 Or $iCastArc == $ANGLE_270 Then
            $fDistToVerticalGridBeingHit = 9999999
        Else
            $fDistToNextYIntersection = $aYStepTable[$iCastArc]

            While True
                $iGridIndexX = Int($iGridVertical / $iTileSize)
                $iGridIndexY = Int($fYIntersection / $iTileSize)

                If $iGridIndexX >= $iMapWidth Or $iGridIndexY >= $iMapHeight Or $iGridIndexX < 0 Or $iGridIndexY < 0 Then
                    $fDistToVerticalGridBeingHit = 9999999

                    ExitLoop
                ElseIf $aMap[$iGridIndexY][$iGridIndexX] <> $sMapIndex_Empty Then
                    $fDistToVerticalGridBeingHit = ($fYIntersection - $iPlayerPosY) * $aISinTable[$iCastArc]

                    ExitLoop
                Else
                    $fYIntersection += $fDistToNextYIntersection
                    $iGridVertical += $iDistToNextVerticalGrid
                EndIf
            WEnd
        EndIf

        If $fDistToHorizontalGridBeingHit < $fDistToVerticalGridBeingHit Then
            $fDist = $fDistToHorizontalGridBeingHit
            ;_GDIPlus_BrushSetSolidColor($hPen, 0xFF444444)
        Else
            $fDist = $fDistToVerticalGridBeingHit
            ;_GDIPlus_BrushSetSolidColor($hPen, 0xFF343434)
        EndIf

        $fDist /= $aFishTable[$iCastColumn]
        $iProjectedWallHeight = Int($iWallHeight * $iPlayerDistanceToTheProjectPlane / $fDist)
        $iBottomOfWall = $iProjectionPlaneYCenter + Int($iProjectedWallHeight * 0.5)
        $iTopOfWall = $iHeight - $iBottomOfWall

        If $iBottomOfWall >= $iHeight Then
            $iBottomOfWall = $iHeight - 1
        EndIf

        _GDIPlus_BrushSetSolidColor($hPen, "0xFF" & Hex(Int($iProjectedWallHeight / 4), 2) & Hex(Int($iProjectedWallHeight / 4), 2) & Hex(Int($iProjectedWallHeight / 4), 2))
        _GDIPlus_GraphicsFillRect($hBuffer, $iCastColumn, $iTopOfWall, 5, $iProjectedWallHeight, $hPen)

        $iCastArc += 5
        If $iCastArc >= $ANGLE_360 Then
            $iCastArc -= $ANGLE_360
        EndIf
    Next

    $iPlayerMovementSpeed = Round(1 / $iFrameTime) / 3
    $iPlayerTurnSpeed = Round(1 / $iFrameTime) * 2

    _GDIPlus_GraphicsDrawImageRect($hGraphic, $hBitmap, 0, 0, $iWidth, $iHeight)
EndFunc

;----------------------------------------------------

 

image.pngimage.pngimage.png

Articles and code samples  i used:

http://lodev.org/cgtutor/raycasting.html

http://www.permadi.com/java/rayc/Rayc.java

Edited by Fever
  • Like 1

Share this post


Link to post
Share on other sites
mLipok

cool

keep it up


Signature beginning:   Wondering who uses AutoIT and what it can be used for ?
* GHAPI UDF - modest begining - comunication with GitHub REST API *
ADO.au3 UDF     POP3.au3 UDF     XML.au3 UDF    How to use IE.au3  UDF with  AutoIt v3.3.14.x  for other useful stuff click the following button

Spoiler

Any of my own code posted anywhere on the forum is available for use by others without any restriction of any kind. 

My contribution (my own projects): * Debenu Quick PDF Library - UDF * Debenu PDF Viewer SDK - UDF * Acrobat Reader - ActiveX Viewer * UDF for PDFCreator v1.x.x * XZip - UDF * AppCompatFlags UDF * CrowdinAPI UDF * _WinMergeCompare2Files() * _JavaExceptionAdd() * _IsBeta() * Writing DPI Awareness App - workaround * _AutoIt_RequiredVersion() * Chilkatsoft.au3 UDF * TeamViewer.au3 UDF * JavaManagement UDF * VIES over SOAP * WinSCP UDF * GHAPI UDF - modest begining - comunication with GitHub REST API *

My contribution to others projects or UDF based on  others projects: * _sql.au3 UDF  * POP3.au3 UDF *  RTF Printer - UDF * XML.au3 UDF * ADO.au3 UDF SMTP Mailer UDF *

Useful links: * Forum Rules * Forum etiquette *  Forum Information and FAQs * How to post code on the forum * AutoIt Online Documentation * AutoIt Online Beta Documentation * SciTE4AutoIt3 getting started * Convert text blocks to AutoIt code * Games made in Autoit * Programming related sites * Polish AutoIt Tutorial * DllCall Code Generator * 

Wiki: Expand your knowledge - AutoIt Wiki * Collection of User Defined Functions * How to use HelpFile * Good coding practices in AutoIt * 

IE Related:  * How to use IE.au3  UDF with  AutoIt v3.3.14.x * Why isn't Autoit able to click a Javascript Dialog? * Clicking javascript button with no ID * IE document >> save as MHT file * IETab Switcher (by LarsJ ) * HTML Entities * _IEquerySelectorAll() (by uncommon) * 

I encourage you to read: * Global Vars * Best Coding Practices * Please explain code used in Help file for several File functions * OOP-like approach in AutoIt * UDF-Spec Questions *  EXAMPLE: How To Catch ConsoleWrite() output to a file or to CMD *

"Homo sum; humani nil a me alienum puto" - Publius Terentius Afer
"Program are meant to be read by humans and only incidentally for computers and execute" - Donald Knuth, "The Art of Computer Programming"
:naughty:  :ranting:, be  :) and       \\//_.

Anticipating Errors :  "Any program that accepts data from a user must include code to validate that data before sending it to the data store. You cannot rely on the data store, ...., or even your programming language to notify you of problems. You must check every byte entered by your users, making sure that data is the correct type for its field and that required fields are not empty."

Signature last update: 2018-03-17

Share this post


Link to post
Share on other sites
UEZ

Looks very cool! I'm curious to see how you want to implement textures with GDI+. ;)

Btw, long time ago Eukalyptus coded a prototype of 3D Wolfenstein with textures -> Prototype 3D Wolfenstein in AutoIt (video only)!

Br,

UEZ

Edited by UEZ
  • Like 1

Please don't send me any personal message and ask for support! I will not reply!

Selection of finest graphical examples at Codepen.io

The own fart smells best!
Her 'sikim hıyar' diyene bir avuç tuz alıp koşma!
¯\_(ツ)_/¯  ٩(●̮̮̃•̃)۶ ٩(-̮̮̃-̃)۶ૐ

Share this post


Link to post
Share on other sites
mLipok

Really kewl.  Can't wait for more.

kewl ?

what this mean ?


Signature beginning:   Wondering who uses AutoIT and what it can be used for ?
* GHAPI UDF - modest begining - comunication with GitHub REST API *
ADO.au3 UDF     POP3.au3 UDF     XML.au3 UDF    How to use IE.au3  UDF with  AutoIt v3.3.14.x  for other useful stuff click the following button

Spoiler

Any of my own code posted anywhere on the forum is available for use by others without any restriction of any kind. 

My contribution (my own projects): * Debenu Quick PDF Library - UDF * Debenu PDF Viewer SDK - UDF * Acrobat Reader - ActiveX Viewer * UDF for PDFCreator v1.x.x * XZip - UDF * AppCompatFlags UDF * CrowdinAPI UDF * _WinMergeCompare2Files() * _JavaExceptionAdd() * _IsBeta() * Writing DPI Awareness App - workaround * _AutoIt_RequiredVersion() * Chilkatsoft.au3 UDF * TeamViewer.au3 UDF * JavaManagement UDF * VIES over SOAP * WinSCP UDF * GHAPI UDF - modest begining - comunication with GitHub REST API *

My contribution to others projects or UDF based on  others projects: * _sql.au3 UDF  * POP3.au3 UDF *  RTF Printer - UDF * XML.au3 UDF * ADO.au3 UDF SMTP Mailer UDF *

Useful links: * Forum Rules * Forum etiquette *  Forum Information and FAQs * How to post code on the forum * AutoIt Online Documentation * AutoIt Online Beta Documentation * SciTE4AutoIt3 getting started * Convert text blocks to AutoIt code * Games made in Autoit * Programming related sites * Polish AutoIt Tutorial * DllCall Code Generator * 

Wiki: Expand your knowledge - AutoIt Wiki * Collection of User Defined Functions * How to use HelpFile * Good coding practices in AutoIt * 

IE Related:  * How to use IE.au3  UDF with  AutoIt v3.3.14.x * Why isn't Autoit able to click a Javascript Dialog? * Clicking javascript button with no ID * IE document >> save as MHT file * IETab Switcher (by LarsJ ) * HTML Entities * _IEquerySelectorAll() (by uncommon) * 

I encourage you to read: * Global Vars * Best Coding Practices * Please explain code used in Help file for several File functions * OOP-like approach in AutoIt * UDF-Spec Questions *  EXAMPLE: How To Catch ConsoleWrite() output to a file or to CMD *

"Homo sum; humani nil a me alienum puto" - Publius Terentius Afer
"Program are meant to be read by humans and only incidentally for computers and execute" - Donald Knuth, "The Art of Computer Programming"
:naughty:  :ranting:, be  :) and       \\//_.

Anticipating Errors :  "Any program that accepts data from a user must include code to validate that data before sending it to the data store. You cannot rely on the data store, ...., or even your programming language to notify you of problems. You must check every byte entered by your users, making sure that data is the correct type for its field and that required fields are not empty."

Signature last update: 2018-03-17

Share this post


Link to post
Share on other sites
michaelslamet

kewl ?

what this mean ?

 

kewl = cool :P

Share this post


Link to post
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
Sign in to follow this  

  • Similar Content

    • UEZ
      By UEZ
      AutoIt Windows Screenshooter
      Key Features:
      takes easily a screenshot from any visible window capture any region of the desktop incl. freehand capturing capture GUI controls and GUI menus separately capture a marked area every x seconds for a duration of y seconds create a GIF animation from saved frames (Vista or higher os required) capture to AVI file (without audio!) takes a screenshot from web sites (available only on Win7+ os and when Aero is enabled) put images to clipboard to paste to other applications easily color picker save image in different formats and also to PDF! add timestamp to saved images simple image editing options: greyscale, b&w, invert, rotate +-90° send image to printer and default email client preview of captured screens incl. zoom option multi monitor support display pixel color under mouse ruler basic image editor (paint, highlight, ellipse, rectangle, text and some graphic FX) watermark captured image no 3rd party tools or DLLs used - pure AutoIt! fully portable - no installation is needed multi language feature (Eng, Ger, Tur, Fra and Rus only) To do:
      capture content of scrollable window/control capture cascaded menus Due to DllCall("User32.dll", "int", "PrintWindow", "hwnd", $hWnd, "handle", $hMemDC, "int", 0) limitation some windows cannot be captured properly (GDI+, ProgDVB, etc.) but can take screenshots of hidden windows. One workaround is to use full screen capturing (F11/F12) or "Grab Screen" function! Or try double click with rmb on listview items (beta).
      Download source code (6295 downloads previously):  AutoIt Windows Screenshooter v1.81 Build 2018-08-12.7z (version 3.3.12.0+ needed!)
      You are not allowed to sell this code or just parts of it in a commercial project or modify it and distribute it with a different name!
      Download compiled Exe only: 4shared / Media Fire / Softpedia (1.54mb)
      Distributing copies of the program in compiled format (exe) must be free of any fee!
      -----> click here to Donate!  
       
      (Current donators: 1. Cuong N.) 
      It is designed for Win7+ operating systems with AERO enabled! E.g. on WinXP machines some functions are not working properly and might crash the application!
      AV scanners may have a negative impact the execution of compiled exe and might report any malware. I guarantee that there is no malicious code in the source code / exe!!! 
      Main GUI:

       
       
      About Intro:

       
       
      Basic Image Editor:

       
       
      Watermark:

       
       
      Click link for an enhanced version of Watermark Image.
      Credits:
      main code by UEZ additional code (alphabetical order) by Authenticity, AutoItObject Team, Eemuli, Eukalyptus, funkey, _Kurt, martin, monoceres, ProgAndy, taietel, trancexx, Ward, wolf9228 and Yashied! mesale0077 for turkish translation wakillon for french translation AZJIO for russian translation Keys:
      Main GUI:
      User your mouse to scroll preview window or
      Numpad 8: Scroll preview window up
      Numpad 2: Scroll preview window down
      Numpad 4: Scroll preview window left
      Numpad 6: Scroll preview window right
      Numpad +: zoom in preview window or mousewheel down
      Numpad -: zoom out preview window or mousewheel up
      F1: capture again on last position
      F5: refresh Windows Name list
      PRINTSCREEN: take screenshot from whole screen
      ALT+PRINTSCR: take a screenshot from active window
      F10: Undo made changes with Image Editing function
      F11: take screenshot from whole screen incl mouse cursor
      F12: take screenshot from whole screen
      Ctrl+Alt+F9 start "Grab Screen" mode
      Ctrl+Alt+F12: take a screenshot from active window using alternative screenshot functionality (beta)!
      Ctrl+r: call ruler
      Ctrl+s: save current displayed image
      Ctrl+x: exit program
      ctrl+w: call web grab input field (availabe only when Aero is enabled)
      Ctrl+i: call image editor
      Ctrl+m: call watermark editor
      Ctrl+z: undo
      Only available on Vista+ os: double click with rmb on list items to use alternative screenshot functionality (beta)!
      When 'Grab Screen' is clicked you can hold down the ctrl key to switch to 'grab controls' mode. Control under mouse will be framed red.
      ctrl + shift will take the screenshot of appropriate control. To capture GUI menues you can press rmb which simulates the lmb. When a menu is opened press shift additionaly to capture it.
      Press and hold only the shift key to capture any region on the desktop using freehand capturing - release it so capture marked regions!
      Or just mark resizeable area which you want to grab. Press CTRL key to grab marked area or right mouse button to capture the marked area every x seconds for a duration of y seconds.
      When saving the image just enter the extension you whish to use (*.jpg;*.png;*.bmp;*.gif;*.tif;*.pdf). Big thanks to taietel for his PDF UDF!
      Image Editor:
      s: save
      c: copy
      n: send
      h: highlighter
      p: pen
      r: rectangle
      e: ellipse
      a: arrow
      o: color
      t: text
      g: text config
      Ctrl+z: undo
      Watermark editor:
      Ctrl+z: undo
       
      To start the app minimized just call it "Windows Screenshooter.exe /min"
      Maybe it is useful for someone...
      Any kind of comment is welcome.
      Br,
      UEZ
      Change log:
       
    • MrCheese
      By MrCheese
      hi all,
      Dumb question, but say I have a loop:
      dim $i Do     sleep(1000)          if $i = ; how do i do a function that enters this IF statement every 10 loops?         ; do stuff every 10     EndIf      Until $i = 100  
      - what commands in the if statement do I need to use to make it pass, and on every 10th loop, it enters the if statement. ?
       
      Thanks
    • c.haslam
      By c.haslam
      I think that _GDIPlus_ImageGetPropertyItem should return a Property Item that can readily be set as a property of another image. Why would one want to do this? A script might (as one of mine does) edit an image of a .jpg file then write the result to a .jpg file. In editing it, in my case, the number of horizontal and vertical pixels change, and the date/time edited should be set as a property. All other property items remain the same. Other GDI+ users may change other properties.
      So an approach is to copy all the property items from image1 to image2, then update a few properties.
      M$ provides a Property Item class (id, length, pointer to an array of values) but _GDIPlus_ImageGetPropertyItem returns something different.
      I think that, wherever reasonable, UDFs that are wrappers for M$ methods should work like M$'s methods. _GDIPlus_ImageGetPropertyItem does not do this:
      While M$ returns 2 values for a value that is a ratio of 2 numbers,  _GDIPlus_ImageGetPropertyItem returns numerator/denominator as a single value (often a Double). _GDIPlus_ImageSetPropertyItem (when included in GDIPlus.au3) will be unable to set ratio property items properly because it cannot know what the numerator and denominator are. So copying such property items will not work properly. M$ has a Void* buffer where the buffer is an array of values but _GDIPlus_ImageGetPropertyItem() returns the values in the same 1-d array as id, length and type. M$'s approach produces a 1-d array with the same number of elements for all property items while _GDIPlus_ImageGetPropertyItem produces a 1-d array with various numbers of elements. To me, this is not good programming practice. For a photo from a Sony camera, the worst case has 1-d array with 67 elements. When combined into a 2-d array with the property items of all properties, there are 66 rows and 67 columns, with many elements not used. So I suggest that _GDIPlus_ImageGetPropertyItem look like this:
      ; #FUNCTION# ==================================================================================================================== ; Name ..........: cGDIPlus_ImageGetPropertyItem ; Description ...: Gets a specified property item (piece of meta data) from an Image object ; Syntax ........: cGDIPlus_ImageGetPropertyItem($hImage, $iPropID) ; Parameters ....: $hImage - Pointer to an image object ; $iPropID - Identifier of the property item to be retrieved ; Return values .: Success: Array containing the values of the property item ; [0] - identifier ; [1] - size, in bytes, of the value array ; [2] - type of value(s) in the value array ; [3] - value array ; Failure: Sets the @error flag to non-zero, @extended may contain GPSTATUS error code ($GPID_ERR*). ; Author ........: Eukalyptus ; Modified ......: c.haslam ; Remarks .......: types: unsigned byte = 1, ASCII string = 2, unsigned short = 3, unsigned long = 4, ; unsinged rational = 5, undefined = 7, signed long = 9, signed rational = 10 ; Related .......: _GDIPlus_ImageGetPropertyIdList ; Link ..........: https://msdn.microsoft.com/en-us/library/windows/desktop/ms535390(v=vs.85).aspx, ; https://msdn.microsoft.com/en-us/library/windows/desktop/ms534493(v=vs.85).aspx, ; https://msdn.microsoft.com/en-us/library/windows/desktop/ms534414(v=vs.85).aspx ; Example .......: Yes ; =============================================================================================================================== Func cGDIPlus_ImageGetPropertyItem($hImage, $iPropID) Local $iSize = __GDIPlus_ImageGetPropertyItemSize($hImage, $iPropID) If @error Then Return SetError(@error, @extended, -1) Local $tBuffer = DllStructCreate("byte[" & $iSize & "];") Local $pBuffer = DllStructGetPtr($tBuffer) Local $aResult = DllCall($__g_hGDIPDll, "int", "GdipGetPropertyItem", "handle", $hImage, "uint", _ $iPropID, "uint", $iSize, "struct*", $tBuffer) If @error Then Return SetError(@error, @extended, -1) If $aResult[0] Then Return SetError(10, $aResult[0], False) Local $tPropertyItem = DllStructCreate("int id; int length; short type; ptr pvalue;", $pBuffer) Local $iBytes = DllStructGetData($tPropertyItem, "length") Local $pValue = DllStructGetData($tPropertyItem, "pvalue") Local $aRet[4] Local $type = DllStructGetData($tPropertyItem,'type') Local $tValues, $iValues Switch $type Case 2 ;ASCII String $iValues = 1 $tValues = DllStructCreate("char[" & $iBytes & "];", $pValue) Case 3 ;Array of UShort $iValues = Int($iBytes / 2) $tValues = DllStructCreate("ushort[" & $iValues & "];", $pValue) Case 4, 5 ;Array of UInt / Fraction $iValues = Int($iBytes / 4) $tValues = DllStructCreate("uint[" & $iValues & "];", $pValue) Case 9, 10 ;Array of Int / Fraction $iValues = Int($iBytes / 4) $tValues = DllStructCreate("int[" & $iValues & "];", $pValue) Case Else ;Array of Bytes $iValues = 1 $tValues = DllStructCreate("byte[" & $iBytes & "];", $pValue) EndSwitch $aRet[0] = DllStructGetData($tPropertyItem,'id') $aRet[1] = $iBytes $aRet[2] = $type Local $aVals[$iValues] If $type=2 Or $type=7 Then ; ASCII string or undefined $aVals[0] = DllStructGetData($tValues,1) Else For $i = 0 To $iValues-1 $aVals[$i] = DllStructGetData($tValues,1,$i+1) Next EndIf $aRet[3] = $aVals Return $aRet EndFunc And here is an example:
      #include <GDIPlus.au3> #include <Array.au3> Example() Func Example() _GDIPlus_Startup() Local $hImage = _GDIPlus_ImageLoadFromFile(RegRead((@AutoItX64 = True ? "HKLM\SOFTWARE\Wow6432Node\AutoIt v3\AutoIt" : "HKLM\SOFTWARE\AutoIt v3\AutoIt"), "InstallDir") & "\Examples\GUI\Torus.png") If @error Then _GDIPlus_Shutdown() MsgBox(16, "", "An error has occured - unable to load image!", 30) Return False EndIf Local $ar = _GDIPlus_ImageGetPropertyIdList($hImage) Local $vPropNbrs[UBound($ar,1)-1] ; Extract ID numbers For $i = 1 To UBound($ar,1)-1 $vPropNbrs[$i-1] = $ar[$i][0] Next ; Get all property items Local $aPropItems[UBound($vPropNbrs)][4],$vPropItem For $i = 0 To UBound($vPropNbrs)-1 $vPropItem = cGDIPlus_ImageGetPropertyItem($hImage,$vPropNbrs[$i]) For $j = 0 To 3 $aPropItems[$i][$j] = $vPropItem[$j] Next Next ; Collapse values arrays so _ArrayDisplay can display them Local $ar = $aPropItems For $i = 0 To UBound($aPropItems,1)-1 $ar[$i][0] = '0x'&Hex($ar[$i][0],4) $ar[$i][3] = '' For $j = 0 To UBound($aPropItems[$i][3])-1 $ar[$i][3] &= ($aPropItems[$i][3])[$j]&'|' Next $ar[$i][3] = StringTrimRight($ar[$i][3],1) Next _ArrayDisplay($ar) _GDIPlus_Shutdown() EndFunc Unfortunately this example (based on one now in the Help) does not exercise most of the item types, but I do not know of a file with EXIF metadata that is on most PCs. I have tested this code by updating and adding property items to torus.jpg and to a photo taken by a Sony camera. The code for implementing and calling _GDIPlus_ImageSetPropertyItem will be fairly simple [see below].
       
      Your thoughts?
       
    • c.haslam
      By c.haslam
      I have a strange symptom of a problem somewhere in my code, or in a UDF: when I add code to get all properties of a GDI+ image to a 6000-line script,  the variable type of a parameter is reported as a pointer when the caller clearly has this argument as a string. If I comment out my code that gets the properties, the function properly sees the parameter as a string.
      [Edit: The reporting as a pointer and getting image properties are miles apart, both in where they are in the script code and in where they are run.]
      At this point, I am looking for clues as to why this is happening, so the hunt is on!
      I have noticed one odd thing, in _GDIPlus_ImageGetPropertyIdList() I see a line that begins Local $sPropertyTagInfo = . This "line" is split into 2 lines. SCiTE shows that the first line is 2454 characters and the second 2400. Adding these numbers I get 4854 characters.
      But the Help for AutoIt3 Limits/defaults says that MAXLINESIZE, Maximum size for a line of script, is 4096 characters.
      The line would exceed the limit if AutoIt considers the subject line to be 1 line and not 2 lines.
      My question: is this line legal? Is buffer overun possible?
    • c.haslam
      By c.haslam
      I find _GDIPlus_ImageClone in the Help, but neither in SciTe auto-complete nor in GDIPlus.au3
      Shoud this be reported in Trac?
      By searching the forum (and changing the name of the first arguement ot DLLCall, the code appears to be:
      Func _GDIPlus_ImageClone($hImage) Local $aResult = DllCall($__g_hGDIPDll, "uint", "GdipCloneImage", "handle", $hImage, "int*", 0) If @error Then Return SetError(@error, @extended, 0) Return $aResult[2] EndFunc ;==>_GDIPlus_ImageClone  
×