snakeware

Python-based Linux distro for x86-64 and RPi
git clone git://squid-tech.com/snakeware.git
Log | Files | Refs | README

commit 40f21d7f629d61d713b60678655b75fcfc6984ff
parent de1d1506718ddff09d6e357b05c64cc718e6306c
Author: Josh Moore <jxm5210@g.rit.edu>
Date:   Wed, 10 Jun 2020 13:35:49 -0400

Merge pull request #103 from mochidaz/master

Added eraser to snakepaint with toggle mechanic
Diffstat:
Msnake_games/snakepaint/README.txt | 9+++++++--
Msnake_games/snakepaint/snakepaint.py | 22++++++++++++++++++----
2 files changed, 25 insertions(+), 6 deletions(-)

diff --git a/snake_games/snakepaint/README.txt b/snake_games/snakepaint/README.txt @@ -3,4 +3,9 @@ SnakePaint Ported and adapted to OOP by: Mochidaz github: https://github.com/mochidaz -Original: https://www.instagram.com/p/CBGDdp4gVH-/- \ No newline at end of file +Original: https://www.instagram.com/p/CBGDdp4gVH-/ + +How to use: +-Hold left/right mouse button to paint +-Use scroll to paint dots +-Press D to toggle eraser, press d again to switch back to paint+ \ No newline at end of file diff --git a/snake_games/snakepaint/snakepaint.py b/snake_games/snakepaint/snakepaint.py @@ -19,6 +19,7 @@ class SnakePaint: self.last_pos = (0, 0) self.color = (255, 128, 0) self.radius = 10 + self.eraser = False def on_init(self): pygame.init() @@ -42,12 +43,24 @@ class SnakePaint: e = pygame.event.wait() if keys[pygame.K_ESCAPE]: self._running = False + if e.type == pygame.KEYUP: + if e.key == pygame.K_d: + self.eraser = not self.eraser pygame.event.pump() if e.type == pygame.MOUSEBUTTONDOWN: + if self.eraser: + self.color = (0,0,0) + else: + self.color = ( + random.randrange(256), + random.randrange(256), + random.randrange(256), + ) + pygame.draw.circle(self._display_surf, self.color, e.pos, self.radius) + self.draw_on = True + elif e.type == pygame.MOUSEBUTTONDOWN and self.eraser is True: self.color = ( - random.randrange(256), - random.randrange(256), - random.randrange(256), + 0,0,0 ) pygame.draw.circle(self._display_surf, self.color, e.pos, self.radius) self.draw_on = True @@ -66,4 +79,4 @@ class SnakePaint: self.radius, ) self.last_pos = e.pos - pygame.display.flip() + pygame.display.flip()+ \ No newline at end of file