-
-
Notifications
You must be signed in to change notification settings - Fork 165
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 Circle rotate()
/ rotate_ip()
#2662
Conversation
Co-authored-by: Emc2356 <63981925+emc2356@users.noreply.github.com> Co-authored-by: NovialRiptide <35881688+novialriptide@users.noreply.github.com> Co-authored-by: ScriptLineStudios <scriptlinestudios@protonmail.com> Co-authored-by: Avaxar <44055981+avaxar@users.noreply.github.com> Co-authored-by: maqa41 <amehebbet41@gmail.com>
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
A really minor thing, but also the error messages have inconsistencies in first letter cases, they should all be lowercase, i.e., Invalid
-> invalid
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
LGTM 👍 Does what it says, and there is documentation and tests.
I used the following cisual test program to tinker around with it:
import pygame
from pygame import Color
from pygame.geometry import Circle
pygame.init()
screen = pygame.display.set_mode((640, 480), 0)
white_background = pygame.Surface(screen.get_rect().size)
white_background.fill((255, 255, 255))
circle_1 = Circle((50, 50), 30)
circle_col = Color("red")
circle_2 = Circle((250, 250), 30)
circle_2_col = Color("blue")
clock = pygame.time.Clock()
running = True
curr_angle = 2.0
rotate_time = 0.005
rotate_acc = 0.0
while running:
for event in pygame.event.get():
if event.type == pygame.QUIT:
running = False
if event.type == pygame.MOUSEBUTTONDOWN and event.button == pygame.BUTTON_LEFT:
circle_1.center = (
pygame.mouse.get_pos()[0],
pygame.mouse.get_pos()[1] - 60,
)
if event.type == pygame.MOUSEBUTTONDOWN and event.button == pygame.BUTTON_RIGHT:
circle_2 = circle_2.rotate(90, pygame.mouse.get_pos())
dt = clock.tick() / 1000.0
rotate_acc += dt
if rotate_acc >= rotate_time:
rotate_acc = 0.0
circle_1.rotate_ip(curr_angle, pygame.mouse.get_pos())
if circle_1.collidecircle(circle_2.x, circle_2.y, circle_2.radius):
circle_col = Color("blue")
circle_2_col = Color("green")
else:
circle_col = Color("red")
circle_2_col = Color("blue")
screen.blit(white_background, (0, 0))
pygame.draw.circle(screen, circle_col, (circle_1.x, circle_1.y), circle_1.r)
pygame.draw.circle(screen, circle_2_col, (circle_2.x, circle_2.y), circle_2.r)
pygame.display.flip()
pygame.quit()
I left a couple of minor suggestions on the documentation and spotted one copy and paste typo in the tests.
Co-authored-by: Dan Lawrence <danintheshed@gmail.com>
You'll need to merge with main again to pick up that CircleCI fix I guess. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Thanks for the PR 🎉
This PR adds the circle.rotate and circle.rotate_ip functions.
Credits
Geometry Project:
For code, docs and tests:
@novialriptide @Emc2356 @itzpr3d4t0r @ScriptLineStudios @avaxar @Matiiss @newpaxonian @maqa41 @blankRiot96
Also thanks to @Starbuck5 for kickstarting the idea and the occasional help!
Functionality added in this PR
circle.c
https://github.com/pygame-community/pygame-geometry/blame/main/src_c/circle.c
Credits to @Emc2356 @itzpr3d4t0r @novialriptide
geometry.pyi
https://github.com/pygame-community/pygame-geometry/blame/main/geometry.pyi
Credits to @Emc2356 @itzpr3d4t0r @novialriptide @ScriptLineStudios @avaxar
geometry_test.py
https://github.com/pygame-community/pygame-geometry/blame/main/test/test_circle.py
Credits to @itzpr3d4t0r @novialriptide
geometry.rst
https://github.com/pygame-community/pygame-geometry/blame/main/docs/circle.rst
Credits to @itzpr3d4t0r
geometry.h
https://github.com/pygame-community/pygame-geometry/blame/main/src_c/include/geometry.h
Credits to @Emc2356 @itzpr3d4t0r @maqa41