Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

create draw.thicklines() with tangentially angled ends to allow for joined up thick line sections (2388) #1225

Open
GalacticEmperor1 opened this issue Feb 12, 2023 · 0 comments · May be fixed by #3154
Labels

Comments

@GalacticEmperor1
Copy link
Collaborator

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:
hmmm

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:
hmmm2

so, instead of get line with some width, we actually get shear transform rectangle. I actually expecting something like this
expectation

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:
hmmm3

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 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


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:

  1. Get point 1(p1), p2, and width
  2. Get new vector by subtracting p2 by p1
  3. Rotate that vector 90 degree from p1
  4. Make it unit vector
  5. Multiply that unit vector by width/2
  6. Add and subtract that vector to p1 and p2 to get 4 new point
  7. Make polygon from that
@MyreMylar MyreMylar changed the title get shear transform rectangle instead of thick line(?) (2388) create draw.thicklines() with tangentially angled ends to allow for joined up thick line sections (2388) May 28, 2024
@mzivic7 mzivic7 linked a pull request Oct 7, 2024 that will close this issue
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

Successfully merging a pull request may close this issue.

2 participants