Ejemplo n.º 1
0
 def testParticleIsColocated(self):
     p = PiltonParticle(1, 2, 3)
     others = {
         PiltonParticle(1, 2, 5): True,
         PiltonParticle(2, 2, 3): False
     }
     for o in others:
         msg = "p={0} o={1} expect={2}".format(p, o, others[o])
         self.assertEqual(p.is_colocated(o), others[o], msg)
Ejemplo n.º 2
0
 def testParticleImmutability(self):
     p = PiltonParticle(1, 2, 3)
     with self.assertRaises(AttributeError):
         p.x = 4
     with self.assertRaises(AttributeError):
         p.y = 4
     with self.assertRaises(AttributeError):
         p.mass = 4
     with self.assertRaises(AttributeError):
         p.location = (1, 2)
Ejemplo n.º 3
0
def makeParticles(*tuples, mass=None):
    if mass:
        return [PiltonParticle(l[0], l[1], mass) for l in tuples]
    else:
        return [PiltonParticle(p[0], p[1], p[2]) for p in tuples]
Ejemplo n.º 4
0
 def testParticleLocation(self):
     p1 = PiltonParticle(1, 2, 3)
     p2 = PiltonParticle(2, 1, 3)
     p3 = PiltonParticle(1, 2, 4)
     self.assertTrue(p1.location != p2.location, "different locations")
     self.assertTrue(p1.location == p3.location, "same location")
Ejemplo n.º 5
0
 def testParticleEquality(self):
     p = PiltonParticle(1, 2, 3)
     self.assertEqual(p, PiltonParticle(1, 2, 3), "equal")
     self.assertNotEqual(p, PiltonParticle(4, 2, 3), "x differs")
     self.assertNotEqual(p, PiltonParticle(1, 4, 3), "y differs")
     self.assertNotEqual(p, PiltonParticle(1, 2, 4), "mass differs")
Ejemplo n.º 6
0
 def testParticleProperties(self):
     p = PiltonParticle(1, 2, 3)
     self.assertEqual(p.x, 1, "x")
     self.assertEqual(p.y, 2, "y")
     self.assertEqual(p.mass, 3, "mass")
Ejemplo n.º 7
0
from tkinter import StringVar
from tkinter import BooleanVar
from tkinter import Text
from PiltonWorld import PiltonParticle
from PiltonWorld import PiltonWorldState

# ----- Core dimensions
_cols = 7
_rows = 7
_cell_width_pixels = 35  # cells are square, so height == width
_grid_width_pixels = _cols * _cell_width_pixels + 1
_grid_height_pixels = _rows * _cell_width_pixels + 1

# ----- Model

starting_particles = [PiltonParticle(3, 2, 1)]

ps = PiltonWorldState(_cols, _rows)
ps.particles = starting_particles

# ----- Controller

status_prefix = "World {0}x{1}".format(_cols, _rows)


def particles_text(ps):
    return str([str(p) for p in ps.particles]).replace("'", "")


def update_display():
    textcanvas.delete('all')