initial commit
This commit is contained in:
commit
39f56a3b10
83 files changed
+3583
No files matched your search
@@ -0,0 +1,41 @@
|
||||
import random
|
||||
|
||||
import pygame
|
||||
|
||||
from my_package.Game_class import Game
|
||||
from my_package.Spark_class import Spark
|
||||
|
||||
|
||||
class PiDraw(Game):
|
||||
def __init__(self, inner_c=None, outer_c=None):
|
||||
self.inner_c = inner_c if inner_c is not None else []
|
||||
self.outer_c = outer_c if outer_c is not None else []
|
||||
super().__init__()
|
||||
|
||||
def update_game(self):
|
||||
for _ in range(2):
|
||||
x = random.randint(0,500)
|
||||
y = random.randint(0,500)
|
||||
|
||||
if (x**2 + y**2) < 500**2: self.inner_c.append(Spark(x, y, (0,255,0), 1))
|
||||
else: self.outer_c.append(Spark(x, y, (255,0,0), 1))
|
||||
|
||||
try:
|
||||
pi = 4.0 * len(self.inner_c) / (len(self.inner_c) + len(self.outer_c))
|
||||
print(pi)
|
||||
except ZeroDivisionError: print("ZeroDivisionError")
|
||||
|
||||
return True
|
||||
|
||||
def draw_game(self):
|
||||
for particle in self.inner_c + self.outer_c:
|
||||
particle.set_surface(self.set_screen())
|
||||
particle.appear(self.set_screen())
|
||||
pygame.display.flip()
|
||||
|
||||
|
||||
def main():
|
||||
game = PiDraw()
|
||||
game.run()
|
||||
|
||||
main()
|
||||
Reference in new issue
Block a user