Sorry your browser is not supported!

You are using an outdated browser that does not support modern web technologies, in order to use this site please update to a new browser.

Browsers supported include Chrome, FireFox, Safari, Opera, Internet Explorer 10+ or Microsoft Edge.

Newcomers AppGameKit Corner / My own DrawEllipse function

Author
Message
Hubert BAYRE
User Offline
Joined: 21st Oct 2017
Location: France
Posted: 5th Jan 2018 11:28 Edited at: 5th Jan 2018 11:29
Hello !

I'm searching some examples to code my own draw FILLED ellipse function.
In fact i need this to draw filled circles on my renderimage.

Have you some code sample to do this ?

this is for an unfilled circle :



Some informations here, but i dont know how to do this with agk (https://stackoverflow.com/questions/10322341/simple-algorithm-for-drawing-filled-ellipse-in-c-c)

Many thanks !
MikeHart
15
Years of Service
User Offline
Joined: 9th Jun 2003
Location: Germany
Posted: 5th Jan 2018 11:48
How about using this command?

DrawEllipse( x, y, radiusx, radiusy, color1, color2, filled )
Running Windows 7 Home, 64 bit, 8 GB ram, Athlon II X2 255, ATI Radeon HD 4200. Using AGK2 Tier 1.
Bengismo
User Offline
Joined: 20th Nov 2017
Location: Yorkshire, England
Posted: 5th Jan 2018 12:15 Edited at: 5th Jan 2018 12:17
Why not use the built in function??

DrawEllipse( x, y, radiusx, radiusy, color1, color2, filled )
https://www.appgamekit.com/documentation/Reference/Core/DrawEllipse.htm


Oops...mike beat me to it.... lol
puzzler2018
User Offline
Joined: 8th Oct 2017
Location:
Posted: 5th Jan 2018 12:53
aww bless and Hubert took the time and energy to create own one.

It is all about learning from each other,so all good all round anyway

Good coding though Hubert


Hubert BAYRE
User Offline
Joined: 21st Oct 2017
Location: France
Posted: 5th Jan 2018 21:06 Edited at: 5th Jan 2018 21:06
I'm searching a way to fix my problem here (https://forum.thegamecreators.com/thread/221225).
Agk2 is very powerfull. I know the DrawEllipse function. But in my case i need to find how to finish my project.
Hubert BAYRE
User Offline
Joined: 21st Oct 2017
Location: France
Posted: 5th Jan 2018 21:21 Edited at: 5th Jan 2018 21:28
http://enchantia.com/graphapp/doc/tech/ellipses.html
Interesting an ellipse filled using scan lines. Not sure to do this with Agk2 :

puzzler2018
User Offline
Joined: 8th Oct 2017
Location:
Posted: 5th Jan 2018 22:18
Nice interesting idea for something different

Will have a go at converting that code to agk when got some time this weekend for you

Hubert BAYRE
User Offline
Joined: 21st Oct 2017
Location: France
Posted: 5th Jan 2018 22:33 Edited at: 5th Jan 2018 22:37
Translated to agk :



works fine.
Hubert BAYRE
User Offline
Joined: 21st Oct 2017
Location: France
Posted: 5th Jan 2018 22:52

Version without external function :

puzzler2018
User Offline
Joined: 8th Oct 2017
Location:
Posted: 5th Jan 2018 23:17
It does indeed, awesome work my good fellow
Hubert BAYRE
User Offline
Joined: 21st Oct 2017
Location: France
Posted: 5th Jan 2018 23:19
No anti-alias with this code, but my problem is fixed now. No idea where was finally the bug. This was the last challenge for my project. Now i've a cool project almost finished.
Many thanks at the community for the help.
puzzler2018
User Offline
Joined: 8th Oct 2017
Location:
Posted: 5th Jan 2018 23:26
you could still have used the in built version of drawellipse

but then if your project (maybe uni project requires you to make an ellipse proramatically) then good for you
puzzler2018
User Offline
Joined: 8th Oct 2017
Location:
Posted: 5th Jan 2018 23:44 Edited at: 5th Jan 2018 23:45
Are you going to be our man to be able to fill in any shape no matter how the shape is?

Phaelax
DBPro Master
15
Years of Service
User Offline
Joined: 16th Apr 2003
Location: Metropia
Posted: 8th Jan 2018 18:01
Quote: "Are you going to be our man to be able to fill in any shape no matter how the shape is?"


Several of us have already done that, it's called a flood fill. Though with something as simple as an ellipse, it'd be overkill.
Tiled TMX Importer V.2
XML Parser V.2
Base64 Encoder/Decoder
Purple Token - Free online hi-score database
Legend of Zelda

"I like offending people, because I think people who get offended should be offended." - Linus Torvalds
janbo
9
Years of Service
User Offline
Joined: 10th Nov 2008
Location: Germany
Posted: 9th Jan 2018 01:50 Edited at: 9th Jan 2018 04:41
The Scan line method is much more efficient.
He could probably optimize it for his purposes, as I think he doesn't need to draw the full ellipse.
Not sure how he does it but...
I would draw with straight lines as it can happen that the pointer jumps leaving a gap in the resulting line.
Then you need a function that not only draws a circle, but a line with width.
Again I would "draw" the two halves of the circle outline, one a the line stat and one at the line end facing to the line opposite point and from there drawing lines connecting the two halves.
( ----------- )
Should be pretty fast and won't give you any gaps.

You can also fill every shape with the scanline method.
You need to split the polygon into convex shapes then each convex polygon into triangles, then every triangle into a top and bottom triangle with a horizontal edge and fill them with horizontal lines.
Not sure how efficient that is vs flood fill.
Phaelax
DBPro Master
15
Years of Service
User Offline
Joined: 16th Apr 2003
Location: Metropia
Posted: 10th Jan 2018 16:09
If he's already got the math to draw the outline of the ellipse, then technically the ability to fill it is already there. Take an edge pixel and draw a horizontal line from it to the center. And the drawing loop can be minimized due to the fact an ellipse is made up of 4 identical quadrants, just reverse the Xs and Ys for each quadrant. (if that makes sense)

I typed this pseudo-code in notepad, so run it at your own risk. Not 100% sure it'll work, but I think it will if I did my math correctly. What this should do is start at the center of the ellipse and traverse along y-axis for the length of the ellipse's Y-radius. At each point, it'll calculate where the corresponding X-pixel should be for the outline of the ellipse. It will then drawn a line from that point horizontally to the other side of the ellipse. It'll do this for the top half and the bottom half (hence the two draw commands), as each line will handle drawing for two quadrants. (the first being the upper half, the second line draws the lower)



In theory this should work for axis-aligned ellipses. If you want anti-aliased ellipses, I can probably manage it but I'll need to take time to do it and use more than notepad.
Tiled TMX Importer V.2
XML Parser V.2
Base64 Encoder/Decoder
Purple Token - Free online hi-score database
Legend of Zelda

"I like offending people, because I think people who get offended should be offended." - Linus Torvalds

Login to post a reply

Server time is: 2018-07-23 07:08:23
Your offset time is: 2018-07-23 07:08:23