Search the Community

Showing results for tags 'math'.



More search options

  • Search By Tags

    Type tags separated by commas.
  • Search By Author

Content Type


Forums

  • General
    • Announcements and Site News
    • Chat
    • 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

Categories

  • Forum
  • AutoIt

Calendars

  • Community Calendar

Found 14 results

  1. RunningStats calculates running (moving) statistics: Standard Deviation, Variance, and Mean . The single function _RunningStats(), queries, clears, restores, or adds to the running statistics. Example.au3 adds 7 samples of data to running statistics and displays the results using _ArrayDisplay(). Example-Persistent-Storage.au3 adds the first 6 samples to the running statistics and stores the results in an INI file. The data is read from the INI file and restored to the running statistics. The 7th sample is added and the results displayed, matching the results from Example.au3. Credits: John D. Cook for his article "Accurately computing running variance" at http://www.johndcook.com/blog/standard_deviation/ RunningStats.zip
  2. I started writing this UDF a while ago, so I decided to share it here. This is an UDF full of advanced mathematical functions. It allows to work with primes, create number sequences, interpolate, calculate values of functions like Riemann zeta. Full list of functions: Changelog: Download
  3. Hey there I'm thinking about making a program that will calculate with huge numbers. Well above 1*10^18 probably. Can autoit deal with that? If not, how can I make it work? Thanks!
  4. I keep getting error : Statement cannot be just an expression. Here are the 3 error variations it gives: Global $ImageCount += 1 ~~~~~~~~~~~~~~~~~~~~~^ Global $ImageCount += 1 ~~~~~~~~~~~~~~~~~~~~^ Global $ImageCount += ~~~~~~~~~~~~~~~~~~~^ Here is the code: Case $Image1 ;GUICtrlSetState($Image1, 4+128) GUICtrlSetState($Image2, 64) $Image1_done = 1 OpenImages() Global $Image1_added = $imagePath ;MsgBox("Info", "Image 1 Path", $Image1_added) OpenEditBox() Global $Image1_Description = $editBox_save If $im1 = 0 Then Global $ImageCount += 1 $im1 = 1 EndIf Case $Image2 If $Image1_done = 1 Then ;GUICtrlSetState($Image2, 4+128) GUICtrlSetState($Image3, 64) OpenImages() Global $Image2_added = $imagePath ;MsgBox("Info", "Image 2 Path", $Image2_added) OpenEditBox() Global $Image2_Description = $editBox_save $Image2_done = 1 If $im2 = 0 Then Global $ImageCount += 1 $im2 = 1 EndIf Else EndIf Case $Image3 If $Image2_done = 1 Then ;GUICtrlSetState($Image3, 4+128) GUICtrlSetState($Image4, 64) OpenImages() Global $Image3_added = $imagePath ;MsgBox("Info", "Image 3 Path", $Image3_added) OpenEditBox() Global $Image3_Description = $editBox_save $Image3_done = 1 If $im3 = 0 Then Global $ImageCount += 1 $im3 = 1 EndIf Else EndIf Case $Image4 If $Image3_done = 1 Then ;GUICtrlSetState($Image4, 4+128) GUICtrlSetState($Image5, 64) OpenImages() Global $Image4_added = $imagePath ;MsgBox("Info", "Image 4 Path", $Image4_added) OpenEditBox() Global $Image4_Description = $editBox_save $Image4_done = 1 If $im4 = 0 Then Global $ImageCount += 1 $im4 = 1 EndIf Else EndIf Case $Image5 If $Image4_done = 1 Then ;GUICtrlSetState($Image5, 4+128) GUICtrlSetState($Image6, 64) OpenImages() Global $Image5_added = $imagePath ;MsgBox("Info", "Image 5 Path", $Image5_added) OpenEditBox() Global $Image5_Description = $editBox_save $Image5_done = 1 If $im5 = 0 Then Global $ImageCount += 1 $im5 = 1 EndIf Else EndIf Case $Image6 If $Image1_done = 1 Then ;GUICtrlSetState($Image6, 4+128) OpenImages() Global $Image6_added = $imagePath ;MsgBox("Info", "Image 6 Path", $Image6_added) OpenEditBox() Global $Image6_Description = $editBox_save If $im6 = 0 Then Global $ImageCount += 1 $im6 = 1 EndIf Else EndIf
  5. Hi, I've attached an example picture of a shape which i would like to calculate it's area. Let's say a user has marked this kind of shaped area on the screen and you need to run some calculations on it, like getting the area of it. - How would you go about this problem? Thanks in advance
  6. Hi, everybody! i'm trying to make a math worksheet generator for kids, but i need it in this format: and generate a PDF file with the math problems.... i know how to generate a problems, but idk how to 'format' this anyone have a ideia how to make this? Thanks a lot. p.s: Here is my sum generator code: Func _Sum_Generator($iMin, $iMax, $iProblems = 100, $iMaxAddends = 2, $bRandomAddends = True, $bUseDecimal = False, $bUseNegative = False) Local $aGenerated[$iProblems][2] If $iMaxAddends < 2 Then $iMaxAddends = 2 For $i = 0 To $iProblems -1 $aGenerated[$i][1] = 0 $iAddends = $iMaxAddends -1 If ($bRandomAddends And $iMaxAddends > 2) Then $iAddends = Random(2, $iMaxAddends, 1) -1 For $j = 0 To $iAddends Local $iOnlyInt = 1, $Negative = 0 If $bUseDecimal Then $iOnlyInt = Random(0,1,1) If $bUseNegative Then $Negative = Random(0,1,1) Local $iRandom = Round(Random($iMin, $iMax, $iOnlyInt), 2) If $Negative Then $iRandom *= -1 If $j = $iAddends Then $aGenerated[$i][0] &= String($iRandom) & " = " Else $aGenerated[$i][0] &= String($iRandom) & " + " EndIf $aGenerated[$i][1] += $iRandom Next Next Return $aGenerated EndFunc
  7. It's not because I am lazy, I believe many hands make light work and this is for PreExpand which will benefit the community anyway. Your input is greatly appreciated in creating a regular expression that can parse simple arithmetic expressions such as ((1 + -10) /809) or 1 + 9, though a different method can be considered if you don't like regexp. Speed isn't an issue, though something that takes 10 minutes to parse isn't ideal of course. Thanks. PS I guess this can be constituted as another game!
  8. For some obvious reason, Sucessfully to translate an #computing padding algorithm, and outputting same value with example of an explanation Lets take a breath, wiki say: The following formulas provide the number of padding bytes required to align the start of a data structure (where mod is the modulo operator): # pseudo-code, see actual code below padding = (align - (offset mod align)) mod align new offset = offset + padding = offset + (align - (offset mod align)) mod align For example, the padding to add to offset 0x59d for a structure aligned to every 4 bytes is 3. The structure will then start at 0x5a0, which is a multiple of 4. Note that when offset already is a multiple of align, the second modulo in (align - (offset mod align)) mod align is required to get a padding of 0. Then I write AutoIt3 script. ConsoleWrite(@CR & '+ Computing padding' & @CR) Local $align, $offset, $padding, $new_offset $align = 4 $offset = 0x59d $padding = Mod($align - Mod($offset, $align), $align) $new_offset = $offset + $padding + Mod($offset + ($align - Mod($offset, $align)), $align) ConsoleWrite('padding: ' & $padding & ' new offset: 0x' & StringLower(Hex($new_offset, 4)) & @CR) And the output is match with example in explanation. + Computing padding padding: 3 new offset: 0x05a0 The question #01 are is that are correct translation? changing second line on second (=) (see below) with plus sign (+) in AutoIt3 (see above) ? new offset = offset + padding = offset + (align - (offset mod align)) mod align . Again lets take a breath, wiki say: If the alignment is a power of two, the modulo operation can be reduced to a bitwise boolean AND operation. The following formulas provide the new offset (where & is a bitwise AND and ~ a bitwise NOT): padding = align - (offset & (align - 1)) = (-offset) & (align - 1) new offset = (offset + align - 1) & ~(align - 1) Then I write AutoIt3 script. ConsoleWrite(@CR & '+ align 2 - Power of Two' & @CR) Local $align, $offset, $padding, $new_offset $align = 2 $offset = 0x59d $padding = $align - (BitAND($offset, ($align - 1))) + BitAND((-$offset), ($align - 1)) $new_offset = BitAND(($offset + $align - 1), BitNOT($align - 1)) ConsoleWrite('padding: ' & $padding & ' new offset: 0x' & StringLower(Hex($new_offset, 4)) & @CR) And the output is. + align 2 - Power of Two padding: 2 new offset: 0x059e The question #02. First line and second (=) I replace with plus (+) sign, again is that correct? The question #03. What is meaning from the word of 'The Power of Two'? Are 2 is The Power of Two? Are 4, 8, 16 is The Power of Two? Which are the number are is The Power of Two and which is not? Can someone give me an confirmation if translation that pseudo-code to AutoIt3 are correct.? Can someone give me an explanation what is so called 'The Power of Two'.? Please answer even if you think this are childish question, because I'm not from Brittain nor from American.
  9. Just trying to wrap my head around some (very) basic math here by converting it into AU3 syntax, on this page (http://www.paulgraham.com/naivebayes.html) there is a good example of how to add two, or more, probabilities together. Here's the short version: Now, any takes on how I would implement that simple math in autoit code? For now I've got: $prbs = 0.60 + 0.72 $dividers = ((0.60+0.72))+((1-0.60)+(1-0.72)) $result = $prbs / $dividers ConsoleWrite('$result: ' & $result & @CRLF) And the output is "0.66" which certainly isn't right so I'm doing something wrong, any takers/helpers on this problem?
  10. 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 ;---------------------------------------------------- Articles and code samples i used: http://lodev.org/cgtutor/raycasting.html http://www.permadi.com/java/rayc/Rayc.java
  11. AutoMathEdit This is a very simple language written in AutoIt. AutoMathEdit only handles numeric operations and lacks the fexibility and functionality of other programming languages. it's still a language nonetheless! See this post: There are currently no keywords or loops, but the intended purpose of AutoMathEdit is to replace the calculator for quick tasks. The standard windows calculator does not keep tabs on every number you type. This is one advantage of using AutoMathEdit instead of using a standard calculator. This is the first scripting language I have ever written and it was certainly an education. I know I'm only scratching the surface with this, but everyone has to start soimewhere. I have gained much respect for the dev team after this endeavour. Dealing with so many complicated commands must be a nightmare. AutoMathEdit is meant to be used exclusivey within an Edit control. The function Echo behaves like the AutoIt function ConsoleWrite. This is an alpha release and there are still several bugs need ironing out. AutoMathEdit.au3 #include-once #include <Math.au3> #include <Array.au3> ; #INDEX# ======================================================================================================================= ; Title .........: AutoMathEdit Version 0.0.0.6 (Alpha) ; AutoIt Version : 3.3.8.1 ; Language ......: English ; Description ...: Simple (maths only) scripting language based on AutoIt ; Notes .........: AutoMathEdit makes use of AutoIt syntax and standard maths functions. ; The library is not yet complete and this release is for evaluation purposes. ;+ ; Supported AutoIt functions:- Abs ACos ASin ATan BitAND BitNOT BitOR BitRotate ; BitShift BitXOR Cos Ceiling Dec Exp Floor Hex Log Mod Random Round Sin Sqrt ;+ ; Supported UDF functions:- _ATan2 _Combinations _Degree Echo _Factorial _Max _Min ; _Radian _Permutations ;+ ; Supported variable types:- integers floats binary ;+ ; Supported operators:- + - * / ^ = += -= *= /= ;+ ; Constants:- ; $MATH_E .... (Napiers Constant) ; $MATH_PHI .. (Golden Ratio) ; $MATH_PI ... (Pi) ; $MATH_PSI .. (Reciprocal Fibonacci Constant) ;+ ; Supported syntax:- ; 1. End of line comments (semicolon) ; 2. Line continuation (underscore) ;+ ; General Comments: ; UDF functions are included automatically. ; All variables are declared automatically. ; The use of $ (dollar sign) for variable names is optional. ; The function Echo returns the value of an expression. ; Echo(expression) ;= value ;+ ; Thanks to the following devs and members who's examples have been a great inspiration: ; Jon, Manadar, Mat, Valik, trancexx, UEZ (list is not complete) ;+ ; Author(s) .....: Nick Wilkinson (czardas) ; =============================================================================================================================== ; #CURRENT# ===================================================================================================================== ;_Combinations ;_Execute ;_Factorial ;_Permutations ; =============================================================================================================================== ; #INTERNAL_USE_ONLY#============================================================================================================ ;__AssignSplit ;__ErrorMsg ;__GetBreakPoint ;__GetNewStr ;__GetSubArr ;__IsConst ;__IsFunc ;__IsReserved ;__Return ;__StripOutStrings ; =============================================================================================================================== ; #FUNCTION# ==================================================================================================================== ; Name...........: _Execute ; Description ...: Runs AutoMathEdit ; Syntax.........: _Execute($_sScript_) ; Parameters ....: $_sScript_ .... The string to parse. ; Return values .: Success ....... Parses AutoMathEdit and returns the new code string. ; Failure ....... Parses AutoMathEdit up to the fail point and sets @error ; |@error = 1 ... Illegal characters ; |@error = 2 ... Invalid Syntax ; |@error = 3 ... Function not recognised ; |@error = 4 ... Unexpected Termination ; |@error = 5 ... Unterminated String ; |@error = 6 ... Failed to reassign mathematical constant ; |@error = 7 ... Missing Parentheses ; |@error = 8 ... Unassigned Variable ; Author ........: czardas ; Modified.......: ; Remarks .......: _Execute also handles calls to the Echo() function which evaluates an expression. ; The value returned by the function Echo appears as a comment in the returned code. ; Related .......: None ; Link ..........: ; Example .......: Yes ; =============================================================================================================================== Func _Execute($_sScript_) If Not StringLen($_sScript_) Then Return SetError(4, 0, $_sScript_) Local Const $MATH_E = 2.71828182845904523536028747135266249 ; Napiers Constant Local Const $MATH_PHI = 1.61803398874989484820458683436563811772 ; Golden Ratio Local Const $MATH_PI = 3.14159265358979323846264338328 ; Pi Local Const $MATH_PSI = 3.359885666243177553172011302918927179688905133731 ; Reciprocal Fibonacci constant Local $_aRawData_ = StringSplit(StringStripCR($_sScript_), @LF) $_sScript_ = StringRegExpReplace($_sScript_, "(;.*)", "") ; Remove comments Local $_subStr_ ; Substitute string for $ and to avoid conflicts with reserved variables or constants __GetNewStr($_sScript_, $_subStr_) Local $_aTemp_, $_error_, $_sFail_ = "" ; To store the string which could not be parsed $_aTemp_ = __GetSubArr($_sScript_, $_subStr_, $_sFail_) ; Returns an array of substitute patterns $_error_ = @error Local $_aScriptArr_, $foo, $_sRawCode_ = $_sScript_ ; Keep original code intact $_sScript_ = StringReplace($_sScript_, "$MATH", ";") ; To avoid corrupting constant variable names $_sScript_ = StringReplace($_sScript_, "$", $_subStr_) ; To avoid conflicts with duplicate variable names $_sScript_ = StringReplace($_sScript_, ";", "$MATH") ; Replace the correct math constant names If $_error_ = 0 Then For $foo = 1 To $_aTemp_[0][0] $_sScript_ = StringRegExpReplace($_sScript_, "(?i)(b" & $_aTemp_[$foo][0] & "b)", $_aTemp_[$foo][1]) Next Else If StringLen($_sFail_) Then $_aScriptArr_ = StringSplit(StringStripCR($_sScript_), @LF) ; Split to lines of raw code For $foo = 0 To UBound($_aScriptArr_) -1 If StringInStr($_aScriptArr_[$foo], $_sFail_) Then $_sFail_ = "Line " & $foo & @LF & $_sFail_ ExitLoop EndIf Next MsgBox(16, "Error", __ErrorMsg($_error_) & @LF & $_sFail_) Return SetError($_error_, 0, __Return($_aRawData_)) ; Unable to parse - Errors vary EndIf EndIf Local $bar ; Variable integer $_aScriptArr_ = StringSplit(StringStripCR($_sScript_), @LF) ; Split to lines of raw code For $foo = 1 To $_aScriptArr_[0] $bar = $foo While StringRegExp($_aScriptArr_[$foo], "(s_s*z)") ; Check for line continuation underscore NOT CHECKED If $bar < $_aScriptArr_[0] Then If StringLen($_aScriptArr_[$bar +1]) Then $_aScriptArr_[$foo] = StringRegExpReplace($_aScriptArr_[$foo], "(s_s*z)", " " & $_aScriptArr_[$bar +1]) $_aScriptArr_[$bar +1] = "" $bar += 1 Else MsgBox(16, "Error", "Line " & $bar & @LF & __ErrorMsg(5) & @LF & $_aRawData_[$bar]) Return SetError(5, 0, __Return($_aRawData_)) ; Unterminated String EndIf ElseIf StringRegExp($_aScriptArr_[$foo], "(s_s*z)") Then MsgBox(16, "Error", "Line " & $_aScriptArr_[0] & @LF & __ErrorMsg(5)) Return SetError(5, 0, __Return($_aRawData_)) ; Unterminated String EndIf WEnd $foo = $bar Next For $foo = 1 To $_aScriptArr_[0] ; Parse each line sequence $_aScriptArr_[$foo] = StringStripWS($_aScriptArr_[$foo], 3) If Not StringLen($_aScriptArr_[$foo]) Then ContinueLoop If StringInStr($_aScriptArr_[$foo], "=") Then $_aAssign_ = __AssignSplit($_aScriptArr_[$foo]) $_error_ = @error If $_error_ = 0 Then If StringLeft($_aAssign_[1], 1) = "$" Then $_aAssign_[1] = StringTrimLeft($_aAssign_[1], 1) Else MsgBox(16, "Error", __ErrorMsg(2) & @LF & "Line " & $foo & @LF & $_aRawData_[$foo]) Return SetError(2, 0, __Return($_aRawData_)) EndIf If __IsConst($_aAssign_[1]) Then MsgBox(16, "Error", __ErrorMsg(6) & @LF & "Line " & $foo & @LF & "$" & $_aAssign_[1] & " =") Return SetError(6, 0, __Return($_aRawData_)) EndIf $_aAssign_[2] = Execute($_aAssign_[2]) $_error_ = @error If StringLen($_aAssign_[2]) = 0 Or ($_aAssign_[2] <> 0 And $_error_ <> 0 And Not IsNumber(Number($_aAssign_[2])) Or $_aAssign_[2] = False) Then MsgBox(16, "Error", __ErrorMsg(2) & @LF & "Line " & $foo & @LF & $_aAssign_[1] & " =") Return SetError(2, 0, __Return($_aRawData_)) EndIf If $_aAssign_[0] = 2 Then Assign($_aAssign_[1], $_aAssign_[2]) ElseIf IsDeclared($_aAssign_[1]) Then $_nValue_ = Execute("$" & $_aAssign_[1]) Switch $_aAssign_[0] Case "+" Assign($_aAssign_[1], $_nValue_ + $_aAssign_[2]) Case "-" Assign($_aAssign_[1], $_nValue_ - $_aAssign_[2]) Case "*" Assign($_aAssign_[1], $_nValue_ * $_aAssign_[2]) Case "/" Assign($_aAssign_[1], $_nValue_ / $_aAssign_[2]) EndSwitch Else MsgBox(16, "Error", __ErrorMsg(8) & @LF & "Line " & $foo & @LF & $_aRawData_[$foo]) Return SetError(8, 0, __Return($_aRawData_)) EndIf Else $bar = __GetBreakPoint($_sRawCode_, $foo, "=", 2) MsgBox(16, "Error", __ErrorMsg(2) & @LF & "Line " & $bar & @LF & "=") Return SetError(2, 0, __Return($_aRawData_)) EndIf ; Echo is an internal command which writes the value of an expression. ElseIf StringLeft($_aScriptArr_[$foo], 4) = "Echo" Then $_aScriptArr_[$foo] = StringStripWS(StringTrimLeft($_aScriptArr_[$foo], 4), 3) If StringLeft($_aScriptArr_[$foo], 1) <> "(" Then MsgBox(16, "Error", __ErrorMsg(7) & @LF & "Line " & $foo & @LF & $_aRawData_[$foo]) Return SetError(7, 0, __Return($_aRawData_)) ; Missing Parentheses EndIf $bar = __GetBreakPoint($_sRawCode_, $foo) If StringRight($_aScriptArr_[$foo], 1) <> ")" Then MsgBox(16, "Error", __ErrorMsg(7) & @LF & "Line " & $bar & @LF & $_aRawData_[$bar]) Return SetError(7, 0, __Return($_aRawData_)) ; Missing Parentheses EndIf $_aScriptArr_[$foo] = StringTrimLeft(StringTrimRight($_aScriptArr_[$foo], 1), 1) $_temp_ = Execute($_aScriptArr_[$foo]) $_error_ = @error If StringLen($_temp_) = 0 Or ($_temp_ <> 0 And $_error_ <> 0 And (Not IsNumber(Number($_temp_)) Or $_temp_ = False)) Then $_aTemp_ = StringRegExp($_aScriptArr_[$foo], "x24w+", 3) If Not @error Then For $bar = 0 To UBound($_aTemp_) -1 $_temp_ = StringTrimLeft($_aTemp_[$bar], 1) If Not IsDeclared($_temp_) Then $_subLen_ = StringLen($_subStr_) If StringLeft($_temp_, $_subLen_ +1) = "k" & $_subStr_ Then ; Or StringLeft($_temp_, $_subLen_ +1) = "n" & $_subStr_ ; may need to add this $_temp_ = StringTrimLeft($_temp_, $_subLen_ +1) ElseIf StringLeft($_temp_, $_subLen_) = $_subStr_ Then $_temp_ = StringTrimLeft($_temp_, $_subLen_) EndIf $bar = __GetBreakPoint($_sRawCode_, $foo, $_temp_) MsgBox(16, "Error", __ErrorMsg(8) & @LF & "Line " & $bar & @LF & $_aRawData_[$bar]) Return SetError(8, 0, __Return($_aRawData_)) EndIf Next EndIf MsgBox(16, "Error", __ErrorMsg(2) & @LF & "Line " & $foo & @LF & $_aRawData_[$foo]) Return SetError(2, 0, __Return($_aRawData_)) EndIf $_aRawData_[$bar] = StringStripWS(StringRegExpReplace($_aRawData_[$bar], "(;.*)", ""), 2) & " ;= " & $_temp_ Else ; No assignments or Echo function - just an expression. What's that all about? $_temp_ = Execute($_aScriptArr_[$foo]) $_error_ = @error If StringLen($_temp_) = 0 Or ($_temp_ <> 0 And $_error_ <> 0 And Not IsNumber(Number($_temp_)) Or $_temp_ = False) Then MsgBox(16, "Error", __ErrorMsg(2) & @LF & "Line " & $foo & @LF & $_aRawData_[$foo]) Return SetError(2, 0, __Return($_aRawData_)) EndIf EndIf Next Return __Return($_aRawData_) EndFunc ;==> _Execute ; #INTERNAL_USE_ONLY# =========================================================================================================== ; Name...........: __GetNewStr ; Description ...: Searches for a nonconflicting substitution string to replace the dollar sign. ; Syntax.........: __GetNewStr($sTestStr, ByRef $sNewString) ; Parameters ....: $sTestStr - AutoMathEdit ; : $sNewString - substitution string ; Return values .: [ByRef] $sNewString ; Author ........: czardas ; Modified.......: ; Remarks .......: Avoids conflicts by placing underscore in the second character position. ; Related .......: __GetSubArr ; Link ..........: ; Example .......: No ; =============================================================================================================================== Func __GetNewStr($sTestStr, ByRef $sNewString) ; Find a nonconflicting replacement for $ (dollar sign) Local $aChar[37] = ["_","0","1","2","3","4","5","6","7","8","9","a","b","c","d","e","f","g","h","i","j","k","l","m","n","o","p","q","r","s","t","u","v","w","x","y","z"] ; Move outside function If StringLen($sNewString) < 2 Then $sNewString = $aChar[Random(0, 36, 1)] & "_" If Not StringInStr($sTestStr, $sNewString) Then Return For $i = 0 To 36 If Not StringInStr($sTestStr, $sNewString & $aChar[$i]) Then $sNewString &= $aChar[$i] Return EndIf Next $sNewString &= $aChar[Random(0, 36, 1)] __GetNewStr($sTestStr, $sNewString) EndFunc ;==> __GetNewStr ; #INTERNAL_USE_ONLY# =========================================================================================================== ; Name...........: __GetSubArr ; Description ...: Searches for a nonconflicting substitution string to replace the dollar sign. ; Syntax.........: __GetNewStr($sTestStr, ByRef $sNewString) ; Parameters ....: $sTestStr - AutoMathEdit ; : $subStr - substitution string ; : $sFail - Unexpected string which caused the function to fail ; ; Return values .: Success - An array of variable name substitutions ; Failure - Sets @error and returns [ByRef] $sFail ; Author ........: czardas ; Modified.......: ; Remarks .......: ; Related .......: __GetNewStr ; Link ..........: ; Example .......: No ; =============================================================================================================================== Func __GetSubArr($sTestStr, $subStr, ByRef $sFail) __StripOutStrings($sTestStr) ; Remove quotes Local $aRegExp = StringRegExp($sTestStr, "[^,w=-^*+()x24s.x22'/]", 3) If Not @error Then ; Encountered an illegal character $sFail = $aRegExp[0] Return SetError(1) ; Illegal character EndIf $aRegExp = StringRegExp($sTestStr, "([w|x24]x24)|(x24[^w])", 3) If Not @error Then ; Dollar is in the wrong place $sFail = $aRegExp[0] Return SetError(2) ; Invalid Syntax EndIf $aRegExp = StringRegExp($sTestStr, "($?w+s*(?)", 3) ; Gets functions and variables If IsArray($aRegExp) Then For $i = 0 To UBound($aRegExp) -1 $aRegExp[$i] = StringLower(StringStripWS($aRegExp[$i], 3)) ; Account for case insensitivity Next $aRegExp = _ArrayUnique($aRegExp) ; Get rid of duplicated substitution strings Local $aSubArr[UBound($aRegExp) +1][2] $aSubArr[0][0] = 0 For $i = 0 To UBound($aRegExp) -1 $aRegExp[$i] = StringStripWS($aRegExp[$i], 2) Select Case StringRight($aRegExp[$i], 1) = "(" If StringLeft($aRegExp[$i], 1) = "$" Then ; Functions do not begin with $ $sFail = $aRegExp[$i] Return SetError(2) ; Invalid Syntax ElseIf Not (__IsFunc(StringRegExpReplace($aRegExp[$i], "s*(", "")) Or StringStripWS($aRegExp[$i], 8) = "_(") Then $sFail = $aRegExp[$i] Return SetError(3) ; Function not recognised EndIf Case StringLeft($aRegExp[$i], 1) = "$" If __IsReserved(StringTrimLeft($aRegExp[$i], 1)) Then $aSubArr[0][0] += 1 $aSubArr[$aSubArr[0][0] ][0] = $aRegExp[$i] $aSubArr[$aSubArr[0][0] ][1] = StringReplace($aRegExp[$i], "$", "$r" & $subStr) ElseIf Not __IsConst(StringTrimLeft($aRegExp[$i], 1)) Then $aSubArr[0][0] += 1 $aSubArr[$aSubArr[0][0] ][0] = $aRegExp[$i] $aSubArr[$aSubArr[0][0] ][1] = StringReplace($aRegExp[$i], "$", "$o" & $subStr) EndIf Case StringLeft($aRegExp[$i], 2) = "0x" If Not StringIsXDigit(StringTrimLeft($aRegExp[$i], 2)) Then $aSubArr[0][0] += 1 $aSubArr[$aSubArr[0][0] ][0] = $aRegExp[$i] $aSubArr[$aSubArr[0][0] ][1] = "$x" & $subStr & $aRegExp[$i] EndIf Case Not (StringIsInt($aRegExp[$i]) Or StringIsFloat($aRegExp[$i]) Or __IsFunc($aRegExp[$i])) If __IsReserved($aRegExp[$i]) Then $aSubArr[0][0] += 1 $aSubArr[$aSubArr[0][0] ][0] = $aRegExp[$i] $aSubArr[$aSubArr[0][0] ][1] = "$r" & $subStr & $aRegExp[$i] ElseIf __IsConst($aRegExp[$i]) Then $aSubArr[0][0] += 1 $aSubArr[$aSubArr[0][0] ][0] = $aRegExp[$i] $aSubArr[$aSubArr[0][0] ][1] = "$k" & $subStr & $aRegExp[$i] ElseIf StringIsDigit(StringLeft($aRegExp[$i], 1)) Then $aSubArr[0][0] += 1 $aSubArr[$aSubArr[0][0] ][0] = $aRegExp[$i] $aSubArr[$aSubArr[0][0] ][1] = "$d" & $subStr & $aRegExp[$i] ElseIf $aRegExp[$i] <> "_" Then $aSubArr[0][0] += 1 $aSubArr[$aSubArr[0][0] ][0] = $aRegExp[$i] $aSubArr[$aSubArr[0][0] ][1] = "$w" & $subStr & $aRegExp[$i] EndIf EndSelect Next ReDim $aSubArr[$aSubArr[0][0] +1][2] For $i = 0 To $aSubArr[0][0] $aSubArr[$i][0] = StringReplace($aSubArr[$i][0], "$", $subStr) Next Return $aSubArr ; No errors have occured. Else Return SetError(4) ; Unexpected Termination EndIf EndFunc ;==> __GetSubArr ; #INTERNAL_USE_ONLY# =========================================================================================================== ; Name...........: __StripOutStrings ; Description ...: Removes all strings wrapped in quotes from the code. ; Syntax.........: __StripOutStrings(ByRef $sCodeStr) ; Parameters ....: $sCodeStr - The string to alter. ; Return values .: [ByRef] the string after removing all strings wrapped in quotes ; Author ........: czardas ; Modified.......: ; Remarks .......: ; Related .......: None ; Link ..........: ; Example .......: No ; =============================================================================================================================== Func __StripOutStrings(ByRef $sCodeStr) Local $foo, $bar, $iStart, $iEnd, $aQuot While 1 $foo = StringInStr($sCodeStr, '"') ; Double quote $bar = StringInStr($sCodeStr, "'") ; Single quote If $foo = 0 And $bar = 0 Then ExitLoop If $foo > $bar And $bar > 0 Then $iStart = $bar $sQuot = "'" Else $iStart = $foo $sQuot = '"' EndIf $iEnd = StringInStr($sCodeStr, $sQuot, 0, 2) If $iEnd = 0 Then ; Error Code??? $sCodeStr = StringLeft($sCodeStr, $iStart -1) Else $sCodeStr = StringLeft($sCodeStr, $iStart -1) & " " & StringRight($sCodeStr, StringLen($sCodeStr) - $iEnd) EndIf WEnd EndFunc ;==> __StripOutStrings ; #INTERNAL_USE_ONLY# =========================================================================================================== ; Name...........: __IsConst ; Description ...: Checks to see if the string is the name of a constant. ; Syntax.........: __IsFunc($sTestStr) ; Parameters ....: $sTestStr - Variable name to test ; Return values .: Returns True or False ; Author ........: czardas ; Modified.......: ; Remarks .......: ; Related .......: __IsFunc , __IsReserved ; Link ..........: ; Example .......: No ; =============================================================================================================================== Func __IsConst($sTestStr) $sTestStr = "|" & $sTestStr & "|" If StringInStr("|MATH_E|MATH_PHI|MATH_PI|MATH_PSI|", $sTestStr) Then Return True Else Return False EndIf EndFunc ;==> __IsConst ; #INTERNAL_USE_ONLY# =========================================================================================================== ; Name...........: __IsFunc ; Description ...: Checks to see if the string is the name of a function. ; Syntax.........: __IsFunc($sTestStr) ; Parameters ....: $sTestStr - Name to test ; Return values .: Returns True or False ; Author ........: czardas ; Modified.......: ; Remarks .......: Only recognises AutoMathEdit functions ; Related .......: __IsConst , __IsReserved ; Link ..........: ; Example .......: No ; =============================================================================================================================== Func __IsFunc($sTestStr) $sTestStr = "|" & $sTestStr & "|" If StringInStr("|_ATan2|_Combinations|_Degree|_Factorial|_Max|_Min|_Permutations|_Radian|Abs|ACos|ASin|ATan|BitAND|BitNOT|BitOR|BitRotate|BitShift|BitXOR|Ceiling|Cos|Dec|Echo|Exp|Floor|Hex|Log|Mod|Random|Round|Sin|Sqrt|Tan|", $sTestStr) Then Return True Else Return False EndIf EndFunc ;==> __IsFunc ; #INTERNAL_USE_ONLY# =========================================================================================================== ; Name...........: __IsReserved ; Description ...: Checks to see if the variable name is already being used. ; Syntax.........: __IsReserved($sTestStr) ; Parameters ....: $sTestStr - Variable name to test ; Return values .: Returns True or False ; Author ........: czardas ; Modified.......: ; Remarks .......: ; Related .......: __IsConst , __IsFunc ; Link ..........: ; Example .......: No ; =============================================================================================================================== Func __IsReserved($sTestStr) $sTestStr = "|" & $sTestStr & "|" If StringInStr("|_subStr_|_in|no_|_error_|_sFail_|_sRawCode_|_aAssign_|_nValue_|_sScript_|_temp_|_aTemp_|_subLen_|_aScriptArr_|_aRawData_|", $sTestStr) Then Return True Else Return False EndIf EndFunc ;==> __IsReserved ; #INTERNAL_USE_ONLY# =========================================================================================================== ; Name...........: __AssignSplit ; Description ...: Splits an assignment command to var = expression ; Syntax.........: __AssignSplit($sAssignStr) ; Parameters ....: $sAssignStr - Line of code containing an assignment operator ; Return values .: An array where:- ; | element 0 = type of assignment = += -= *= /= ; | element 1 = variable name ; | element 2 = expression ; Author ........: czardas ; Modified.......: ; Remarks .......: ; Related .......: None ; Link ..........: ; Example .......: No ; =============================================================================================================================== Func __AssignSplit($sAssignStr) Local $aAssignArr = StringSplit($sAssignStr, "=") ; Split string => variable equals expression If $aAssignArr[0] > 2 Then Return SetError(2, 0, 0) ; Only one assignment allowed per line Switch StringRight($aAssignArr[1], 1) Case "+","-","*","/" ; Get type of assignment $aAssignArr[0] = StringRight($aAssignArr[1], 1) ; += or -= or *= or /= $aAssignArr[1] = StringTrimRight($aAssignArr[1], 1) Case Else If StringRegExp($aAssignArr[1], "([+-*/][s]+z)") Then Return SetError(2) EndSwitch $aAssignArr[1] = StringStripWS($aAssignArr[1], 3) Return $aAssignArr EndFunc ;==> __AssignSplit ; #INTERNAL_USE_ONLY# =========================================================================================================== ; Name...........: __GetBreakPoint ; Description ...: Determines the exact line where a break in operations occurs - an error or a closing bracket for Echo ; Syntax.........: __GetBreakPoint($scriptStr, $iPosition [, $sErrorStr = False [, $iOccurence = 1 ]] ) ; Parameters ....: $scriptStr - AutoMathEdit ; : $iPosition - Line to start the search ; : $sErrorStr - Unexpected string which caused the function to fail ; : $iOccurence - The occurence of the error string to find. ; Return values .: The line number from the original script where the break in operations occured. ; Author ........: czardas ; Modified.......: ; Remarks .......: ; Related .......: None ; Link ..........: ; Example .......: No ; =============================================================================================================================== Func __GetBreakPoint($scriptStr, $iPosition, $sErrorStr = False, $iOccurence = 1) Local $aScriptArr = StringSplit(StringStripCR($scriptStr), @LF), $iCount = 0 Switch $sErrorStr Case "=" For $i = $iPosition To $aScriptArr[0] If StringRegExp($aScriptArr[$i], "(s_s*z)") Then While StringInStr($aScriptArr[$i], $sErrorStr, 0, 1) $aScriptArr[$i] = StringReplace($aScriptArr[$i], $sErrorStr, "", 1) $iCount += 1 If $iCount = $iOccurence Then Return $i WEnd Else Return $i EndIf Next Case False While StringRegExp($aScriptArr[$iPosition], "(s_s*z)") $iPosition += 1 If $iPosition > $aScriptArr[0] Or $aScriptArr[$iPosition -1] = "" Then Return SetError (5, 0, $iPosition) ; Unterminated string WEnd Return $iPosition Case Else For $iPosition = $iPosition To $aScriptArr[0] If StringRegExp($aScriptArr[$iPosition], "(x24" & $sErrorStr &"[^w])") Or StringRegExp($aScriptArr[$iPosition], "([^w]" & $sErrorStr &"[^w])") Then Return $iPosition Next EndSwitch EndFunc ;==> __GetBreakPoint ; #INTERNAL_USE_ONLY# =========================================================================================================== ; Name...........: __ErrorMsg ; Description ...: Returns the details of an error encountered while parsing the script. ; Syntax.........: __ErrorMsg($vError) ; Parameters ....: $vError - Error code 1 - 8 ; Return values .: $vError - Details of the type of error encountered. ; Author ........: czardas ; Modified.......: ; Remarks .......: ; Related .......: None ; Link ..........: ; Example .......: No ; =============================================================================================================================== Func __ErrorMsg($vError) Switch $vError Case 1 $vError = "Illegal characters" Case 2 $vError = "Invalid Syntax" Case 3 $vError = "Function not recognised" Case 4 $vError = "Unexpected Termination" Case 5 $vError = "Unterminated String" Case 6 $vError = "Failed to reassign mathematical constant" Case 7 $vError = "Missing Parentheses" Case 8 $vError = "Unassigned Variable" EndSwitch Return $vError EndFunc ;==> __ErrorMsg ; #INTERNAL_USE_ONLY# =========================================================================================================== ; Name...........: __Return ; Description ...: Same as _ArrayToString, but with parameters already set ; Syntax.........: __Return($aRawData) ; Parameters ....: $aRawData - an array with the original script plus added comments. ; Return values .: Original script plus comments. ; Author ........: czardas ; Modified.......: ; Remarks .......: This function only exists to simplify reading the code for _Execute. ; Related .......: None ; Link ..........: ; Example .......: No ; =============================================================================================================================== Func __Return($aRawData) Return _ArrayToString($aRawData, @CRLF, 1) EndFunc ;==> __Return ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;; #region ;... External library not yet complete Func _Permutations($n, $k) If Not IsInt($n) Or Not IsInt($k) Then Return SetError(1) If $k > $n Then Return 0 Return _Factorial($n)/(_Factorial($n -$k)) EndFunc ;==> _Permutations Func _Combinations($n, $k) If Not IsInt($n) Or $n < 1 Or Not IsInt($k) Or $k < 1 Then Return SetError(1) If $k > $n Then Return 0 Return _Factorial($n)/(_Factorial($k)*_Factorial($n -$k)) EndFunc ;==> _Combinations Func _Factorial($n) ; From UEZ If Not IsInt($n) Or $n < 1 Then Return SetError(1) Local $iRet = 1 For $i = 1 to $n $iRet *= $i Next Return $iRet EndFunc #endregion Test Edit Control #include <WindowsConstants.au3> #include <GUIConstantsEx.au3> #include <GuiEdit.au3> #include <WinAPI.au3> #include <AutoMathEdit.au3> _MathEditorTest() Func _MathEditorTest() Local $hGUI = GUICreate("AutoMathScript Edit Control Test", 600, 400, Default, Default, BitOR($WS_OVERLAPPEDWINDOW, $WS_EX_COMPOSITED)) Local $hFileMenu = GUICtrlCreateMenu("File") Local $hExit = GUICtrlCreateMenuItem("Exit", $hFileMenu), _ $hTools = GUICtrlCreateMenu("Tools") Local $hExecute = GUICtrlCreateMenuItem("Execute" & @TAB & "F5", $hTools), _ $iyOffset = _WinAPI_GetSystemMetrics(55) ; SM_CYMENUSIZE Local $hEdit1 = GUICtrlCreateEdit("", 0, 0, 600, 400 - $iyOffset, BitOr($GUI_SS_DEFAULT_EDIT, $ES_NOHIDESEL)), _ $hF5 = GUICtrlCreateDummy(), _ $hTab = GUICtrlCreateDummy(), _ $hSelectAll = GUICtrlCreateDummy(), _ $AccelKeys[3][2] = [[ @TAB, $hTab],["^a", $hSelectAll],["{F5}", $hF5]] GUICtrlSetFont($hEdit1, 12, 400, 1, "Lucida Console") GUISetAccelerators($AccelKeys) GUISetState() While 1 $msg = GUIGetMsg() Switch $msg Case $GUI_EVENT_CLOSE, $hExit ExitLoop Case $hExecute, $hF5 $sRet = _Execute(_GetSelectedText($hEdit1)) _GUICtrlEdit_ReplaceSel($hEdit1, $sRet) Case $hTab _TAB($hEdit1) Case $hSelectAll _SelectAll($hEdit1) EndSwitch WEnd EndFunc ;==> _MathEditorTest Func _GetSelectedText($hEdit) Local $aPos = _GUICtrlEdit_GetSel($hEdit) If $aPos[0] = $aPos[1] Then Return SetError(1, 0, "") ; Nothing selected $sRet = StringMid(_GUICtrlEdit_GetText($hEdit), $aPos[0] +1, $aPos[1] - $aPos[0]) Return $sRet EndFunc ;==> _GetSelectedText Func _TAB($hEdit) Local $sSelText = _GetSelectedText($hEdit) If Not @error Then Local $aLines = StringSplit($sSelText, @CRLF, 1) If $aLines[0] > 1 Then For $i = 1 To $aLines[0] $aLines[$i] = @TAB & $aLines[$i] Next _GUICtrlEdit_ReplaceSel($hEdit, _ArrayToString($aLines, @CRLF, 1)) Return EndIf EndIf _GUICtrlEdit_ReplaceSel($hEdit, @TAB) EndFunc ;==> _TAB Func _SelectAll($hEdit) _GUICtrlEdit_SetSel($hEdit, 0, -1) EndFunc ;==> _SelectAll See next post for features, history and AutoMathEdit examples.
  12. Hi there! I have been learning linear algebra in my university for months. The subject was rather hard, I did't understand it much so I sent a email to my teacher to ask him. But I realized that typing a matrix by text was extremely hard. I don't want to make a LaTex function, save to a file, attach it to the mail, bla bla bla!!! It's complicated! So I spent 2 hours yesterday to make this tool. Just type the number of lines and columns and matrix values, it will generate a quite nice matrix in ASCII characters Enjoy! Notes: It will rearrage your numbers to straight columns. 1x1 will cause error. ConsoleWrite (@CRLF & '------------------------------------MATRIX TEST-----------------------------------------' &@CRLF) Dim $c = 6;column Dim $l = 4;line Dim $n = '1,6,2,4,b,a,7,6,6,0,44,4,6,3,6,2,6,8,9,6,6,1,2,logmein' $split = StringSplit ($n,',') If $c * $l <> $split[0] Then ConsoleWrite ('! Matrix values number do not match the columns and lines !' & @CRLF) Exit EndIf Dim $char[$l][$c], $len[$l][$c], $maxlen[$c][3] For $i = 0 To $l-1 For $u = 0 To $c -1 $v = $i*($c) + $u +1 $char[$i][$u] = $split[$v] $len[$i][$u] = StringLen ($split[$v]) If $len[$i][$u] > $maxlen[$u][0] Then $maxlen[$u][0] = $len[$i][$u] $maxlen[$u][1] = $i $maxlen[$u][2] = $u EndIf Next Next Local $finallen For $u = 0 To $c - 1 $finallen += $maxlen[$u][0] Next ConsoleWrite (' _' & _Repeat(' ',$finallen + $c) & '_' & @CRLF) For $i = 0 To $l-1;write lines For $u = 0 To $c-1;write columns $v = $i*($c) + $u +1 $char[$i][$u] = $split[$v] Switch $u Case 0; the first column If StringLen ($char[$i][$u])<$maxlen[$u][0] Then ConsoleWrite ('| ' & $char[$i][$u] & _Repeat(' ', $maxlen[$u][0]-StringLen ($char[$i][$u])+1)) Else ConsoleWrite ('| ' & $char[$i][$u] & ' ') EndIf Case 1 To $c-2 ;middle columns If $i > 0 Then If StringLen ($char[$i][$u]) < $maxlen[$u][0] Then ConsoleWrite ($char[$i][$u] & _Repeat(' ', $maxlen[$u][0]-StringLen ($char[$i][$u])+1)) Else ConsoleWrite ($char[$i][$u] & ' ' ) EndIf Else If StringLen ($char[$i][$u]) < $maxlen[$u][0] Then ConsoleWrite ($char[$i][$u] & _Repeat(' ', $maxlen[$u][0]-StringLen ($char[$i][$u])+1)) Else ConsoleWrite ($char[$i][$u] & ' ' ) EndIf EndIf Case Else ; the last column If StringLen ($char[$i][$u])<$maxlen[$u][0] Then ConsoleWrite ($char[$i][$u] & _Repeat(' ', $maxlen[$u][0]-StringLen ($char[$i][$u])+1) & ' |' & @CRLF) Else ConsoleWrite ($char[$i][$u] & ' |' & @CRLF) EndIf EndSwitch Next Next ConsoleWrite ('|_' & _Repeat(' ',$finallen + $c ) & '_|' & @CRLF) Func _Repeat($chars, $times);repeat a character in a specified time Local $rChar For $a = 1 To $times $rChar &= $chars Next Return $rChar EndFunc ;==>_Repeat
  13. Hi guys, i have a math question: $Widht = 70 $Height = 30 $GUI = GUICreate("Test", $Widht, $Height, 10, 10) $Label = GUICtrlCreateLabel("00:00", -1, -1, $Widht, $Height) GUICtrlSetFont($LabelClock, 20, 600) With font size 20 and the label/gui 70 * 30 it fit perfect, but if i want to make the font size bigger i need to change everytime the GUI size and the label size. How i can make the GUI/Label variable connected to the size of the font? Example i know Font size = 40 $Widht = 70*2 $Height = 30*2 But if i make the size 17 or 54? Hope is clear what is my goal. Thanks
  14. How to convert string that retrieved from inputbox into math equation. for example, if the user type a math equation like : 2x^2+3x-4 how to convert it into math equation so we can process the result?