Description
Issue №2388 opened by diazdaiz at 2020-12-09 10:17:06
this is already mentioned in closed issue no. # 448 but i think they didn't really get what DaFluffyPotato actually point out. I just realize that when i try to draw a line with passed width argument, i actually get shear transform rectangle, the problem with thit is when you want to draw continuously line like for example sin wave with width. Here, i will show the result when i want to get a sin point that connect every 10 pixel, so we will get the idea of what i actually talking about:
import pygame
import math
pygame.init()
screen = pygame.display.set_mode((500, 500))
running= True
clock= pygame.time.Clock()
while running:
clock.tick(60)
screen.fill((0,0,0))
for event in pygame.event.get():
if(event.type== pygame.QUIT):
running= False
for i in range(1, 48):
pygame.draw.line(screen, (255,255,255), (i*10, math.sin(i/5)*50+250), ((i+1)*10, math.sin((i+1)/5)*50+250), 20)
pygame.display.flip()
when we run this, we will get:
and i will try to make it more clear why is it happening in the code below:
import pygame
import math
pygame.init()
screen = pygame.display.set_mode((500, 500))
running= True
clock= pygame.time.Clock()
while running:
clock.tick(60)
screen.fill((0,0,0))
for event in pygame.event.get():
if(event.type== pygame.QUIT):
running= False
pygame.draw.line(screen, (255,255,255), (20,20), (80,80), 20)
pygame.draw.line(screen, (255,255,255), (20,20+100), (80,79+100), 20)
pygame.display.flip()
when we run this, we will get:
so, instead of get line with some width, we actually get shear transform rectangle. I actually expecting something like this
can we get update for drawing line function?, i actually might do creating a new draw line function where the idea is create connected plate with length is equal to the width of passed width line argument, like this:
but, i am afraid it will cause graphic performance, because i dont really understand how pygame draw something in screen
Comments
# # MightyJosip commented at 2020-12-11 10:01:43
I would be glad to do it (soon™) just the problem is that it would need to be new function (because draw.lines() has to remain the same)
but, i am afraid it will cause graphic performance, because i dont really understand how pygame draw something in screen
It shouldn't, calculating what to draw is pretty fast (the slowest thing is actually setting that list of pixels in memory)
Now the biggest problem remains to be how should that new function even be called
# # MyreMylar commented at 2020-12-11 11:58:40
draw.thicklines() ?
On Fri, 11 Dec 2020, 10:02 Josip Komljenović, [email protected]
wrote:
I would be glad to do it (soon™) just the problem is that it would need to
be new function (because draw.lines() has to remain the same)but, i am afraid it will cause graphic performance, because i dont really
understand how pygame draw something in screenIt shouldn't, calculating what to draw is pretty fast (the slowest thing
is actually setting that list of pixels in memory)Now the biggest problem remains to be how should that new function even be
called—
You are receiving this because you are subscribed to this thread.
Reply to this email directly, view it on GitHub
<pygame/pygame#2388 issuecomment-743099209>, or
unsubscribe
https://github.com/notifications/unsubscribe-auth/ADGDGGU45E5HATS2BHN2QGDSUHUZTANCNFSM4UTINHBA
.
# # diazdaiz commented at 2020-12-11 16:45:00
Thanks guys for replying, draw.thicklines(), sound good. Btw, i currently using polygon to draw thick line, and it working very well, i hope this algorithm can help you
Algorithm:
- Get point 1(p1), p2, and width
- Get new vector by subtracting p2 by p1
- Rotate that vector 90 degree from p1
- Make it unit vector
- Multiply that unit vector by width/2
- Add and subtract that vector to p1 and p2 to get 4 new point
- Make polygon from that