From 9f786aee883f380a74bbda1a3fd3b2d995cec358 Mon Sep 17 00:00:00 2001 From: Trimpta <68428753+trimpta@users.noreply.github.com> Date: Mon, 12 Feb 2024 17:03:15 +0530 Subject: [PATCH 01/11] fixes --- .gitignore | 1 + __pycache__/classes.cpython-311.pyc | Bin 8412 -> 8569 bytes classes.py | 5 +++-- main.py | 23 +++++++++++++++++------ 4 files changed, 21 insertions(+), 8 deletions(-) diff --git a/.gitignore b/.gitignore index c12916f..ef07548 100644 --- a/.gitignore +++ b/.gitignore @@ -2,3 +2,4 @@ *.pyc *.pyc *.pyc +*.pyc diff --git a/__pycache__/classes.cpython-311.pyc b/__pycache__/classes.cpython-311.pyc index b2272fa11e628da3776d4cc116efc6aedefd2902..52f52ca87b63c3bc13612ea3d630fe30f6b738de 100644 GIT binary patch delta 775 zcmZ{hUuaTM9LLX3z1PjD)4Qwb)%??NR*-~36hSqkAR&qVX>G%{T_KB9u8vT)vOTRB z{rkP_v4>bv4=tpJdaBnVxWXPn8VE63Zw`8?mpaFrgJAs*_jA7Y`#tCUIGit|KjYSC z7K@3{x57=H=mj!sc2(GeimsZ8mQ-oB(_rsj7a!*7aT5Uh%43Z+~* zSI7qn)6+A>TviSSgLu%f2Sl85q=gn&RC4)ptN(nZm_4B=1qI(aGLS&Y`B7Rk+aC_! zO)MrB5^I7-^+uaQY*mP<=2&Ch83q_bi|f&xRgRDjxA4s@9s-K_QuUDDIKN{QzLCGcmtUC?(@~- zO;@C8jx4}uvu*Lzl3}URbnWiB_|iKA?M7(lIe>Yr_;PRwzxqZ7x=l{ACRb7PkKBGw zWo>J;`%SfY$FPHoLx(Uv3Dx!W<8|ZHi1xoy(&l&5+N`F=)rl+Wq^wTJtEuc?vvgAv z+b~Lap`!yX)*%#|_{Q(I`MCWZvV~)S-~17{jLtw9Zs3tX=IBX)Lmjd`H@p6i|D=k8 G-tP}=MZJ;$ delta 616 zcmezAbjOizIWI340}$kXKaqNwejbq(ml5Nq^x3+Q(@ zMHva>FpzP6AR-(@Kuia*SU?2Gn?)eM6vcxGK@br=IY&l;4XiJG@+282o&=z1u^}S^ zLj%Ku$&9iJlVo*8F7jw}Fy7!1=<%GvGNbaMga%MxvbSt0nDrKXEH`i zu9sKi1{>`QGCF1Q26?sm13+d296sRWYH<3%BFgH-_<;dLE>K;;yux_}`w~3}e?u{Z zK9CHdFNDWjh)uYVm~tUD Date: Mon, 12 Feb 2024 20:59:58 +0530 Subject: [PATCH 02/11] Update .gitignore --- .gitignore | 4 ---- 1 file changed, 4 deletions(-) diff --git a/.gitignore b/.gitignore index ef07548..0d20b64 100644 --- a/.gitignore +++ b/.gitignore @@ -1,5 +1 @@ - -*.pyc -*.pyc -*.pyc *.pyc From 8700066ef7c8acce555192336a78cbe9d056956f Mon Sep 17 00:00:00 2001 From: Trimpta <68428753+trimpta@users.noreply.github.com> Date: Wed, 14 Feb 2024 03:05:11 +0530 Subject: [PATCH 03/11] wasm combatiblity wooo --- main.py | 50 +++++++++++++++++++++++++++++--------------------- 1 file changed, 29 insertions(+), 21 deletions(-) diff --git a/main.py b/main.py index 63b7119..d1fc803 100644 --- a/main.py +++ b/main.py @@ -9,11 +9,10 @@ import pygame import asyncio - try: import plyer plyer.accelerometer.enable() - if plyer.accelerometer.acceleration[0] is None: + if plyer.accelerometer.acceleration[0] == 0: accel = False raise ValueError @@ -29,52 +28,61 @@ screen = pygame.display.set_mode((width,height), flags= pygame.RESIZABLE) surface = plane((width/10,height/10)) +clear_button = Button((50,10),(20,50),"clear", (150,150,150), (10,10,10), surface.clear) + + + +pygame.mouse.set_pos((height/2, width/2)) + async def main(): - global previous_time, accel + + global accel, previous_time + while True: clock.tick() for event in pygame.event.get(): + if event.type == pygame.QUIT: pygame.quit() break + if event.type == pygame.KEYDOWN: + surface.clear() - if event.key == pygame.K_SPACE: - surface.contents = [] - + clear_button.handle_events(event) + + clear_button.draw(screen) if pygame.mouse.get_pressed()[0]: mX, mY = pygame.mouse.get_pos() - try: - surface.contents.append(dust(surface, (mX/10, mY/10), mass= random.randint(10,100)/10)) - except TypeError: - pass + if dust.gridPos(mX/10, mY/10) not in surface.positions: + surface.contents.append(dust(surface, (mX/10, mY/10),mass = random.randint(10, 30)/10)) + #Loop variables + deltaTime = time.time() - previous_time + previous_time = time.time() + if accel: force = plyer.accelerometer.get_acceleration()[:-1] else: surface.followMouse(surface) force = surface.force() - - #Loop variables - deltaTime = time.time() - previous_time - previous_time = time.time() #Particle updates - for particle in surface.contents: - particle.updatePos(deltaTime, force) - particle.draw(screen) - - pygame.display.set_caption(f"pixel-dust | trimpta | FPS: {clock.get_fps():.0f} | PC: {len(surface.contents)}") + surface.update(screen, deltaTime , force) + + surface.indicator(screen) - surface.updateSize(screen) + + + pygame.display.set_caption(f"pixel-dust | trimpta | FPS: {clock.get_fps():.0f} | PC: {len(surface.contents)}") pygame.display.update() screen.fill((0,0,0)) - surface.positions = [] + surface.updateSize(screen) await asyncio.sleep(0) From 44581b4849535f44bedaaf19575b93d324b85151 Mon Sep 17 00:00:00 2001 From: Trimpta <68428753+trimpta@users.noreply.github.com> Date: Wed, 14 Feb 2024 07:38:00 +0530 Subject: [PATCH 04/11] att --- .gitignore | 1 + __pycache__/classes.cpython-311.pyc | Bin 8569 -> 8518 bytes button.py | 51 ++++++++++++++++++++++++++++ classes.py | 42 +++++++++++++++-------- main.py | 9 +++-- 5 files changed, 83 insertions(+), 20 deletions(-) create mode 100644 button.py diff --git a/.gitignore b/.gitignore index 0d20b64..1d036fd 100644 --- a/.gitignore +++ b/.gitignore @@ -1 +1,2 @@ *.pyc +__pycache__/classes.cpython-311.pyc diff --git a/__pycache__/classes.cpython-311.pyc b/__pycache__/classes.cpython-311.pyc index 52f52ca87b63c3bc13612ea3d630fe30f6b738de..a726a5df2f5c194b22c39a57e5bb202d03a46e3c 100644 GIT binary patch delta 481 zcmezAbj*o&IWI340}xDlcsf;XBkyt{#-7bvg)T5M3QTSjkz;9MOktgTOhi>$0Hg>6 zvcY7rejXzuLkepRLl*PoQzC}8!XSQ$Dp(Rsq_8bxWMEhg#1H^9i6NK)gf-dyig~JCvlcL9;l`$1Vn^RPLot( zjN9BPxq-wWGBTvF)i7i+PhKOUs4N6il?`ST3xniK)M26w3@PlB zbwnjaIQ)uufPydOK*WC_@rzM$a+s(+qsZiGqLFN@1x1;8C6nKYW-)qAjubn?#UnUD zxznr1tHW!vintjgWAx-`iL=~^K#fJAAR=tCv7{1X{N^yp4NS)2AQ3+h5rI$uVzGb- zeh?u5B9cIaAc%;WY$>C_2G$obIbOzz2P9Q&4fJyZ!-L7^WE3`^l@VcLY?}N?E|W2G zvX8tPH(0YTNOQ*IT6yajaaJeB4-6o3f$9q870xTzm*_$G8;T+Hfn*4MAw1?nY{G@a zlnb#bSHe@Fg2m+!1{Tt2vWP-9W7OmZ1$D;U$tx7%?cEp|Ek7_|CqIJ4zu=H95(PRL E0D7%@0{{R3 diff --git a/button.py b/button.py new file mode 100644 index 0000000..a844a11 --- /dev/null +++ b/button.py @@ -0,0 +1,51 @@ +""" +This file is a part of the 'Pygame Examples (pgex)' source code. +The source code is distributed under the MIT license. +""" +from typing import Tuple, Union + +import pygame + + +class Button: + def __init__( + self, + pos: Tuple[int, int], + size: Tuple[int, int], + text: str, + text_color: Union[str, Tuple[int, int, int]], + bg_color: Union[str, Tuple[int, int, int]], + method: callable = lambda: None, + ) -> None: + self.rect = pygame.Rect(pos, size) + self.font = pygame.font.SysFont("Arial", size[1]) + self.text_surf = self.font.render(text, False, text_color) + + self.color = bg_color + self.text = text + self.func = method + + self._text_pos = self.text_surf.get_rect(center=self.rect.center).topleft + + self._is_pressed = False + + def draw(self, surface: pygame.Surface) -> None: + """Draws the pygame.Rect and font""" + pygame.draw.rect(surface, self.color, self.rect) + surface.blit( + self.text_surf, + self._text_pos, + ) + + def handle_events(self, event: pygame.event.Event) -> None: + """Put this inside of your event loop""" + if event.type == pygame.MOUSEBUTTONDOWN: + if event.button == 1 and self.rect.collidepoint(event.pos): + self._is_pressed = True + else: + self._is_pressed = False + + elif event.type == pygame.MOUSEBUTTONUP: + if self._is_pressed and self.rect.collidepoint(event.pos): + self.func() + self._is_pressed = False \ No newline at end of file diff --git a/classes.py b/classes.py index 96d6d86..1c7673e 100644 --- a/classes.py +++ b/classes.py @@ -41,7 +41,11 @@ def followMouse(self,screen): y = pygame.mouse.get_pos()[1] - h/2 self.setAngle(x * unitX, y * unitY) - + + def update(self, screen, deltaTime, force): + for particle in self.contents: + particle.updatePos(deltaTime, force) + particle.draw(screen) def force(self): self.forceX = plane.g * math.sin(self.skewX) @@ -59,9 +63,14 @@ def indicator(self,screen): def updateSize(self, screen): self.sizeX, self.sizeY = pygame.display.Info().current_w/10 , pygame.display.Info().current_h/10 + def clear(self): + self.contents = [] + dust.id = 0 + class dust: id = 0 + dampCollisions = 5 def __init__(self, plane, pos:tuple[int,int], mass:int = 1, color:str = False, vel:tuple[int,int] = (0, 0)) -> None: @@ -78,11 +87,8 @@ def __init__(self, plane, pos:tuple[int,int], mass:int = 1, color:str = False, v else: self.color = (random.randint(30,255),random.randint(30,255),random.randint(30,255)) - if self.pos() not in self.plane.positions: - self.plane.contents.append(self) - else: - del self - raise TypeError('Position occupied!!!') + self.plane.contents.append(self) + self.plane.positions.append(self.pos()) if not (0 Date: Wed, 14 Feb 2024 07:47:17 +0530 Subject: [PATCH 05/11] push --- main.py | 1 - 1 file changed, 1 deletion(-) diff --git a/main.py b/main.py index 4ef256e..79a125b 100644 --- a/main.py +++ b/main.py @@ -17,7 +17,6 @@ except Exception as e: accel = False -accel = True pygame.init() clock = pygame.time.Clock() From 5c5996d76bb40ec36626657dfb44efe525e44d63 Mon Sep 17 00:00:00 2001 From: Trimpta <68428753+trimpta@users.noreply.github.com> Date: Fri, 16 Feb 2024 16:36:45 +0530 Subject: [PATCH 06/11] grid, color, button, code --- __pycache__/classes.cpython-311.pyc | Bin 8518 -> 13132 bytes button.py | 51 ------------------ classes.py | 79 +++++++++++++++++++++++----- main.py | 26 ++++----- 4 files changed, 78 insertions(+), 78 deletions(-) delete mode 100644 button.py diff --git a/__pycache__/classes.cpython-311.pyc b/__pycache__/classes.cpython-311.pyc index a726a5df2f5c194b22c39a57e5bb202d03a46e3c..d6542b39a9564e21c870654638ddb568af1f0b94 100644 GIT binary patch literal 13132 zcmb_iYit`=cAg_#s=e*U8#RWXrOx#ByTEv8~uqXw68bLQ%>L zwYIg=R$b%=9ViXG5MXAZ6qAMGrE71iq7JH}{*fPTkrvyQBMcy600S!8{O~^oPJv>9 zB0c90=W-}fn{2a}!*kzv?&I8Z&i(HE+VA%;;O?~lyVzCDF#m}W(>Zd1XOj@P%Lt6X z#+W|CXZu(ZxAob;x5exujy}f-*T=DpjXA{#_V*dVanHsu58!XOJ}1fHAji2b$3=2n zki)Ob;RUvb3A>+S6Ww8(&h?Iu#YCOE5RZ<=2XZYF&zp-p`#A*eG9rULgx;}zcEKjt zhL}OSU>6-CCvt-}7;4T5kRm{u;1r#LOW+4Rg8O~0&n0-?XZm=-3)C(6fO-T!P_Iw| z)F%Xh`h`-UB|;g{fKU#!RHy)2Ch*Ybpw5lOB5`r(mmi~Rd_}^U&>eDg0{Sn%E8e(d zc$am4U^Jc(;|W=JN@8MMigyn<&HjOJ&;6gh#*%elCz*blEnp1N4M$>h#z_oo6F12U ztYzG`379cRv#(DZutAIF+A|R5%oY+pGsG~%E;Fp~X2|N_gUAD#FzhyiKcEf5sn`zb zp}F4JL)x!N?7QE5*CYqA5;Hc0B?D$mU|@|L-DFXoV#`l)62qkujz+@n>dwJYX+XS` z^Do0{!P4QPfp=MVj@=rHjEK5Rh{~|gw{*vu_~5AS9vGJ-Sj+w!`QUZkB@alV7{6!+ zPU}u1MZ#C>?y*rhngEWL!%pB3F*YdS^hz~IXopBy895_F-0$iJU%WCDOgA?Wgr%jWl`QYc1!2``=jw_qQ8HlgfQYhGmbMS-v%1tzweu|vA2G`}Kn-6?n2oJe)?xdrRUz>FE7i5&l_cT!3_8OMP%efD@-TAl zvws6}7glZ*xPZZH3!z$EL2#-_AW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~2oa(S5hxT9 zNiWwGLpBsc8QW4sbk$IF%}{m6ea@V^Ys{s)7nF!*ICRf~a2=%Hgxekwr|w-4A}-wr z=+?^sJ-Q29gyoU-88gMJJoT`9bvudkZJ$3*#H<^O5&JS!$v%{w9g|pt__#o5Fe6MB zNnsMRnUAcGKk}>ksvbK`Z_Q-1l;RZq*`JRKi+I4l?E`cJ_D!B&aoG+VlS$w zs3wb7+h^ymgQ;(p{0`Lt{6KlUDRyeLq1g`O2g}qLP4O%X%bU$c*D);d0C<=_4v&Pr^dXq& zHxZ5@Jb~~q!f^oj$CIKw$t{nWil$5a0;Ytm=3~M=smZu=9cWW~F;WD8Yk7R1R$j{|~m}sBKuW>p>f=>5~XD0v>Jq#D6=! zF`dw7ri?y{`3rF=m_G&BkO(1bg8LHu*pK&D(+% None: - self.rect = pygame.Rect(pos, size) - self.font = pygame.font.SysFont("Arial", size[1]) - self.text_surf = self.font.render(text, False, text_color) - - self.color = bg_color - self.text = text - self.func = method - - self._text_pos = self.text_surf.get_rect(center=self.rect.center).topleft - - self._is_pressed = False - - def draw(self, surface: pygame.Surface) -> None: - """Draws the pygame.Rect and font""" - pygame.draw.rect(surface, self.color, self.rect) - surface.blit( - self.text_surf, - self._text_pos, - ) - - def handle_events(self, event: pygame.event.Event) -> None: - """Put this inside of your event loop""" - if event.type == pygame.MOUSEBUTTONDOWN: - if event.button == 1 and self.rect.collidepoint(event.pos): - self._is_pressed = True - else: - self._is_pressed = False - - elif event.type == pygame.MOUSEBUTTONUP: - if self._is_pressed and self.rect.collidepoint(event.pos): - self.func() - self._is_pressed = False \ No newline at end of file diff --git a/classes.py b/classes.py index 1c7673e..c19a4e5 100644 --- a/classes.py +++ b/classes.py @@ -2,11 +2,13 @@ import math import pygame import random +from typing import Tuple, Union + class plane: g = 9.8 - def __init__(self, size:tuple[int,int], skewX:int = 0, skewY:int = 0, contents:list = []) -> None: + def __init__(self, size:tuple[int,int], screen, skewX:int = 0, skewY:int = 0, contents:list = []) -> None: self.skewX = 0 self.skewY = 0 @@ -15,6 +17,9 @@ def __init__(self, size:tuple[int,int], skewX:int = 0, skewY:int = 0, contents:l self.forceY = 0 self.sizeX, self.sizeY = size[0]/10, size[1]/10 + self.screenW, self.screenH = pygame.display.Info().current_w, pygame.display.Info().current_h + self.screen = screen + self.contents = contents self.positions = [] @@ -33,19 +38,18 @@ def addAngle(self, x, y): self.skewX += y self.maxAngle() - def followMouse(self,screen): - w, h = pygame.display.Info().current_w, pygame.display.Info().current_h - unitX, unitY = (2*math.pi)/w, (2*math.pi)/w + def followMouse(self): + unitX, unitY = (2*math.pi)/self.screenW, (2*math.pi)/self.screenH - x = pygame.mouse.get_pos()[0] - w/2 - y = pygame.mouse.get_pos()[1] - h/2 + x = pygame.mouse.get_pos()[0] - self.screenW/2 + y = pygame.mouse.get_pos()[1] - self.screenH/2 self.setAngle(x * unitX, y * unitY) - def update(self, screen, deltaTime, force): + def update(self, deltaTime, force): for particle in self.contents: particle.updatePos(deltaTime, force) - particle.draw(screen) + particle.draw(self.screen) def force(self): self.forceX = plane.g * math.sin(self.skewX) @@ -53,14 +57,21 @@ def force(self): return (self.forceX, self.forceY) - def indicator(self,screen): + def indicator(self): w, h = pygame.display.Info().current_w, pygame.display.Info().current_h unitX, unitY = w/(2*math.pi), h/(2*math.pi) center = (round(w/2),round(h/2)) end_pos = (round( self.skewX * unitX + w/2 ), round( self.skewY * unitY + h/2 )) - pygame.draw.line(screen,(110,100,110), center, (end_pos)) + pygame.draw.line(self.screen,(110,100,110), center, (end_pos)) + + def drawGrid(self): + for i in range(0,self.screenW, 10): + pygame.draw.line(self.screen, (0,10,30), (i,0), (i,self.screenH)) + + for i in range(0,self.screenH, 10): + pygame.draw.line(self.screen, (0,10,30), (0, i), (self.screenW, i)) - def updateSize(self, screen): + def updateSize(self): self.sizeX, self.sizeY = pygame.display.Info().current_w/10 , pygame.display.Info().current_h/10 def clear(self): @@ -140,4 +151,48 @@ def updatePos(self, deltaTime, force): def draw(self,screen): x,y = self.pos() - pygame.draw.rect(screen, self.color,(x,y,10,10)) + pygame.draw.rect(screen, self.color,(x,y,10,10),5,2) + + +class Button: + def __init__( + self, + pos: Tuple[int, int], + size: Tuple[int, int], + text: str, + text_color: Union[str, Tuple[int, int, int]], + bg_color: Union[str, Tuple[int, int, int]], + method: callable = lambda: None, + ) -> None: + self.rect = pygame.Rect(pos, size) + self.font = pygame.font.SysFont("Arial", size[1]) + self.text_surf = self.font.render(text, False, text_color) + + self.color = bg_color + self.text = text + self.func = method + + self._text_pos = self.text_surf.get_rect(center=self.rect.center).topleft + + self._is_pressed = False + + def draw(self, surface: pygame.Surface) -> None: + """Draws the pygame.Rect and font""" + pygame.draw.rect(surface, self.color, self.rect) + surface.blit( + self.text_surf, + self._text_pos, + ) + + def handle_events(self, event: pygame.event.Event) -> None: + """Put this inside of your event loop""" + if event.type == pygame.MOUSEBUTTONDOWN: + if event.button == 1 and self.rect.collidepoint(event.pos): + self._is_pressed = True + else: + self._is_pressed = False + + elif event.type == pygame.MOUSEBUTTONUP: + if self._is_pressed and self.rect.collidepoint(event.pos): + self.func() + self._is_pressed = False diff --git a/main.py b/main.py index 79a125b..140a556 100644 --- a/main.py +++ b/main.py @@ -8,7 +8,6 @@ import time import pygame import asyncio -from button import Button try: import plyer @@ -24,9 +23,9 @@ previous_time = time.time() height, width = 700,700 screen = pygame.display.set_mode((width,height), flags= pygame.RESIZABLE) -surface = plane((width/10,height/10)) +surface = plane((width/10,height/10), screen=screen) -clear_button = Button((50,10),(20,50),"clear", (150,150,150), (10,10,10), surface.clear) +clear_button = Button((50,10),(80,40),"clear", (150,150,150), (5,10,30), surface.clear) @@ -52,12 +51,9 @@ async def main(): clear_button.handle_events(event) - clear_button.draw(screen) - if pygame.mouse.get_pressed()[0]: mX, mY = pygame.mouse.get_pos() - if dust.gridPos(mX/10, mY/10) not in surface.positions: - surface.contents.append(dust(surface, (mX/10, mY/10),mass = random.randint(10, 30)/10)) + surface.contents.append(dust(surface, (mX/10, mY/10),mass = random.randint(10, 30)/10)) #Loop variables deltaTime = time.time() - previous_time @@ -66,21 +62,21 @@ async def main(): if accel: force = (-1 * plyer.accelerometer.get_acceleration()[0], plyer.accelerometer.get_acceleration()[1]) else: - surface.followMouse(surface) + surface.followMouse() force = surface.force() + + clear_button.draw(screen) + surface.drawGrid() + surface.indicator() #Particle updates - surface.update(screen, deltaTime , force) - - - surface.indicator(screen) - + surface.update(deltaTime , force) pygame.display.set_caption(f"pixel-dust | trimpta | FPS: {clock.get_fps():.0f} | PC: {len(surface.contents)}") pygame.display.update() - screen.fill((0,0,0)) + screen.fill((5,1,20)) - surface.updateSize(screen) + surface.updateSize() await asyncio.sleep(0) From 57e2431689cfd959076a163189d13a358eb9e03b Mon Sep 17 00:00:00 2001 From: Trimpta <68428753+trimpta@users.noreply.github.com> Date: Fri, 16 Feb 2024 16:36:57 +0530 Subject: [PATCH 07/11] a --- requirements.txt | 1 - 1 file changed, 1 deletion(-) delete mode 100644 requirements.txt diff --git a/requirements.txt b/requirements.txt deleted file mode 100644 index 62621d5..0000000 --- a/requirements.txt +++ /dev/null @@ -1 +0,0 @@ -Plyer >= 2.1.0 From cd9c6b1c0e824b5e6f0ee638d8de98bc711075c6 Mon Sep 17 00:00:00 2001 From: Trimpta <68428753+trimpta@users.noreply.github.com> Date: Fri, 16 Feb 2024 16:37:07 +0530 Subject: [PATCH 08/11] um --- test.py | 43 ------------------------------------------- 1 file changed, 43 deletions(-) delete mode 100644 test.py diff --git a/test.py b/test.py deleted file mode 100644 index 60f5e2d..0000000 --- a/test.py +++ /dev/null @@ -1,43 +0,0 @@ -from classes import * -import time -import pygame -pygame.init() - -previous_time = time.time() -height, width = 500,500 -screen = pygame.display.set_mode((width,height)) - -surface = plane((width/10,height/10)) -surface.setAngle(0,90) - -particle1 = dust(surface, (15,15)) -particle2 = dust(surface, (14,12)) -particle3 = dust(surface, (10,10)) - -while True: - - # #Pygame events iteration - # for event in pygame.event.get(): - # if event.type == pygame.quit(): - # pygame.quit() - # break - - # if event.type == pygame.MOUSEWHEEL: - # if pygame.key.get_pressed[pygame.K_LSHIFT]: - # surface.addAngle(0,event.y) - # else: - # surface.addAngle(event.y, 0) - - #Loop variables - deltaTime = time.time() - previous_time - previous_time = time.time() - screen.fill((0,0,0)) - force = surface.force() - - #Particle updates - for particle in surface.contents: - particle.updatePos(deltaTime, force) - particle.draw(screen) - - pygame.display.update() - surface.positions = [] From f097c0b5310f94ce6bb67f55e3e657383e0a6e8e Mon Sep 17 00:00:00 2001 From: Trimpta <68428753+trimpta@users.noreply.github.com> Date: Sun, 18 Feb 2024 16:12:12 +0530 Subject: [PATCH 09/11] Phone fix F PC --- main.py | 13 ++++++++++--- 1 file changed, 10 insertions(+), 3 deletions(-) diff --git a/main.py b/main.py index 140a556..f5bf661 100644 --- a/main.py +++ b/main.py @@ -12,18 +12,25 @@ try: import plyer plyer.accelerometer.enable() - accel = True + accel = False + for _ in range(25): + if plyer.accelerometer.get_acceleration()[0] != plyer.accelerometer.get_acceleration()[1]: + accel = True + break + except Exception as e: accel = False +#F this i quit +accel = True pygame.init() clock = pygame.time.Clock() previous_time = time.time() height, width = 700,700 -screen = pygame.display.set_mode((width,height), flags= pygame.RESIZABLE) -surface = plane((width/10,height/10), screen=screen) +screen = pygame.display.set_mode((width,height), flags = pygame.RESIZABLE) +surface = plane((width/10,height/10), screen = screen) clear_button = Button((50,10),(80,40),"clear", (150,150,150), (5,10,30), surface.clear) From 7e2b6c207fba9ce2caccae38c47dca4be2cbc9db Mon Sep 17 00:00:00 2001 From: Trimpta <68428753+trimpta@users.noreply.github.com> Date: Mon, 27 Jan 2025 16:19:40 +0530 Subject: [PATCH 10/11] Update classes.py --- classes.py | 1 + 1 file changed, 1 insertion(+) diff --git a/classes.py b/classes.py index c19a4e5..52a5092 100644 --- a/classes.py +++ b/classes.py @@ -76,6 +76,7 @@ def updateSize(self): def clear(self): self.contents = [] + self.positions = [] dust.id = 0 class dust: From 987475aecd3de305efc451bece6872792531b805 Mon Sep 17 00:00:00 2001 From: Trimpta <68428753+trimpta@users.noreply.github.com> Date: Mon, 20 Jul 2026 12:20:50 +0530 Subject: [PATCH 11/11] feat: initialize project with uv and throttle dust particle generation in main.py --- .python-version | 1 + README.md | 0 main.py | 8 +++++--- pyproject.toml | 10 ++++++++++ uv.lock | 41 +++++++++++++++++++++++++++++++++++++++++ 5 files changed, 57 insertions(+), 3 deletions(-) create mode 100644 .python-version create mode 100644 README.md create mode 100644 pyproject.toml create mode 100644 uv.lock diff --git a/.python-version b/.python-version new file mode 100644 index 0000000..6324d40 --- /dev/null +++ b/.python-version @@ -0,0 +1 @@ +3.14 diff --git a/README.md b/README.md new file mode 100644 index 0000000..e69de29 diff --git a/main.py b/main.py index f5bf661..465258c 100644 --- a/main.py +++ b/main.py @@ -38,7 +38,7 @@ pygame.mouse.set_pos((height/2, width/2)) - +last_touched = time.time() async def main(): global accel, previous_time @@ -59,8 +59,10 @@ async def main(): clear_button.handle_events(event) if pygame.mouse.get_pressed()[0]: - mX, mY = pygame.mouse.get_pos() - surface.contents.append(dust(surface, (mX/10, mY/10),mass = random.randint(10, 30)/10)) + if time.time() - last_touched >= 0.03: + mX, mY = pygame.mouse.get_pos() + surface.contents.append(dust(surface, (mX/10, mY/10),mass = random.randint(10, 30)/10)) + last_touched = time.time() #Loop variables deltaTime = time.time() - previous_time diff --git a/pyproject.toml b/pyproject.toml new file mode 100644 index 0000000..d5c8b31 --- /dev/null +++ b/pyproject.toml @@ -0,0 +1,10 @@ +[project] +name = "pixel-dust" +version = "0.1.0" +description = "Add your description here" +readme = "README.md" +requires-python = ">=3.14" +dependencies = [ + "plyer>=2.1.0", + "pygame-ce>=2.5.7", +] diff --git a/uv.lock b/uv.lock new file mode 100644 index 0000000..ee07a87 --- /dev/null +++ b/uv.lock @@ -0,0 +1,41 @@ +version = 1 +revision = 3 +requires-python = ">=3.14" + +[[package]] +name = "pixel-dust" +version = "0.1.0" +source = { virtual = "." } +dependencies = [ + { name = "plyer" }, + { name = "pygame-ce" }, +] + +[package.metadata] +requires-dist = [ + { name = "plyer", specifier = ">=2.1.0" }, + { name = "pygame-ce", specifier = ">=2.5.7" }, +] + +[[package]] +name = "plyer" +version = "2.1.0" +source = { registry = "https://pypi.org/simple" } +sdist = { url = "https://files.pythonhosted.org/packages/20/85/f61425aa9be1f9108eec1c13861c1e11c9a04eb786eb4832a8f7188317df/plyer-2.1.0.tar.gz", hash = "sha256:65b7dfb7e11e07af37a8487eb2aa69524276ef70dad500b07228ce64736baa61", size = 121371, upload-time = "2022-11-12T13:36:48.978Z" } +wheels = [ + { url = "https://files.pythonhosted.org/packages/d3/89/a41c2643fc8eabeb84791acb9d0e4d139b1e4b53473cc4dae947b5fa33ed/plyer-2.1.0-py2.py3-none-any.whl", hash = "sha256:1b1772060df8b3045ed4f08231690ec8f7de30f5a004aa1724665a9074eed113", size = 142266, upload-time = "2022-11-12T13:36:47.181Z" }, +] + +[[package]] +name = "pygame-ce" +version = "2.5.7" +source = { registry = "https://pypi.org/simple" } +sdist = { url = "https://files.pythonhosted.org/packages/e9/0d/bb6a6fdf1b227c0bb9a44437a70962a3854bcc541533c261e5021a5ee691/pygame_ce-2.5.7.tar.gz", hash = "sha256:86beb797cd73c141299a29b56f7df2b0543fbdc81d428022458329ff694aaa51", size = 5935870, upload-time = "2026-03-02T09:26:59.005Z" } +wheels = [ + { url = "https://files.pythonhosted.org/packages/26/08/9fe0003d69077ff8faff242a85260b8a192d3b7111c02332b8b2f515d40c/pygame_ce-2.5.7-cp314-cp314-macosx_10_15_universal2.whl", hash = "sha256:addfbf7d119647eec157d611f463e5d572836fa74d0d222c59210294ed618b9d", size = 17211017, upload-time = "2026-03-02T09:26:30.243Z" }, + { url = "https://files.pythonhosted.org/packages/40/c7/217c5430c8c612879162beb2d18cb10ad8b1b4db6ce03245289a3de6bc1b/pygame_ce-2.5.7-cp314-cp314-manylinux2014_aarch64.manylinux_2_17_aarch64.whl", hash = "sha256:1c92feb289e34ac323a7b62b91d230a4e32b44059c4d7fb95631e504b1d9b365", size = 12710845, upload-time = "2026-03-02T09:26:33.165Z" }, + { url = "https://files.pythonhosted.org/packages/00/a4/6fb0054bfb2522c4ad3ff82ecbc9c1a3c6694c50d24f2451717121636a1d/pygame_ce-2.5.7-cp314-cp314-manylinux2014_x86_64.manylinux_2_17_x86_64.whl", hash = "sha256:5c1ed4100311015cc67d24fe4e4d7c2f4cb25c34e043545061271c1d018c02d4", size = 12812020, upload-time = "2026-03-02T09:26:35.953Z" }, + { url = "https://files.pythonhosted.org/packages/a2/9b/0e0996573a9dd4bb34874c10643224a72372818242e07486c9eb4a22eebb/pygame_ce-2.5.7-cp314-cp314-win32.whl", hash = "sha256:1b7e641af3aeac92bb7e4df1402d6802271f4bd09c747d2665f154ef9b07a4e6", size = 9968590, upload-time = "2026-03-02T09:26:38.517Z" }, + { url = "https://files.pythonhosted.org/packages/96/96/c94d0e508954093e37a77b03101a3cf51a242e02cc0ec726edcb117f8885/pygame_ce-2.5.7-cp314-cp314-win_amd64.whl", hash = "sha256:595f4257c15fed11cd816ae0bfabad3d99f8f04a000d7d164a22c0f9afd6cb65", size = 10581240, upload-time = "2026-03-02T09:26:41.139Z" }, + { url = "https://files.pythonhosted.org/packages/81/bb/93c5dadb66ac9733ca52952e063cce117a9312d6f97facd5dc4932f3d777/pygame_ce-2.5.7-cp314-cp314-win_arm64.whl", hash = "sha256:3e6ce74fd5a5f146f1bcf0224ae3e880c733917a9edbb53f790329d235520433", size = 11057480, upload-time = "2026-03-02T09:26:43.871Z" }, +]