TheAutomator Posted November 28, 2017 Posted November 28, 2017 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.. expandcollapse popupfunc 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 Retro Console, NestedArrayDisplay UDF foldermaker-pro-clone MiniMark Editor
junkew Posted November 28, 2017 Posted November 28, 2017 https://www.autoitscript.com/forum/search/?&q=drawellipse FAQ 31 How to click some elements, FAQ 40 Test automation with AutoIt, Multithreading CLR .NET Powershell CMDLets
TheAutomator Posted November 29, 2017 Author Posted November 29, 2017 3 minutes ago, junkew said: https://www.autoitscript.com/forum/search/?&q=drawellipse don't need a function that hides the actual code that draws the ellipse i need the code itself that puts the pixels where they are supposed to be Retro Console, NestedArrayDisplay UDF foldermaker-pro-clone MiniMark Editor
Gianni Posted November 29, 2017 Posted November 29, 2017 (edited) 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 November 29, 2017 by Chimp TheAutomator 1 Chimp small minds discuss people average minds discuss events great minds discuss ideas.... and use AutoIt....
TheAutomator Posted November 29, 2017 Author Posted November 29, 2017 Chimp, Thanks so much, i'm gonna look in to that! haha "a naive question" Retro Console, NestedArrayDisplay UDF foldermaker-pro-clone MiniMark Editor
TheAutomator Posted November 29, 2017 Author Posted November 29, 2017 (edited) Would be nice to know how to fill the ellipse too btw [edit:] if you draw an ellipse with your algorithm (w = 9, h = 4) then there are some pixels drawn twice.. Edited November 29, 2017 by TheAutomator Retro Console, NestedArrayDisplay UDF foldermaker-pro-clone MiniMark Editor
Recommended Posts
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 accountSign in
Already have an account? Sign in here.
Sign In Now