GASP/GASP_Code
6
1
Fork
You've already forked GASP_Code
4

Titles, Circles, and Keystroke Updates #4

Closed
opened 2020年07月22日 23:48:03 +02:00 by caleb33 · 1 comment

My first issue is super small but in the Pygame version of Gasp the begin_graphics() function has the parameter screen_title while Tkinter uses title, so assigning arguments using the parameter name and '=' causes an error.

Secondly, in my efforts to run the Robots game in Tkinter Gasp, I found there is no way to draw circles (used to show the player for the game). Below I have attempted to solve the issue. It seems to work when I have tried it, but deserves further testing and optimization.

class Circle:
 """Draw a circle centered at the given coordinates with the given radius"""
 def __init__(self, position, radius, color=color.BLACK, filled=False):
 self.x = position[0]
 self.y = position[1]
 self.radius = radius
 self.color = color
 self.filled = filled
 x0 = self.x - self.radius
 y0 = self.y - self.radius
 x1 = self.x + self.radius
 y1 = self.y + self.radius
 
 if filled:
 fill = color
 else:
 fill = ""
 self.id = _canvas.create_oval(x0, y0, x1, y1, outline=color, fill=fill)
 _canvas.update()
 def __repr__(self):
 return f"<Circle object centered at ({self.position}) with a radius of {self.radius}"

Lastly, Tkinter Gasp has no function for update_when to handle keystrokes as game input. Solving this issue might be beyond my current skillset.

All bugs are on Python 3.8.2 on my MacBook Pro running Catalina 10.15.5

My first issue is super small but in the Pygame version of Gasp the `begin_graphics()` function has the parameter `screen_title` while Tkinter uses `title`, so assigning arguments using the parameter name and '=' causes an error. Secondly, in my efforts to run the Robots game in Tkinter Gasp, I found there is no way to draw circles (used to show the player for the game). Below I have attempted to solve the issue. It seems to work when I have tried it, but deserves further testing and optimization. ``` class Circle: """Draw a circle centered at the given coordinates with the given radius""" def __init__(self, position, radius, color=color.BLACK, filled=False): self.x = position[0] self.y = position[1] self.radius = radius self.color = color self.filled = filled x0 = self.x - self.radius y0 = self.y - self.radius x1 = self.x + self.radius y1 = self.y + self.radius if filled: fill = color else: fill = "" self.id = _canvas.create_oval(x0, y0, x1, y1, outline=color, fill=fill) _canvas.update() def __repr__(self): return f"<Circle object centered at ({self.position}) with a radius of {self.radius}" ``` Lastly, Tkinter Gasp has no function for `update_when` to handle keystrokes as game input. Solving this issue might be beyond my current skillset. All bugs are on Python 3.8.2 on my MacBook Pro running Catalina 10.15.5

Nice work, Caleb! Let's hold off on even looking at the Pygame version until we get the Tkinter one complete. Your screen_title issue should be filed for the GASP_Pygame, not here. We are working on off the API as defined on Sheet G (http://www.openbookproject.net/pybiblio/gasp/course/G-gasp.html), so title is the name it should have.

I added your Circle class, togther with tests. So that now works. I've added you to the new AUTHORS.md file to credit you for your work. You might want to spruce up your personal page a bit, so we can link to it, since this is now becoming a public part of your resume.

Lastly, a challenge. See if you can look at the beginners.py module here:

https://github.com/livewires/python/blob/master/module/livewires/beginners.py

and use that to figure out how to make update_when work.

Nice work, Caleb! Let's hold off on even looking at the Pygame version until we get the Tkinter one complete. Your screen_title issue should be filed for the GASP_Pygame, not here. We are working on off the API as defined on Sheet G (http://www.openbookproject.net/pybiblio/gasp/course/G-gasp.html), so title is the name it should have. I added your Circle class, togther with tests. So that now works. I've added you to the new AUTHORS.md file to credit you for your work. You might want to spruce up your personal page a bit, so we can link to it, since this is now becoming a public part of your resume. Lastly, a challenge. See if you can look at the beginners.py module here: https://github.com/livewires/python/blob/master/module/livewires/beginners.py and use that to figure out how to make update_when work.
Sign in to join this conversation.
No Branch/Tag specified
main
No results found.
Milestone
Clear milestone
No items
No milestone
Projects
Clear projects
No items
No project
Assignees
Clear assignees
No assignees
2 participants
Notifications
Due date
The due date is invalid or out of range. Please use the format "yyyy-mm-dd".

No due date set.

Dependencies

No dependencies set.

Reference
GASP/GASP_Code#4
Reference in a new issue
GASP/GASP_Code
No description provided.
Delete branch "%!s()"

Deleting a branch is permanent. Although the deleted branch may continue to exist for a short time before it actually gets removed, it CANNOT be undone in most cases. Continue?