Jump to content

Search the Community

Showing results for tags 'bmp'.

  • Search By Tags

    Type tags separated by commas.
  • Search By Author

Content Type


Forums

  • General
    • Announcements and Site News
    • Administration
  • AutoIt v3
    • AutoIt Help and Support
    • AutoIt Technical Discussion
    • AutoIt Example Scripts
  • Scripting and Development
    • Developer General Discussion
    • Language Specific Discussion
  • IT Administration
    • Operating System Deployment
    • Windows Client
    • Windows Server
    • Office

Categories

  • AutoIt Team
    • Beta
    • MVP
  • AutoIt
    • Automation
    • Databases and web connections
    • Data compression
    • Encryption and hash
    • Games
    • GUI Additions
    • Hardware
    • Information gathering
    • Internet protocol suite
    • Maths
    • Media
    • PDF
    • Security
    • Social Media and other Website API
    • Windows
  • Scripting and Development
  • IT Administration
    • Operating System Deployment
    • Windows Client
    • Windows Server
    • Office

Find results in...

Find results that contain...


Date Created

  • Start

    End


Last Updated

  • Start

    End


Filter by number of...

Joined

  • Start

    End


Group


Member Title


Location


WWW


Interests

Found 13 results

  1. Browsing a Chinese AutoIt forum, i fall on a little pearl that i want to share with you ! I have already seen water effects example with autoit, but this one is very easy to create using waterctrl.dll Only BMP are supported. Position of Blob water can be set by coordinates and mouse movements (and clicks) when over bmp create traces on water. All files are embeded in script with BinaryToAu3Kompressor. WaterEffect.au3 Hope you like it !
  2. wakillon

    WaterEffect

    1,060 downloads

    Create water effects using waterctrl.dll. Topic
  3. Hello all. I am trying to figure out the best approach to compare PDF outputs for consistency. Currently, this is a human task where PDFs are held up to a light to see if all the values line up exactly with test data. I have to believe there is a better way. That said GDIPlus is a bit of a mystery to me - I have looked at some of the functions - and I stumbled upon >this very useful script in my forum search. My question is: would converting the PDF to an image and comparing the image with GDIPlus be the way to go or is there a different more efficient approach that you would recommend? Any guidance would be greatly appreciated. JFish
  4. I'm trying to use '?do=embed' frameborder='0' data-embedContent>> but none of the examples work. Mostly, I'm just not seeing any pictures, just nothing, a window with some text but no picture. What am I doing wrong? Do these examples work for anybody else?
  5. I'd like to load a BMP file then change chosen color (0xFF00FF) to transparent and save it as PNG file. I'm using a code from other thread. I've modified it a little, but it still doesn't work. My program displays image with transparent color correctly, however saves a black image file. #include <Constants.au3> #include <WinAPIEx.au3> #include <WindowsConstants.au3> #include <GUIConstantsEx.au3> #include <ScreenCapture.au3> #include <WinAPI.au3> Global Const $STM_SETIMAGE = 0x0172 Global Const $STM_GETIMAGE = 0x0173 $hForm = GUICreate('MyGUI', 400, 400) $Pic = GUICtrlCreatePic('', 50, 50, 144, 87) $hPic = GUICtrlGetHandle(-1) _GDIPlus_Startup() $hDstDC = _WinAPI_CreateCompatibleDC(0) $hBitmap = _WinAPI_CreateSolidBitmap(0, _WinAPI_GetSysColor($COLOR_3DFACE), 144, 87, 0) $hDstSv = _WinAPI_SelectObject($hDstDC, $hBitmap) $hSrcDC = _WinAPI_CreateCompatibleDC(0) $hImg = _WinAPI_LoadImage(0, @ScriptDir & '\piclvq.bmp', $IMAGE_BITMAP, 0, 0, $LR_LOADFROMFILE) $hSrcSv = _WinAPI_SelectObject($hSrcDC, $hImg) _WinAPI_TransparentBlt($hDstDC, 0, 0, 144, 87, $hSrcDC, 0, 0, 144, 87, 0xFF00FF) $hGraphic = _GDIPlus_GraphicsCreateFromHWND($hForm) $hImage = _GDIPlus_BitmapCreateFromGraphics(144, 87, $hGraphic) ; Save resultant image _GDIPlus_ImageSaveToFile($hImage, "My_transparent_image.png") _WinAPI_SelectObject($hDstDC, $hDstSv) _WinAPI_DeleteDC($hDstDC) _WinAPI_SelectObject($hSrcDC, $hSrcSv) _WinAPI_DeleteDC($hSrcDC) _WinAPI_DeleteObject($hImg) _WinAPI_DeleteObject(_SendMessage($hPic, $STM_SETIMAGE, $IMAGE_BITMAP, $hBitmap)) $hPic = _SendMessage($hPic, $STM_GETIMAGE) If $hPic <> $hBitmap Then _WinAPI_DeleteObject($hBitmap) EndIf GUISetState() Do Until GUIGetMsg() = -3 piclvq.bmp
  6. Here's a simple script I'm testing the ScreenCapture function with. #include <ScreenCapture.au3> #include <WindowsConstants.au3> #include <GUIConstantsEx.au3> ; Capture region _ScreenCapture_Capture(@ScriptDir & "\image.bmp", 290,18,1465,652,0) $form=GUICreate("Test",1175,634,290,18,BitOR($WS_SYSMENU,$WS_POPUP),$WS_EX_COMPOSITED) $PSimage=GUICtrlCreatePic(@ScriptDir & "\image.bmp", 0,0,1175,634) GUISetState(@SW_SHOW) MsgBox(0,"","Test of screen cap and display.") . The above script captures an area of the screen (the SciTE editor with this script open), writes it to image.bmp, and displays image.bmp. The problem I'm having is when image.bmp is displayed using GUICtrlCreatePic the result is fuzzy. Here's a SnagIt screen capture of what GUICtrlCreatePic displays. Attached is image.bmp, which is sharp and equivalent to seeing the actual script open in SciTE on-screen. Any suggestions for displaying an accurate rendition of ScreenCapture's output? (Must be borderless, no chrome, etc. -- equivalent to what my test script yields.) image.bmp
  7. To save future readers a little sweat I'm editing my original post to insert the following: After trying various suggested scripting approaches, some of which introduced new problems and some which had the same problem described here, I tried my script and a few others on another computer. No white flashes, tears, glitches. So I brought it back to my main box and disabled the Intel GPU that was feeding a 3rd monitor. Down to two monitors connected to a single NVidia GPU the visual glitches disappeared. Who would'a thought?! That said, some of the replies that follow provide valuable insights into the various ways to skin this cat using AutoIt. Some suggested scripts introduced new problems so they might be instructive about approaches to avoid. Ultimately, JohnOne suggested an elegantly simple script that perfectly accomplishes my goal. --------------------- I want to display a 800x600 picture (i.e., not full-screen) without a border, close-box, title, etc. I then want to replace that picture with another one -- cleanly. Think of an old-fashioned dual-projector slide show where there's no black-out or other interruption to the image on screen. This way I can start with a background image, then add elements to it seamlessly (once called "a build", i.e., pseudo-animation). The image format doesn't matter to me. I can't use an animated GIF or video because my code is doing things in the background between images, so timing varies. I'm having bad luck using an AutoIt form to accomplish this (GUICtrlCreatePic, followed by subsequent GUICtrlSetImage's). The result is a glitch -- usually a white flash or tear in the picture -- at almost every image change. (see 10/10/13 post entitled "random visual glitch when using GUICtrlSetImage"). So I guess that's out. SplashImageOn blanks out the first image before displaying the next (like a single-projector slide show), so it's not seamless -- plus there's still a tiny border visible. $var = Default SplashImageOn("","image1.bmp",$var,$var,$var,$var,1) sleep(2000) SplashImageOn("","image2.bmp",$var,$var,$var,$var,1) sleep(2000) SplashImageOn("","image3.bmp",$var,$var,$var,$var,1) sleep(2000) Any suggestions?
  8. I'm displaying a series of BMP images using AutoIt's GUI capabilities. Here's my initial test code. All it does is test my goal of displaying a picture, then allowing some code to accomplish a brief task, followed by the next picture, etc. The problem I'm having is that sometimes there's a brief visual glitch in the picture when GUICtrlSetImage displays the next picture. This doesn't happen every time but it happens enough to make the result look funky. Any suggestions about what I can do to prevent the glitch? Could it be the specs of the BMP images I'm creating in Photoshop CS6? Under BMP Options I'm using 24 Bit depth, no RLE compression -- ie., the defaults. (note that I've tried using jpg's instead of bmp file without improvement) $form=GUICreate("PowerStrips",900,530,518,272, BitOR($WS_SYSMENU,$WS_POPUP), 0) $cid=GUICtrlCreatePic(@ScriptDir & "\imagebackground.bmp", 0,0, 900, 530) GuiCtrlSetState($cid,$GUI_DISABLE) ;The initial "button" I want to show $PSimage=GUICtrlCreatePic(@ScriptDir & "\image1.bmp", 0,0,900,530) GUISetState(@SW_SHOW) ;show 1st image MsgBox(0,"","test") GUICtrlSetImage($PSimage, @ScriptDir & "\image2.bmp") ;show 2nd image MsgBox(0,"","test") GUICtrlSetImage($PSimage,@ScriptDir & "\image3.bmp") ;show 3rd image MsgBox(0,"","test") GUICtrlSetImage($PSimage,@ScriptDir & "\image4.bmp") 'show 4th image MsgBox(0,"","test") Exit
  9. In a script I'm using the GuiCtrlSetImage command to display a bmp image created in Illustrator. When exporting to bmp from Illustrator the Basic options include 16 bit, 24 bit, and 32 bit. (all are RGB, 72ppi, with anti-aliasing = "art optimized" (though I tried "none" and it made no difference to the outcomes shown)) Following are screen captures of how AutoIt's GuiCtrlSetImage command renders the bmp image. 32 bit original (note ragged edges) 24 bit original (looks closest to original, but there are some black pixel artifacts in the top left chrome border, so it ain't perfect) 16 bit original (note lots of breakup in chrome border and black pixels around border of white silhouette) As you see, the 24 bit capture is the only acceptable one. However, I had to compromise on the graphic because originally it had "inner glow" effects in the white areas. Below is a screen capture of what AutoIt did to this 24 bit image. The only difference between this and the previous 24 bit image is that this one has an inner glow (gray to white gradient along edges of white silhoutte) effect. Either there's a bug in AutoIt or my bmp files are incompatible in some way. Can anyone tell me the ideal specs for a bmp image for use with GuiCtrlSetImage? In case it helps, below are some of Illustrator's Advanced Export-to-bmp options (I used the Basic Modes described at the top). Note also that I brought the image into Photoshop and saved it as a bump there, and I got the same artifacts.
  10. Hi all I am wondering if someone knows what could be causing the images in my GUI to display little black squares all over them. They seem to change depending on how much code is in the file/program. I have attached two examples, the first is from a set of buttons called using GUICtrlCreatePic and they are in BMP format Shows a screenshot of the GUI image on the left and the original images on the right The second is also called using GUICtrlCreatePic but they are in JPG format Shows a screenshot of the GUI image on the top and the original image on the bottom Both of them display the same problem although in earlier versions of the code it seemed to just exist on the BMP buttons, although i havent been watching it closely until i noticed them in both places today. They show up whether the script is compiled or not. Thanks in advance Adam
  11. Identicon.au3 v0.8 A simple UDF to create identicons or visual representations of any hash value. Based on Don Park's original Identicon program. Main features: 3x3 and 4x4 grid patterns.Aside from rotational symmetry there are also checkerboard and Space Invader (mirror symmetry) patterns.Adapted to handle hashes up to SHA512.Save as PNG, JPG, GIF or BMP identicons.Alpha-transparency support for PNG.The UDF and a demo:Identicon.au3 Identicon-Demo.au3 Version 0.8: * Initial public release. To do: * In the checkerboard pattern there is a bias for diamond shapes. * Improve image saving, BMP, GIF and JPG suck, much artifacts and dithering. * Transparency doesn't work with GIF (and BMP?) due to the wrong Bitmap format. * Add some more unique sprite shapes and preferably cap the shape arrays at powers of two as BitAND is faster than a modulus operation.
  12. I know there are snippet threads, but I'd like this one to be specific. I've see quite a few neat GDI+ code snippets (UEZ and Progandy come to mind first) to manipulate, create, etc, and I thought it'd be neat to be able to find them under one thread. I'm going to reserve the next 3 posts because I'm unsure at the moment if it's the "Quote" or "Spoiler" bbcode tags that has the 10 limit. You can link or post the snippets you find or create and I'll title them and put them in the threads for everyone to find. ( Going to have to remember to edit with regular editor! ) Some of these may not have titles, so I may create my own, if the author(s) want(s) a different one, let me know. _GDIPlus_WaterMark.au3 - Author: UEZ - Added: 2012-10-13 - Updated: _GDIPlus_BMPFromMemory – Author UEZ – Added: 2012-10-14 – Updated: Example – Needle Movement (4bit example provided, link to 32bit found in code) – Author: UEZ - Added: 2012-10-14 – Updated:
  13. This is my maze generator. It creates a maze useing the Recursive backtracker witch i found here: http://en.wikipedia.org/wiki/Maze_generation_algorithm#Recursive_backtracker It'll save the finished maze in the a folder with the name Mazes in @scriptdir as Maze (Seed).bmp where Seed is the seed of the maze and size is the size. It usees the Bitmap Libray by evelertoaster find it here: Thanks to MvGulik for cleaning the code. Here's a picture of a finished 25*25 maze: The green dot is the start and the red dot is the end. It can also solve the maze. Here's the solution for the above 25*25 maze. So here's the code: ;~ #AutoIt3Wrapper_Au3Check_Stop_OnWarning=y ;~ #AutoIt3Wrapper_AU3Check_Parameters=-q -d -w 1 -w 2 -w 3 -w 4 -w 5 -w 6 -w 7 ;Thanks to MvGulik (http://www.autoitscript.com/forum/user/14111-mvgulik/) for cleaning up the code. And for RND_SeedTimed function #region Decleres and includes ;Add the needed includes #include <Array.au3> #include <ButtonConstants.au3> #include <EditConstants.au3> #include <GUIConstantsEx.au3> #include <StaticConstants.au3> #include <WindowsConstants.au3> #include "BMP3.au3" ; Downloaded from http://www.autoitscript.com/forum/topic/27362-bitmap-library/ #endregion Decleres and includes #Region ### START Koda GUI section ### Form=*** $Gui = GUICreate("Maze Generator", 673, 728, 299, 77) $GenerateButton = GUICtrlCreateButton("Generate!", 528, 8, 137, 49) GUICtrlSetFont(-1, 17, 400, 0, "MS Sans Serif") $SizeXLabel = GUICtrlCreateLabel("X:", 8, 24, 19, 24) GUICtrlSetFont(-1, 12, 400, 0, "MS Sans Serif") $SizeYLabel = GUICtrlCreateLabel("Y:", 112, 24, 19, 24) GUICtrlSetFont(-1, 12, 400, 0, "MS Sans Serif") $SolveCheck = GUICtrlCreateCheckbox("Solve maze?", 384, 24, 137, 20) GUICtrlSetFont(-1, 15, 400, 0, "MS Sans Serif") $MazeYInput = GUICtrlCreateInput("", 136, 24, 57, 21, BitOR($GUI_SS_DEFAULT_INPUT,$ES_NUMBER)) $MazeXInput = GUICtrlCreateInput("", 32, 24, 57, 21, BitOR($GUI_SS_DEFAULT_INPUT,$ES_NUMBER)) $SizeLabel = GUICtrlCreateLabel("Size:", 80, 0, 39, 24) GUICtrlSetFont(-1, 13, 400, 0, "MS Sans Serif") $SeedLabel = GUICtrlCreateLabel("Seed:", 216, 24, 46, 24) GUICtrlSetFont(-1, 12, 400, 0, "MS Sans Serif") $SeedInput = GUICtrlCreateInput("", 264, 24, 97, 21) GUICtrlSetLimit(-1, 10) GUICtrlSetTip(-1, "Leave blank for a random seed.") $MazeTempPic = GUICtrlCreateGraphic(5,72, 663, 651) GUICtrlSetBkColor(-1, 0x000000) $MazeShowPic = GUICtrlCreatePic("", 5, 72, 663, 651) ;this is where the maze will be shown GUISetState(@SW_SHOW) #EndRegion ### END Koda GUI section ### While 1 $nMsg = GUIGetMsg() Switch $nMsg Case $GUI_EVENT_CLOSE Exit Case $GenerateButton Generate(Int(GUICtrlRead($MazeXInput)), Int(GUICtrlRead($MazeYInput)), GUICtrlRead($SeedInput), Int(GUICtrlRead($SolveCheck))) EndSwitch WEnd Func Generate($iMazeX, $iMazeY, $sSeed, $iSolve) ProgressOn("Generating maze", "Generating maze. Please Wait", "", -1, -1 , 16) $iSeed = UseSeed($sSeed) If $sSeed = "" Then $sSeed = String($iSeed) ProgressSet(1, "1 Percent.") Local $sBaseName = 'MazesMaze [' & String($iMazeX) & ', ' & String($iMazeY) & '] (' & $sSeed & ')' ; Now saves mazes in a separate folder DirCreate(@ScriptDir&"Mazes") Local $aiSize[2] = [$iMazeX, $iMazeY] ;$aiSize[0] Equals Number of Rows in each colum and $aiSize[1] equals number of Colums Local $aCells = _;This is where the maze will be stored ; It will store witch walls are intact Generate_Maze($aiSize, $iSolve) ; 25.5% of progress or 51% if not being solved Draw_Maze_Image($aiSize, $aCells, $sBaseName, $iSolve) ; 24.5% of progress or 48% if not being so)ved ;Show image if maze should not be solved If $iSolve = 49 Then GUICtrlSetImage($MazeShowPic, @ScriptDir & "" & $sBaseName & ".bmp") If $iSolve <> 49 Then Local $aCurrentPath = Solve_Maze($aiSize, $aCells) ; 25.5% of progress Solve_Maze_ImgDraw($aiSize, $aCurrentPath, $sBaseName) ; 23.5% of progress GUICtrlSetImage($MazeShowPic, @ScriptDir & "" & $sBaseName & "_Solved.bmp") EndIf ProgressOff() EndFunc Func Generate_Maze(Const ByRef $aiSize, ByRef $iSolve) Local Const $iTotalCells = $aiSize[0] * $aiSize[1] Local $iMoveToCell ; What cell to move to Local $aCellstack[$iTotalCells][2];This stores with sequnce the cell got generated in. used for backtracing. First dimension is Row. Second is Colum Local $iCurrentCellStackNumber = 0 ; Current subscript number to write to in $aCellstack Local $aCurrentCellStack[2] ; USed as a temp storage of a bit of cellstack. First dimension is Row. Second is Colum Local $iUnvisitedCells = $iTotalCells ; Number of cell that are unvisited Local $sNeighbours = '' Local $sNeighbourOk Local $iRndDirection Local $aCurrentCellRowColum $iSolve -= 1 If $iSolve = 3 Then $iSolve = 25.5 ;; setup cell array. Local $aCells[$iTotalCells];This is where the maze will be stored ; It will store witch walls are intact Local $iCurrentCell = Random(0, $iTotalCells - 1, 1) ;; set random start point/cell ;Make all walls be intact by filling the cells array with 1111 array_filler($aCells, '1111') Local $aVisitedCells[$iTotalCells] array_filler($aVisitedCells, False) While 1 ;Mark as visited and add to the cell stack $aCurrentCellRowColum = AddToCellStack($iCurrentCell, $iCurrentCellStackNumber, $aCellstack, $aiSize) ;; $iCurrentCell not used in function. ;Check to see if it sould stop createing the maze If $iUnvisitedCells <> 0 Then ;Check to see if the current cell has any neighbours there are unvisited $sNeighbours = _Neighbours($aCurrentCellRowColum, $iCurrentCell, $aVisitedCells, $aiSize) If $sNeighbours <> "0000" Then ;Choose a random unvisited Neighbour Do $iRndDirection = Random(0, 3, 1) $sNeighbourOk = StringMid($sNeighbours, $iRndDirection + 1, 1) Until $sNeighbourOk = "1" Switch $iRndDirection ;Witch side to move to Case 0 ; Move Up $iMoveToCell = $iCurrentCell - $aiSize[1] Case 1 ; Move Right $iMoveToCell = $iCurrentCell + 1 Case 2 ; Move Down $iMoveToCell = $iCurrentCell + $aiSize[1] Case 3 ; Move Left $iMoveToCell = $iCurrentCell - 1 EndSwitch BustWall($iCurrentCell, $iMoveToCell, $iRndDirection, $aCells) $iCurrentCell = $iMoveToCell ;Make the current cell visited $aVisitedCells[$iCurrentCell] = True $iUnvisitedCells -= 1 Else $aCurrentCellStack[0] = $aCellstack[$iCurrentCellStackNumber - 2][0] ; Get row of last item in cellstack $aCurrentCellStack[1] = $aCellstack[$iCurrentCellStackNumber - 2][1] ; Get colum of last item in cellstack $iCurrentCell = _GetCellPos($aiSize, $aCurrentCellStack) ; Combine row and colum to get pos $iCurrentCellStackNumber -= 2 ; This will ensure that the used cell from the cellstack will be overwritten EndIf Else ExitLoop EndIf ;Update the progress ProgressSet(Int(Map($iUnvisitedCells, $iTotalCells, 0, 0, 25.5) + 1 + $iSolve), String(Int(Map($iUnvisitedCells, $iTotalCells, 0, 0, 25.5) + 1 + $iSolve))&" Percent.") WEnd ProgressSet(Int(25.5 + $iSolve), String(Int(25.5 + $iSolve))&" Percent.") ; Update progress Return $aCells EndFunc ;==>Generate_Maze Func Draw_Maze_Image(Const ByRef $aiSize, ByRef Const $aCells, ByRef Const $sFilename, ByRef $iSolve) Local Const $iTotalCells = $aiSize[0] * $aiSize[1] Local $aImageRowColum Local $tBMP = _BMPCreate($aiSize[1] * 9, $aiSize[0] * 9) ;Define the size of the maze (in bmp) If $iSolve = 25.5 Then $iSolve = 25.5 + 23.5 ;Draw the maze with no walls For $i = 0 To $iTotalCells - 1 $aImageRowColum = _GetCellPos($aiSize, $i) Draw3By3($tBMP, $aImageRowColum[0] * 9, $aImageRowColum[1] * 9) Draw3By3($tBMP, 6 + $aImageRowColum[0] * 9, $aImageRowColum[1] * 9) Draw3By3($tBMP, $aImageRowColum[0] * 9, 6 + $aImageRowColum[1] * 9) Draw3By3($tBMP, 6 + $aImageRowColum[0] * 9, 6 + $aImageRowColum[1] * 9) ProgressSet(Int(Map($i, 0, $iTotalCells-1, 0, 10) + 26.5 + $iSolve), String(Int(Map($i, 0, $iTotalCells-1, 0, 10) + 26.5 + $iSolve))&" Percent."); Update progress Next ;Then Draw the wall on the cells For $i = 0 To $iTotalCells - 1 $aImageRowColum = _GetCellPos($aiSize, $i) If StringMid($aCells[$i], 1, 1) = "1" Then Draw3By3($tBMP, 3 + $aImageRowColum[1] * 9, $aImageRowColum[0] * 9) EndIf If StringMid($aCells[$i], 2, 1) = "1" Then Draw3By3($tBMP, 6 + $aImageRowColum[1] * 9, 3 + $aImageRowColum[0] * 9) EndIf If StringMid($aCells[$i], 3, 1) = "1" Then Draw3By3($tBMP, 3 + $aImageRowColum[1] * 9, 6 + $aImageRowColum[0] * 9) EndIf If StringMid($aCells[$i], 4, 1) = "1" Then Draw3By3($tBMP, $aImageRowColum[1] * 9, 3 + $aImageRowColum[0] * 9) EndIf ProgressSet(Int(Map($i, 0, $iTotalCells-1, 0, 10) + 36.5 + $iSolve), String(Int(Map($i, 0, $iTotalCells-1, 0, 10) + 36.5 + $iSolve))&" Percent."); Update progress Next ;Draw start and exit. ;Start will be green and exit will be red Draw3By3($tBMP, 3, 3, '00FF00') ; Draw a green cube in the first cell(Top Left Corner) $aImageRowColum = _GetCellPos($aiSize, $iTotalCells - 1);Get row and colum of the last cell in the maze Draw3By3($tBMP, 3 + + $aImageRowColum[1] * 9, 3 + $aImageRowColum[0] * 9, 'FF0000') ; Draw a red cube in the last cell (Buttom right corner) ;And finaly save the bmp _BMPWrite($tBMP, @ScriptDir & "" & $sFilename & ".bmp") ProgressSet(Int(51 + $iSolve), String(Int(51 + $iSolve))&" Percent.") ; Update progress EndFunc ;==>Draw_Maze_Image Func Solve_Maze(Const ByRef $aiSize, ByRef $aCells) Local Const $iTotalCells = $aiSize[0] * $aiSize[1] Local $aCurrentPath[$iTotalCells+1000] ; Will store the current solved path Local $aSolveVisitedCells[$iTotalCells] ;This will store if the solver has been to a cell yet or not Local $iCurrentPathSubscriptNumber = -1 ; Current subscript number to write to in $aCurrentPath Local $iCurrentCell = 0 AddToCurrentPath($iCurrentCell, $iCurrentPathSubscriptNumber, $aCurrentPath) ; Add the cell the the path $aSolveVisitedCells[$iCurrentCell] = 1;Mark cell as visited ;Loop until the path has been found Local $CanGoOrNot Local $aYX[2] ; Store Y and X in an array ; used in solveing the maze While 1 ;Find a direction to go For $iDirection = 0 To 3 ;;If $iDirection = 4 Then ExitLoop $aYX = _GetCellPos($aiSize, $iCurrentCell); Convert it to rows and colums $CanGoOrNot = CanGo($aYX[0], $aYX[1], $iDirection, $aCells, $aSolveVisitedCells, $aiSize) ; Check if it can go there If $CanGoOrNot = 1 Then ExitLoop Next If $iDirection <> 4 Then Switch $iDirection Case 0 ; Up $iCurrentCell -= $aiSize[0] Case 1 ; Right $iCurrentCell += 1 Case 2 ; Down $iCurrentCell += $aiSize[0] Case 3 ; Left $iCurrentCell -= 1 EndSwitch AddToCurrentPath($iCurrentCell, $iCurrentPathSubscriptNumber, $aCurrentPath) ; Add the cell the the path $aSolveVisitedCells[$iCurrentCell] = True;Mark cell as visited Else If $iCurrentPathSubscriptNumber > 0 Then $iCurrentCell = $aCurrentPath[$iCurrentPathSubscriptNumber - 1] $iCurrentPathSubscriptNumber -= 1 ;Else ; $iCurrentPathSubscriptNumber -= 1 EndIf EndIf If $iCurrentCell = $iTotalCells - 1 Then ExitLoop WEnd ProgressSet(Int(76.5), "75 Percent"); Update progress Return $aCurrentPath EndFunc ;==>Solve_Maze Func Solve_Maze_ImgDraw(Const ByRef $aiSize, ByRef $aCurrentPath, Const ByRef $sFilename) Local Const $iTotalCells = $aiSize[0] * $aiSize[1] ;This function will use functions from the Drawing Functions region ;Open The Generated maze as a bmp handle Local $tBMP = _BMPOpen(@ScriptDir & "" & $sFilename & ".bmp") Local $aCurrentRowAndColum ;Go thoug all the cells one by one For $i = 0 To UBound($aCurrentPath) - 1 If $aCurrentPath[$i] = $iTotalCells - 1 Then ExitLoop If $aCurrentPath[$i] <> "" Then $aCurrentRowAndColum = _GetCellPos($aiSize, $aCurrentPath[$i]) Draw3By3($tBMP, 9 * $aCurrentRowAndColum[1] + 3, 9 * $aCurrentRowAndColum[0] + 3, 'FFFF00') If $aCurrentPath[$i] - $aiSize[0] = $aCurrentPath[$i + 1] Then ; Up Draw3By3($tBMP, 9 * $aCurrentRowAndColum[1] + 3, 9 * $aCurrentRowAndColum[0], 'FFFF00') Draw3By3($tBMP, 9 * $aCurrentRowAndColum[1] + 3, 9 * $aCurrentRowAndColum[0] - 3, 'FFFF00') ElseIf $aCurrentPath[$i] + 1 = $aCurrentPath[$i + 1] Then ;Right Draw3By3($tBMP, 9 * $aCurrentRowAndColum[1] + 6, 9 * $aCurrentRowAndColum[0] + 3, 'FFFF00') Draw3By3($tBMP, 9 * $aCurrentRowAndColum[1] + 9, 9 * $aCurrentRowAndColum[0] + 3, 'FFFF00') ElseIf $aCurrentPath[$i] + $aiSize[0] = $aCurrentPath[$i + 1] Then ; Down Draw3By3($tBMP, 9 * $aCurrentRowAndColum[1] + 3, 9 * $aCurrentRowAndColum[0] + 6, 'FFFF00') Draw3By3($tBMP, 9 * $aCurrentRowAndColum[1] + 3, 9 * $aCurrentRowAndColum[0] + 9, 'FFFF00') ElseIf $aCurrentPath[$i] - 1 = $aCurrentPath[$i + 1] Then ;LEft Draw3By3($tBMP, 9 * $aCurrentRowAndColum[1], 9 * $aCurrentRowAndColum[0] + 3, 'FFFF00') Draw3By3($tBMP, 9 * $aCurrentRowAndColum[1] - 3, 9 * $aCurrentRowAndColum[0] + 3, 'FFFF00') EndIf EndIf ProgressSet(Int(Map($i, 0, UBound($aCurrentPath) - 1, 0, 22.5) + 76.5), String(Int(Map($i, 0, UBound($aCurrentPath) - 1, 0, 22.5) + 76.5))&" Percent") ; Update progress Next ;reDraw start and exit. ;Start will be green and exit will be red Draw3By3($tBMP, 3, 3, '00FF00') ; Draw a green cube in the first cell(Top Left Corner) Local $aImageRowColum = _GetCellPos($aiSize, $iTotalCells - 1);Get row and colum of the last cell in the maze Draw3By3($tBMP, 3 + + $aImageRowColum[1] * 9, 3 + $aImageRowColum[0] * 9, 'FF0000') ; Draw a red cube in the last cell (Buttom right corner) ;And finaly save th bmp as Maze.bmp _BMPWrite($tBMP, @ScriptDir & "" & $sFilename & "_Solved.bmp") ProgressSet(100, "100 Percent") ; Update progress EndFunc ;==>Solve_Maze_ImgDraw #region Maze generation functions Func BustWall($Cell1, $Cell2, $iDirection, ByRef $aCells) ; This function will remove the walls in two adjacent cells. Direction is from first cell to second. Direction can be from 0 - 3. 0 = Up, 1 = Right, 2 = Down, 3 = Left $aCells[$Cell1] = StringReplace($aCells[$Cell1], $iDirection + 1, "0", 1, 2) ; Bust the wall between cell1 and cell2 in cell1 FlipDirection_br($iDirection) $aCells[$Cell2] = StringReplace($aCells[$Cell2], $iDirection + 1, "0", 1, 2) ; Bust the wall between cell1 and cell2 in cell2 EndFunc ;==>BustWall Func AddToCellStack($iCurrentCell, ByRef $iCurrentCellStackNumber, ByRef $aCellstack, Const ByRef $aiSize); This function will add the $Cell to the $aCellstack at the subscript of $CurretCellStackNumber ;Convert to Rows and colums Local $aCurrentCellRowColum = _GetCellPos($aiSize, $iCurrentCell) ;Add cell to the cell stack $aCellstack[$iCurrentCellStackNumber][0] = $aCurrentCellRowColum[0] $aCellstack[$iCurrentCellStackNumber][1] = $aCurrentCellRowColum[1] ;Add one to $iCurrentCellStackNumber $iCurrentCellStackNumber += 1 Return $aCurrentCellRowColum EndFunc ;==>AddToCellStack Func _Neighbours(Const ByRef $aCurrentCellRowColum, $Cell, ByRef Const $aVisitedCells, Const ByRef $aiSize) ; Check for Neighbours and store them in a string an 1 means that the neighbour has not been visited and an 0 means the neighbour has been visited it also checks for the edge of the maze. Local $NeighbourRowColum, $sNeighbours = '' Local Const $iTotalCells = $aiSize[0] * $aiSize[1] ;Check Clockwise ;Check Above cell If ($Cell - $aiSize[1] >= 0) And ($aVisitedCells[$Cell - $aiSize[1]] = False) Then $sNeighbours &= "1" Else $sNeighbours &= "0" EndIf ;Check Right Cell $NeighbourRowColum = _GetCellPos($aiSize, $Cell + 1) If ($aCurrentCellRowColum[0] >= $NeighbourRowColum[0]) And ($Cell + 1 < $iTotalCells) And ($aVisitedCells[$Cell + 1] = False) Then $sNeighbours &= "1" Else $sNeighbours &= "0" EndIf ;Check Buttom Cell If ($Cell + $aiSize[1] < $iTotalCells) And ($aVisitedCells[$Cell + $aiSize[1]] = False) Then $sNeighbours &= "1" Else $sNeighbours &= "0" EndIf ;Check Left Cell $NeighbourRowColum = _GetCellPos($aiSize, $Cell - 1) If ($aCurrentCellRowColum[0] <= $NeighbourRowColum[0]) And ($Cell - 1 >= 0) And ($aVisitedCells[$Cell - 1] = False) Then $sNeighbours &= "1" Else $sNeighbours &= "0" EndIf Return $sNeighbours EndFunc ;==>_Neighbours #endregion Maze generation functions #region Drawing Functions Func Draw3By3(ByRef $tBMP, $x, $y, $Colur = '000000') ; This function will draw a 3*3 Cube at a given x and y on the $tBMP _PixelWrite($tBMP, $x, $y, $Colur) _PixelWrite($tBMP, $x + 1, $y, $Colur) _PixelWrite($tBMP, $x + 2, $y, $Colur) _PixelWrite($tBMP, $x, $y + 1, $Colur) _PixelWrite($tBMP, $x + 1, $y + 1, $Colur) _PixelWrite($tBMP, $x + 2, $y + 1, $Colur) _PixelWrite($tBMP, $x, $y + 2, $Colur) _PixelWrite($tBMP, $x + 1, $y + 2, $Colur) _PixelWrite($tBMP, $x + 2, $y + 2, $Colur) EndFunc ;==>Draw3By3 #endregion Drawing Functions #region Maze solveing Functions Func CanGo($y, $x, ByRef Const $iDirection, ByRef Const $aCells, ByRef Const $aSolveVisitedCells, Const ByRef $aiSize);Returns 1 if the direction can the traveled and if not it will return 0. $Y = Row, $x = Colum, $iDirection = Direction Local $aYX[2] = [$y, $x] If StringMid($aCells[_GetCellPos($aiSize, $aYX)], $iDirection + 1, 1) = "0" Then Switch $iDirection Case 0 ; Up $aYX[0] -= 1 Case 1 ; Right $aYX[1] += 1 Case 2 ; Down $aYX[0] += 1 Case 3 ; Left $aYX[1] -= 1 EndSwitch If ($aSolveVisitedCells[_GetCellPos($aiSize, $aYX)] <> True) Then Return 1 ; IF cell has not been seen before by the solver EndIf Return 0 EndFunc ;==>CanGo Func AddToCurrentPath(ByRef Const $Cell, ByRef $iCurrentPathSubscriptNumber, ByRef $aCurrentPath) $iCurrentPathSubscriptNumber += 1 $aCurrentPath[$iCurrentPathSubscriptNumber] = $Cell EndFunc ;==>AddToCurrentPath #endregion Maze solveing Functions #region Seed Functions Func UseSeed($sRawSeed) Local Const $INT31u = Int('0x0080000000') ;; (2^31), int64. (2147483648) Local Const $INT32u = Int('0x0100000000') ;; (2^32), int64. (4294967296) If $sRawSeed = "" Then Return SetError(0, 1, RND_SeedTimed()) If StringLen($sRawSeed) > 10 Then Return SetError(1, 0, -1) $s = StringSplit($sRawSeed, "") $iSeed = 0 For $i = 1 To $s[0] $iSeed += (Asc($s[$i])*31^($s[0]-$i)) Next $iSeed = Int(Mod(Int($iSeed), $INT32u) - ($INT31u), 1) SRandom($iSeed) Return SetError(0, 0, $iSeed) EndFunc Func RND_SeedTimed($iSeed = Default) ;; Set seed base on current timer value. Returns used seed value. Local Const $INT31u = Int('0x0080000000') ;; (2^31), int64. (2147483648) Local Const $INT32u = Int('0x0100000000') ;; (2^32), int64. (4294967296) If Not IsNumber($iSeed) Then $iSeed = Int(Mod(Int(TimerInit()), $INT32u) - ($INT31u), 1) ;; wraps to [-2^31 and 2^31-1]. (has value shift) EndIf SRandom($iSeed) Return SetError(@error, @extended, $iSeed) EndFunc ;==>RND_SeedTimed #endregion Seed Functions #region Global Functions Func _GetCellPos(Const ByRef $aiSize, $vFind) ; This function will make a row and a colum into a Pos to be used with $aCells or $aCellstack, Or it will Make a Pos into an array with row and colum If IsArray($vFind) Then Local $CellPos = $vFind[0] * $aiSize[1] + $vFind[1] Return $CellPos Else Local $aCellRowColum[2] ; Will be used in the _GetCellPos function to temp.. store an array $aCellRowColum[0] = Int($vFind / $aiSize[1]) $aCellRowColum[1] = $vFind - ($aCellRowColum[0] * $aiSize[1]) Return $aCellRowColum EndIf EndFunc ;==>_GetCellPos Func FlipDirection_br(ByRef $iDirection) ; Flips the direction If $iDirection > 1 Then $iDirection -= 2 Else $iDirection += 2 EndIf EndFunc ;==>FlipDirection_br Func FlipDirection($iDirection) ; Flips the direction If $iDirection > 1 Then Return $iDirection - 2 Return $iDirection + 2 EndFunc ;==>FlipDirection Func array_filler(ByRef $aArray, $vFiller) ; Fills $aArray with $vFiller For $i = 0 To UBound($aArray) - 1 $aArray[$i] = $vFiller Next EndFunc ;==>array_filler Func Map($iValue, $iFromLow, $iFromHigh, $iToLow, $iToHigh) Return ($iValue - $iFromLow) * ($iToHigh - $iToLow) / ($iFromHigh - $iFromLow) + $iTolow EndFunc #endregion Global Functions Also be VERY carefull when generating very big mazes, my computer crashed when i was trying to generate a 500*500 maze. -FIXED Please post comments and/or any bug or problems. Sorry for any bad spelling that there may be.
×
×
  • Create New...