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

Add draw.aaline width argument #3140

Merged
merged 5 commits into from
Oct 5, 2024

Conversation

mzivic7
Copy link
Contributor

@mzivic7 mzivic7 commented Oct 4, 2024

This PR adds width argument to draw.aaline.

How it works:
First draw draw_line_width (its not antialiased).
Calculate its corner points, but slightly move them so relevant antialiased pixels don't overlap with fully opaque pixels.
Then draw 2 thin draw_aaline.

I made this calculation in separate function line_width_corners, because it will be used again when implementing width for draw.aalines and draw.aapolygon.

Screenshot From 2024-10-04 20-53-09

Sample code
import pygame

pygame.init()
screen = pygame.display.set_mode((300, 300))
clock = pygame.time.Clock()
run = True
while run:
  for event in pygame.event.get():
      if event.type == pygame.QUIT:
          run = False
  screen.fill("black")
  pygame.draw.aaline(screen, "white", (120, 100), (220, 160), 16)
  pygame.draw.aaline(screen, "red", (180, 170), (100, 260), 16)
  pygame.draw.aaline(screen, "blue", (70, 240), (150, 150), 7)
  pygame.display.flip()
  clock.tick(60)
pygame.quit()

Added to code examples
Added to documentation
@mzivic7 mzivic7 requested a review from a team as a code owner October 4, 2024 19:19
@damusss damusss added the draw pygame.draw label Oct 4, 2024
Copy link
Contributor

@bilhox bilhox left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM, big thanks for this work!

It will just need a little update with upstream and test fixes.

Copy link
Contributor

@bilhox bilhox left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Actually I forgot something important, the final step is also to add new unittests.

@damusss
Copy link
Member

damusss commented Oct 4, 2024

Actually I forgot something important, the final step is also to add new unittests.

well also perhaps it'd be nice if there weren't 15 failed checks lmao

@bilhox
Copy link
Contributor

bilhox commented Oct 4, 2024

Judging by how much line got updated/added, I'm moving this PR to 2.5.2 milestone.

@bilhox bilhox added this to the 2.5.2 milestone Oct 4, 2024
@mzivic7 mzivic7 mentioned this pull request Oct 4, 2024
19 tasks
Copy link
Contributor

@bilhox bilhox left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM

Copy link
Member

@damusss damusss left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Awesome, thank you :) LGTM 👍
Looking forward for aalines, polygon, and aapolygon width enhancements (especially polygon, bro is really ugly at the moment)

Copy link
Member

@MyreMylar MyreMylar left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

OK, LGTM. Line output looks good in local testing and the code makes sense.

👍 🎆 🍾

@MyreMylar MyreMylar merged commit 0f42f98 into pygame-community:main Oct 5, 2024
25 checks passed
@mzivic7 mzivic7 deleted the draw.aaline_width branch October 5, 2024 17:00
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
draw pygame.draw
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants