
Other times the small block just gets stuck to the big block which also should not happen. Sometimes the smaller block just gets stuck in the middle of the line until the big block crashes into it.
#Frame duplicate detector code#
(screen, "WHITE",, ) # draw floorĭue to dt being different every time, however, the code just fails to work every time. If small_block.has_collided(big_block): #check if 2 blocks collided and change velocities appropriately Small_block.change_velocity(-small_block.get_velocity()) If small_block.center() - small_block.get_dim() / 2 <= 200: # check if block has collided with line <= other_block.center() + other_block.get_dim() / 2ĭef mass_two_final_velocity(m1, m2, v1, v2): #equation for mass two final velocity in elastic collisionĭef mass_one_final_velocity(m1, m2, v1, v2): #equation for mass one final velocity in elastic collision >= other_block.center() - other_block.get_dim() / 2 Return (self.x + self.dim / 2 - self.dim, self.y + self.dim / 2 - self.dim) # get center of block relative to where it is drawn on screen Screen.blit(self.img, (self.x - self.dim, self.y - self.dim)) _caption("Collision Pi Simulation")ĭef _init_(self, mass, x, y, dim, color, initial_velocity): The way the simulation works is that 2 blocks are generated on a horizontal line alongside a wall, and the bigger block (which starts at the right) is set in motion and the simulation unfolds using equations to find the final velocity after elastic collisions for both blocks and reversing velocity if the block collides into a wall. I saw a video by 3blue1brown on calculating pi using just colliding blocks so I tried to implement my own version of this.
