Skip to content

Commit aa21da1

Browse files
committed
refactoring
1 parent 3acaa50 commit aa21da1

File tree

4 files changed

+4
-16
lines changed

4 files changed

+4
-16
lines changed

__pycache__/particle.cpython-312.pyc

2.04 KB
Binary file not shown.

grid.py

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,4 @@
11
import pygame
2-
from particle import SandParticle
3-
from particle import RockParticle
42

53
class Grid:
64
def __init__(self, width, height, cell_size):
@@ -10,7 +8,6 @@ def __init__(self, width, height, cell_size):
108
self.cells = [[None for _ in range(self.columns)] for _ in range(self.rows)]
119

1210
def draw(self, window):
13-
1411
for row in range(self.rows):
1512
for column in range(self.columns):
1613
particle = self.cells[row][column]

main.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
import pygame, sys
1+
import pygame
22
from simulation import Simulation
33

44
GREY = (29, 29, 29)

simulation.py

Lines changed: 3 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -14,21 +14,18 @@ def draw(self, window):
1414
self.grid.draw(window)
1515
self.draw_brush(window)
1616

17-
1817
def add_particle(self, row, column):
1918
if self.mode == "sand":
20-
# 50% chance to add a sand particle
21-
if random.random() < 0.2: # 50% probability
19+
if random.random() < 0.2:
2220
particle = SandParticle
2321
self.grid.add_particle(row, column, particle)
2422
elif self.mode == "rock":
25-
# Always add a rock particle
2623
particle = RockParticle
2724
self.grid.add_particle(row, column, particle)
2825

2926
def update(self):
3027
orientation = random.randint(0, 1)
31-
for row in range(self.grid.rows - 1, -1, -1): # Start from the bottom
28+
for row in range(self.grid.rows - 1, -1, -1):
3229
if orientation == 0:
3330
for column in range(self.grid.columns - 1, -1, -1):
3431
self.process_particle(row, column)
@@ -92,11 +89,9 @@ def apply_brush(self, row, column):
9289
self.add_particle(current_row, current_col)
9390

9491
def draw_brush(self, window):
95-
9692
mouse_pos = pygame.mouse.get_pos()
9793
column = mouse_pos[0] // self.cell_size
9894
row = mouse_pos[1] // self.cell_size
99-
10095
cursor_size = self.brush_size * self.cell_size
10196
color = (255, 255, 255)
10297

@@ -107,8 +102,4 @@ def draw_brush(self, window):
107102
elif self.mode == "erase":
108103
color = (255, 105, 180)
109104

110-
pygame.draw.rect(
111-
window,
112-
color,
113-
(column * self.cell_size, row * self.cell_size, cursor_size, cursor_size),
114-
)
105+
pygame.draw.rect(window, color, (column * self.cell_size, row * self.cell_size, cursor_size, cursor_size))

0 commit comments

Comments
 (0)