├── README.md ├── main.py ├── requirements.txt └── utils ├── __init__.py ├── __pycache__ ├── __init__.cpython-38.pyc ├── button.cpython-38.pyc └── settings.cpython-38.pyc ├── button.py └── settings.py /README.md: -------------------------------------------------------------------------------- 1 | # PythonPaintProgram 2 | 3 | ## Dependencies 4 | 5 | - Python 3.6+ 6 | 7 | ## Module Installation / Setup 8 | 9 | ```git clone ``` 10 | 11 | ```cd ``` 12 | 13 | ```pip install -r requirements.txt``` 14 | 15 | or 16 | 17 | ```pip3 install -r requirements.txt``` 18 | 19 | or 20 | 21 | ```python - m pip install -r requirements.txt``` 22 | 23 | or 24 | 25 | ```python3 -m pip install -r requirements.txt``` 26 | 27 | ## Running The Program 28 | 29 | ```python main.py``` 30 | 31 | or 32 | 33 | ```python3 main.py``` 34 | 35 | 36 | # 💻 Launch Your Software Development Career Today! 37 | 38 | 🎓 **No degree? No problem!** My program equips you with everything you need to break into tech and land an entry-level software development role. 39 | 40 | 🚀 **Why Join?** 41 | - 💼 **$70k+ starting salary potential** 42 | - 🕐 **Self-paced:** Complete on your own time 43 | - 🤑 **Affordable:** Low risk compared to expensive bootcamps or degrees 44 | - 🎯 **45,000+ job openings** in the market 45 | 46 | 👉 **[Start your journey today!](https://techwithtim.net/dev)** 47 | No experience needed—just your determination. Future-proof your career and unlock six-figure potential like many of our students have! 48 | -------------------------------------------------------------------------------- /main.py: -------------------------------------------------------------------------------- 1 | from utils import * 2 | 3 | WIN = pygame.display.set_mode((WIDTH, HEIGHT)) 4 | pygame.display.set_caption("Drawing Program") 5 | 6 | 7 | def init_grid(rows, cols, color): 8 | grid = [] 9 | 10 | for i in range(rows): 11 | grid.append([]) 12 | for _ in range(cols): 13 | grid[i].append(color) 14 | 15 | return grid 16 | 17 | 18 | def draw_grid(win, grid): 19 | for i, row in enumerate(grid): 20 | for j, pixel in enumerate(row): 21 | pygame.draw.rect(win, pixel, (j * PIXEL_SIZE, i * 22 | PIXEL_SIZE, PIXEL_SIZE, PIXEL_SIZE)) 23 | 24 | if DRAW_GRID_LINES: 25 | for i in range(ROWS + 1): 26 | pygame.draw.line(win, BLACK, (0, i * PIXEL_SIZE), 27 | (WIDTH, i * PIXEL_SIZE)) 28 | 29 | for i in range(COLS + 1): 30 | pygame.draw.line(win, BLACK, (i * PIXEL_SIZE, 0), 31 | (i * PIXEL_SIZE, HEIGHT - TOOLBAR_HEIGHT)) 32 | 33 | 34 | def draw(win, grid, buttons): 35 | win.fill(BG_COLOR) 36 | draw_grid(win, grid) 37 | 38 | for button in buttons: 39 | button.draw(win) 40 | 41 | pygame.display.update() 42 | 43 | 44 | def get_row_col_from_pos(pos): 45 | x, y = pos 46 | row = y // PIXEL_SIZE 47 | col = x // PIXEL_SIZE 48 | 49 | if row >= ROWS: 50 | raise IndexError 51 | 52 | return row, col 53 | 54 | 55 | run = True 56 | clock = pygame.time.Clock() 57 | grid = init_grid(ROWS, COLS, BG_COLOR) 58 | drawing_color = BLACK 59 | 60 | button_y = HEIGHT - TOOLBAR_HEIGHT/2 - 25 61 | buttons = [ 62 | Button(10, button_y, 50, 50, BLACK), 63 | Button(70, button_y, 50, 50, RED), 64 | Button(130, button_y, 50, 50, GREEN), 65 | Button(190, button_y, 50, 50, BLUE), 66 | Button(250, button_y, 50, 50, WHITE, "Erase", BLACK), 67 | Button(310, button_y, 50, 50, WHITE, "Clear", BLACK) 68 | ] 69 | 70 | while run: 71 | clock.tick(FPS) 72 | 73 | for event in pygame.event.get(): 74 | if event.type == pygame.QUIT: 75 | run = False 76 | 77 | if pygame.mouse.get_pressed()[0]: 78 | pos = pygame.mouse.get_pos() 79 | 80 | try: 81 | row, col = get_row_col_from_pos(pos) 82 | grid[row][col] = drawing_color 83 | except IndexError: 84 | for button in buttons: 85 | if not button.clicked(pos): 86 | continue 87 | 88 | drawing_color = button.color 89 | if button.text == "Clear": 90 | grid = init_grid(ROWS, COLS, BG_COLOR) 91 | drawing_color = BLACK 92 | 93 | draw(WIN, grid, buttons) 94 | 95 | pygame.quit() 96 | -------------------------------------------------------------------------------- /requirements.txt: -------------------------------------------------------------------------------- 1 | pygame 2 | -------------------------------------------------------------------------------- /utils/__init__.py: -------------------------------------------------------------------------------- 1 | from .settings import * 2 | from .button import Button 3 | import pygame 4 | pygame.init() 5 | pygame.font.init() 6 | -------------------------------------------------------------------------------- /utils/__pycache__/__init__.cpython-38.pyc: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/techwithtim/PythonPaintProgram/99dc7d8ad8922f5db72ed05bb82a7af0c9ab0a19/utils/__pycache__/__init__.cpython-38.pyc -------------------------------------------------------------------------------- /utils/__pycache__/button.cpython-38.pyc: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/techwithtim/PythonPaintProgram/99dc7d8ad8922f5db72ed05bb82a7af0c9ab0a19/utils/__pycache__/button.cpython-38.pyc -------------------------------------------------------------------------------- /utils/__pycache__/settings.cpython-38.pyc: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/techwithtim/PythonPaintProgram/99dc7d8ad8922f5db72ed05bb82a7af0c9ab0a19/utils/__pycache__/settings.cpython-38.pyc -------------------------------------------------------------------------------- /utils/button.py: -------------------------------------------------------------------------------- 1 | from .settings import * 2 | 3 | 4 | class Button: 5 | def __init__(self, x, y, width, height, color, text=None, text_color=BLACK): 6 | self.x = x 7 | self.y = y 8 | self.width = width 9 | self.height = height 10 | self.color = color 11 | self.text = text 12 | self.text_color = text_color 13 | 14 | def draw(self, win): 15 | pygame.draw.rect( 16 | win, self.color, (self.x, self.y, self.width, self.height)) 17 | pygame.draw.rect( 18 | win, BLACK, (self.x, self.y, self.width, self.height), 2) 19 | if self.text: 20 | button_font = get_font(22) 21 | text_surface = button_font.render(self.text, 1, self.text_color) 22 | win.blit(text_surface, (self.x + self.width / 23 | 2 - text_surface.get_width()/2, self.y + self.height/2 - text_surface.get_height()/2)) 24 | 25 | def clicked(self, pos): 26 | x, y = pos 27 | 28 | if not (x >= self.x and x <= self.x + self.width): 29 | return False 30 | if not (y >= self.y and y <= self.y + self.height): 31 | return False 32 | 33 | return True 34 | -------------------------------------------------------------------------------- /utils/settings.py: -------------------------------------------------------------------------------- 1 | import pygame 2 | pygame.init() 3 | pygame.font.init() 4 | 5 | WHITE = (255, 255, 255) 6 | BLACK = (0, 0, 0) 7 | RED = (255, 0, 0) 8 | BLUE = (0, 255, 0) 9 | GREEN = (0, 0, 255) 10 | 11 | FPS = 240 12 | 13 | WIDTH, HEIGHT = 600, 700 14 | 15 | ROWS = COLS = 100 16 | 17 | TOOLBAR_HEIGHT = HEIGHT - WIDTH 18 | 19 | PIXEL_SIZE = WIDTH // COLS 20 | 21 | BG_COLOR = WHITE 22 | 23 | DRAW_GRID_LINES = True 24 | 25 | 26 | def get_font(size): 27 | return pygame.font.SysFont("comicsans", size) 28 | --------------------------------------------------------------------------------