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

update screen.py so we can draw custom images with any pensize or width #69

Closed
wants to merge 2 commits into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 4 additions & 0 deletions README.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
add this file to avoid FileNotFoundError: [Errno 2] No such file or directory: 'D:\\coding\\pgzero\\README.txt' when create a locally-editable install use pip3.
pip3 install --editable .

maybe the default version of pgzero installed by pip is lower so when debug pgzero code,will not find pgzrun moduel.
2 changes: 1 addition & 1 deletion examples/basic/circle.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
def draw():
screen.clear()
screen.draw.circle((400, 300), 30, 'white')
screen.draw.circle((400, 300), 300, 'red', 10)

24 changes: 13 additions & 11 deletions pgzero/screen.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,9 @@


def round_pos(pos):
"""Round a tuple position so it can be used for drawing."""
"""Round a tuple position so it can be used for drawing.
may cause problems when update.
"""
x, y = pos
return round(x), round(y)

Expand All @@ -27,33 +29,33 @@ def __init__(self, screen):
def _surf(self):
return self._screen.surface

def line(self, start, end, color):
def line(self, start, end, color, pensize = 1):
"""Draw a line from start to end."""
start = round_pos(start)
end = round_pos(end)
pygame.draw.line(self._surf, make_color(color), start, end, 1)
pygame.draw.line(self._surf, make_color(color), start, end, pensize)

def circle(self, pos, radius, color):
def circle(self, pos, radius, color, pensize = 1):
"""Draw a circle."""
pos = round_pos(pos)
pygame.draw.circle(self._surf, make_color(color), pos, radius, 1)
pygame.draw.circle(self._surf, make_color(color), pos, radius, pensize)

def filled_circle(self, pos, radius, color):
def filled_circle(self, pos, radius, color, pensize = 0):
"""Draw a filled circle."""
pos = round_pos(pos)
pygame.draw.circle(self._surf, make_color(color), pos, radius, 0)
pygame.draw.circle(self._surf, make_color(color), pos, radius, pensize)

def rect(self, rect, color):
def rect(self, rect, color, pensize = 1):
"""Draw a rectangle."""
if not isinstance(rect, RECT_CLASSES):
raise TypeError("screen.draw.rect() requires a rect to draw")
pygame.draw.rect(self._surf, make_color(color), rect, 1)
pygame.draw.rect(self._surf, make_color(color), rect, pensize)

def filled_rect(self, rect, color):
def filled_rect(self, rect, color, pensize = 0):
"""Draw a filled rectangle."""
if not isinstance(rect, RECT_CLASSES):
raise TypeError("screen.draw.filled_rect() requires a rect to draw")
pygame.draw.rect(self._surf, make_color(color), rect, 0)
pygame.draw.rect(self._surf, make_color(color), rect, pensize)

def text(self, *args, **kwargs):
"""Draw text to the screen."""
Expand Down