Jump to content

Recommended Posts

Hi!

I'm trying to script an ellipse drawing algorithm in AutoIT for learning purposes.
I use an edit control to "draw" the ellipse with characters.

The code i have works kinda good but i would like to see if others around here know a better algorithm to do it..
I would like to be able to give the x, y and width, height arguments to the function and not have to start at the middle point and draw the ellipse around it.

side note, the ellipse glitches when it has to be 2 pixels high too..

 

func ellipsePlotPoints ($xc,$yc, $x,$y)

    pixel ($xc + $x, $yc + $y)
    pixel ($xc - $x, $yc + $y)
    pixel ($xc + $x, $yc - $y)
    pixel ($xc - $x, $yc - $y)

endfunc

func ellipse($xc,$yc, $a,$b)

    local $a2 = $a * $a
    local $b2 = $b * $b
    local $twoa2 = 2 * $a2
    local $twob2 = 2 * $b2
    local $p
    local $x = 0
    local $y = $b
    local $px = 0
    local $py = $twoa2 * $y

    ; Plot the initial point in each quadrant.
    ellipsePlotPoints ($xc,$yc, $x,$y)

    ; Region 1
    $p = int($b2 - ($a2 * $b) + (0.25 * $a2))
    while ($px < $py)
        $x+=1
        $px += $twob2
        if ($p < 0) then
            $p += $b2 + $px
        else
            $y-=1
            $py -= $twoa2
            $p += $b2 + $px - $py
        endif
        ellipsePlotPoints ($xc,$yc, $x,$y)
    wend

    ; Region 2
    $p = int ($b2 * ($x+0.5) * ($x+0.5) + $a2 * ($y-1) * ($y-1) - $a2 * $b2)
    while ($y > 0)
        $y-=1
        $py -= $twoa2
        if ($p > 0) then
            $p += $a2 - $py
        else
            $x+=1
            $px += $twob2
            $p += $a2 - $py + $px
        endif
        ellipsePlotPoints ($xc,$yc, $x,$y)
    wend

endfunc

 

Link to post
Share on other sites

here (https://www.autoitscript.com/forum/topic/181014-a-naive-question/?do=findComment&comment=1299979) you can find a simple implementation of the Bresenham's Algorithm, translated in AutoIt, to plot lines, circles, ellipses and Bézier curves plotted pixel by pixel (or character by character on a text box as well if you prefer)

 

Edited by Chimp

 

image.jpeg.9f1a974c98e9f77d824b358729b089b0.jpeg Chimp

small minds discuss people average minds discuss events great minds discuss ideas.... and use AutoIt....

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
  • Recently Browsing   0 members

    No registered users viewing this page.

  • Similar Content

    • By kellariluukku
      Hey.
      Is there anything that does the same thing as this?
       
      Namely I'm talking about detecting when something has changed on screen.
      The FastFind library is crashing without any errors after running:
      FFSnapShot($left, $top, $right, $bottom, 0) FFSnapShot($left, $top, $right, $bottom, 1) $diff = FFLocalizeChanges(0, 1) And then trying to overwritite the old snapshot (0 or 1).
      If I use always different snapshot numbers its using too much memory and will eventually crash my pc.
      I tried downloading older versions but they're not working and the author is inactive.
       
      It takes 2 snapshots and compares them returning the area that has changed very quickly (left, top, right ,bottom).
      Can anyone help me do this?
      Looping PixelGetColor would require a bunch of extra code to my purpose and its not as efficient...
       
      Thanks
       
       
    • By Colduction
      Hello again to all, I've searched many times in forum and help file to find AES-256-GCM Algorithm for Crypt\Decrypt strings and files but i did not find anything about GCM Algorithm.

      Do you have any idea for solving this issue?
    • By v120
      Original posted by CoePSX
       
       
       
       
      Drawing_Script.au3
    • By dejhost
      Happy New Year everyone!
      I would like to extract the color values of certain pixels in an image.  This is how I picture the workflow: 
      User opens an image of his choice. Image is shown on the screen. User draws a line into the image. This happens by marking the startpixel and the endpixel of the line The line is drawn, so the user can check visually if he is happy with the line.  The following pixel based properties belonging to the line are stored in Excel: X-Coordinate Y-Coordinate Color Value Additional operations: Extracting for max- and min. color values; Statistical operations.   Browsing through the helpfile of AutoIt I find plenty of functions for treating images (e.g. GDIPlus), but I am completely unsure if Autoit will get me there. Should I read the entire image into an array? Should I rather attempt to script an external image software (e.g. IrfanView, Gimp)?
      I would be very thankful if someone could give some recommendations and maybe list a couple of the most important commands to use.
      Thank you very much.
      Dejhost
       
       
    • By badcoder123
      Hey, All!
       
      I was looking into the help file at all the drawing utilities and I was wondering if you draw a translucent line that follows your cursor. Upon looking for ideas I came across this thread (1.0) and saw UEZ's response. I also came across another post that UEZ replied to and found this reply (1.1) where he shows how you can draw on the desktop. This is what I'm looking for however I'd still like to be able to interact with a designated application and have the line/curve/vector passively follow it. Obviously we don't move our cursor very linearly so it would have to be able to draw on vectors. Am I over complicating this? 
      Any ideas or starting points I should look more into? 
       
       
       
      1.0
      #include <GUIConstantsEx.au3> #include <WindowsConstants.au3> Global Const $aFullScreen = WinGetPos(WinGetHandle("[TITLE:Program Manager;CLASS:Progman]")) Global $iHeight = 4 Global Const $hGUI = GUICreate("Screen Ruler Underline for free :-)", $aFullScreen[2], $iHeight, $aFullScreen[0], MouseGetPos(1), $WS_POPUP, BitOR($WS_EX_TOPMOST, $WS_EX_TRANSPARENT)) GUISetBkColor(0x000000) WinSetTrans($hGUI, "", 0xA0) GUISetState() HotKeySet("{ESC}", "_Exit") Do WinMove($hGUI, "", $aFullScreen[0], MouseGetPos(1)) Until Not Sleep(50) Func _Exit() GUIDelete() Exit EndFunc _____________
      1.1
      #include <GUIConstantsEx.au3> #include <WindowsConstants.au3> #include <WinAPI.au3> AutoItSetOption("GUIOnEventMode", 1) Global $hGUI, $hDC, $hPen, $obj_orig $hGUI = GUICreate("", @DesktopWidth, @DesktopHeight, 0, 0, $WS_POPUP) WinSetTrans($hGUI, "", 1) GUISetState() _line() Func _line() $hDC = _WinAPI_GetWindowDC(0) ; DC of entire screen (desktop) $hPen = _WinAPI_CreatePen($PS_SOLID, 2, 0x00ff) $obj_orig = _WinAPI_SelectObject($hDC, $hPen) GUISetOnEvent($GUI_EVENT_PRIMARYDOWN, "Draw", $hGUI) GUISetOnEvent(-3, "_Exit") Do Until Not Sleep(1000) EndFunc ;==>_line Func Draw() Local $aMC, $mxo, $myo $aMC = GUIGetCursorInfo($hGUI) Do GUISetCursor(0, 1, 0) $mxo = $aMC[0] $myo = $aMC[1] $aMC = GUIGetCursorInfo($hGUI) If $mxo <> $aMC[0] Or $myo <> $aMC[1] Then _WinAPI_DrawLine($hDC, $aMC[0], $aMC[1], $mxo, $myo) _WinAPI_RedrawWindow(_WinAPI_GetDesktopWindow(), 0, 0, $RDW_INVALIDATE) $mxo = $aMC[0] $myo = $aMC[1] EndIf Sleep(10) Until Not $aMC[2] EndFunc Func _Exit() _WinAPI_SelectObject($hDC, $obj_orig) _WinAPI_DeleteObject($hPen) _WinAPI_ReleaseDC(0, $hDC) Exit EndFunc  
×
×
  • Create New...