Yay, it works! Drawing broad lines the pygamedraw way
June 23, 2010The the basic shape algorithms are mostly implemented and I get more and more to the parts of implementing new features and improving stuff. Today I worked one the Pen.line() method or more specifically the drawing of broad poly-lines through more than two points.
First, lets have a look how the current implementation does it:
Well, that’s just a multiple call of pygame.draw.line() which is also badly implemented as it simply adds half of the width on both sides to either the x or y values of the endpoints (and thus different angles result in different line widths). This is just ugly and nearly unusable.
So I had to fix that and do a bit more than calling Pen.line(surf, point1, point2). But what? There are quite a few ways how to draw the corners and so I added the next attribute to the Pen class, called line_style.
Currently there are 4 different line styles (and no more planned because I cannot think of any further (useful) style(s), but if you do, please tell me and I may think about it): DENTED_VERT, SHARP_VERT, FLAT_VERT and ROUND_VERT.
First of all, I did some studies and tests and thought about lines and how to draw and connect them to nice-looking polylines:
Some more tests and a first, ugly hacked version ensued. Then I rewrote it and did a cleaner implementation using an own Vert class to hold the data and do some calculations.
At the end, it looks like this:
I also added a first style for line endings (more styles will come later):
Yay, that’s a lot better and more flexible than the current pygame/sdl implementation and thas is what this whole GSoC project is all about! 🙂
Nice! This looks great 🙂
by Tim July 3, 2010 at 7:48 amWill these also be antialiased?
Yes.
by pygamedraw July 3, 2010 at 5:14 pmi really appreciate your work. once i was trying to draw a blue elliptical energy shield for my spaceship with pygame and it was very ugly, no AA and no alpha. it was really annoying but now im really happy to looking forward to have these awesome drawing functions available / thank you !
by Peter July 9, 2010 at 7:01 pmLooks awesome! Keep it up!
by Atav October 30, 2010 at 6:32 pmThanks!
by Pedro will not tell the rest December 16, 2018 at 5:54 pm