def test_solid_disc_intersect(self): from lepton.domain import Disc from lepton.particle_struct import Vec3 normal = Vec3(1, 1, 0).normalize() disc = Disc((-2, 0, 1), normal, 1) lines = [ ((-5, 0, 0), (5, 0, 0)), ((-2, 1, 1), (-2, -1, 1)), ((3, normal.y, 1), (-3, normal.y, 1)), ] expected = [ ((-2, 0, 0), -normal), ((-2, 0, 1), normal), ((-2 - normal.x, normal.y, 1), normal), ] for (start, end), (point, normal) in zip(lines, expected): p, N = disc.intersect(start, end) self.assertVector(p, point) self.assertVector(N, normal) # Reverse direction should yield same point and inverse normal p, N = disc.intersect(end, start) self.assertVector(p, point) self.assertVector(N, -Vec3(*normal))
def test_solid_disc_no_intersect(self): from lepton.domain import Disc disc = Disc((0, 0, 0), (1, 0, 0), 1) for start, end in [((1, 0, 0), (2, 0, 0)), ((0, 0, 0), (0, 1, 0)), ((-2, 10, 20), (-5, 15, 19))]: self.assertEqual(disc.intersect(start, end), (None, None)) self.assertEqual(disc.intersect(end, start), (None, None))
def test_hollow_disc_intersect(self): from lepton.domain import Disc from lepton.particle_struct import Vec3 disc = Disc((2,2,2), (0,1,0), 3, 1) lines = [ ((-1, 3, 2), (-1, 0, 2)), ((1, 3, 0), (1, 0, 0)), ((2, 5, 4), (2, -5, 4)), ((3, 1, 2), (5, 3, 2)), ] expected = [ ((-1, 2, 2), (0,1,0)), ((1, 2, 0), (0,1,0)), ((2, 2, 4), (0,1,0)), ((4, 2, 2), (0,-1,0)), ] for (start, end), (point, normal) in zip(lines, expected): p, N = disc.intersect(start, end) self.assertVector(p, point) self.assertVector(N, normal) # Reverse direction should yield same point and inverse normal p, N = disc.intersect(end, start) self.assertVector(p, point) self.assertVector(N, -Vec3(*normal))
def test_hollow_disc_intersect(self): from lepton.domain import Disc from lepton.particle_struct import Vec3 disc = Disc((2, 2, 2), (0, 1, 0), 3, 1) lines = [ ((-1, 3, 2), (-1, 0, 2)), ((1, 3, 0), (1, 0, 0)), ((2, 5, 4), (2, -5, 4)), ((3, 1, 2), (5, 3, 2)), ] expected = [ ((-1, 2, 2), (0, 1, 0)), ((1, 2, 0), (0, 1, 0)), ((2, 2, 4), (0, 1, 0)), ((4, 2, 2), (0, -1, 0)), ] for (start, end), (point, normal) in zip(lines, expected): p, N = disc.intersect(start, end) self.assertVector(p, point) self.assertVector(N, normal) # Reverse direction should yield same point and inverse normal p, N = disc.intersect(end, start) self.assertVector(p, point) self.assertVector(N, -Vec3(*normal))
def test_hollow_disc_no_intersect(self): from lepton.domain import Disc disc = Disc((2, 2, 2), (0, 1, 0), 3, 1) for start, end in [((2, 3, 2.5), (2, 0, 1.5)), ((2, 2, 2), (5, 2, 2)), ((-2, 10, 20), (-5, 15, 19))]: self.assertEqual(disc.intersect(start, end), (None, None)) self.assertEqual(disc.intersect(end, start), (None, None))
def test_shell_disc_generate_contains(self): from lepton.domain import Disc disc = Disc((-2, 0, 1), (1, 1, 0), 2, 2) for i in range(20): x, y, z = disc.generate() mag = (x + 2)**2 + y**2 + (z - 1)**2 self.assertAlmostEqual(mag, 4.0, 4) self.failUnless((x, y, z) in disc, (x, y ,z))
def test_shell_disc_generate_contains(self): from lepton.domain import Disc disc = Disc((-2, 0, 1), (1, 1, 0), 2, 2) for i in range(20): x, y, z = disc.generate() mag = (x + 2)**2 + y**2 + (z - 1)**2 self.assertAlmostEqual(mag, 4.0, 4) self.failUnless((x, y, z) in disc, (x, y, z))
def test_solid_disc_closest_pt_to_on_axis(self): from lepton.domain import Disc disc = Disc((0, 3, 0), (0, 1, 0), 3) for point, closest, normal in [ ((0, 4, 0), (0, 3, 0), (0, 1, 0)), ((0, 3, 0), (0, 3, 0), (0, 0, 0)), ((0, 2, 0), (0, 3, 0), (0, -1, 0)), ]: p, N = disc.closest_point_to(point) self.assertVector(p, closest) self.assertVector(N, normal)
def test_hollow_disc_no_intersect(self): from lepton.domain import Disc disc = Disc((2,2,2), (0,1,0), 3, 1) for start, end in [ ((2, 3, 2.5), (2, 0, 1.5)), ((2, 2, 2), (5, 2, 2)), ((-2, 10, 20), (-5, 15, 19))]: self.assertEqual( disc.intersect(start, end), (None, None)) self.assertEqual( disc.intersect(end, start), (None, None))
def test_solid_disc_no_intersect(self): from lepton.domain import Disc disc = Disc((0, 0, 0), (1, 0, 0), 1) for start, end in [ ((1, 0, 0), (2, 0, 0)), ((0, 0, 0), (0, 1, 0)), ((-2, 10, 20), (-5, 15, 19))]: self.assertEqual( disc.intersect(start, end), (None, None)) self.assertEqual( disc.intersect(end, start), (None, None))
def test_solid_disc_generate_contains(self): from lepton.domain import Disc disc = Disc((0, 1, 2), (0, 0, 1), 2) for i in range(20): x, y, z = disc.generate() mag = x**2 + (y - 1)**2 + (z - 2)**2 self.failUnless(mag <= 4, ((x, y, z), mag)) self.failUnless((x, y, z) in disc, (x, y, z)) self.failUnless((0, 1, 2) in disc) self.failUnless((1, 2, 2) in disc) self.failUnless((2, 1, 2) in disc) self.failUnless((-2, 1, 2) in disc) self.failIf((2.1, 1, 2) in disc) self.failIf((-2.1, 1, 2) in disc) self.failIf((0, 1, 2.1) in disc)
def test_solid_disc_generate_contains(self): from lepton.domain import Disc disc = Disc((0, 1, 2), (0, 0, 1), 2) for i in range(20): x, y, z = disc.generate() mag = x**2 + (y - 1)**2 + (z - 2)**2 self.failUnless(mag <= 4, ((x, y, z), mag)) self.failUnless((x, y, z) in disc, (x, y ,z)) self.failUnless((0, 1, 2) in disc) self.failUnless((1, 2, 2) in disc) self.failUnless((2, 1, 2) in disc) self.failUnless((-2, 1, 2) in disc) self.failIf((2.1, 1, 2) in disc) self.failIf((-2.1, 1, 2) in disc) self.failIf((0, 1, 2.1) in disc)
def __init__(self, x, y, direction): self.x, self.y = (x, y) self.direction = direction if direction < 0: self.speed = -800 else: self.speed = 800 self.emitter = emitter.StaticEmitter( rate=300, template=Particle( position=(x, y, 0), velocity=(0, 0, 0), color=(1, 1, 0, 0.5), size=(8, 8, 0), # rotation? # up? ), velocity=Disc((0,0,0), (0,0,1), 200), time_to_live=self.duration, ) self.fader = controller.Fader(start_alpha=1,fade_out_start=0,fade_out_end=.5,end_alpha=0) self.group = ParticleGroup( controllers=[ self.emitter, controller.Gravity((0, -100, 0)), controller.Movement(), self.fader, controller.Lifetime(1), ], renderer=Render('zap-star.png'), ) self.emitter.emit(1, self.group)
def test_disc_closest_pt_to(self): from lepton.domain import Disc from lepton.particle_struct import Vec3 disc = Disc((-3, 1, 2), (0, 1, 1), 4, 1) for point, closest, normal in [ ((-2, 1, 2), (-2, 1, 2), (0, 0, 0)), ((-2, 2, 2), (-2, 1.5, 1.5), Vec3(0, 1, 1).normalize()), ((-2, -1, 2), (-2, 0, 3), Vec3(0, -1, -1).normalize()), ((-3, 5, 8), (-3, 0, 3), Vec3(0, 1, 1).normalize()), ((-3, 1, 2), (-3, 1, 2), (0, 0, 0)), ((-3, 3, 4), (-3, 1, 2), (0, 0, 0)), ((-3, 0, 1), (-3, 1, 2), (0, 0, 0)), ]: p, N = disc.closest_point_to(point) self.assertVector(p, closest) self.assertVector(N, normal)
def test_hollow_disc_generate_contains(self): from lepton.domain import Disc disc = Disc((0, 1, 2), (0, 1, 0), 2, 1) self.assertEqual(tuple(disc.center), (0, 1, 2)) self.assertEqual(tuple(disc.normal), (0, 1, 0)) self.assertEqual(disc.inner_radius, 1) self.assertEqual(disc.outer_radius, 2) for i in range(20): x, y, z = disc.generate() mag = x**2 + (y - 1)**2 + (z - 2)**2 self.failUnless(1 <= mag <= 4, ((x, y, z), mag)) self.failUnless((x, y, z) in disc, (x, y ,z)) self.failIf((0, 1, 2) in disc) self.failIf((0, 0, 2) in disc) self.failUnless((1, 1, 3) in disc) self.failUnless((2, 1, 2) in disc) self.failUnless((-2, 1, 2) in disc) self.failIf((2.1, 1, 2) in disc) self.failIf((-2.1, 1, 2) in disc) self.failIf((0, 1.2, 2) in disc)
def test_hollow_disc_generate_contains(self): from lepton.domain import Disc disc = Disc((0, 1, 2), (0, 1, 0), 2, 1) self.assertEqual(tuple(disc.center), (0, 1, 2)) self.assertEqual(tuple(disc.normal), (0, 1, 0)) self.assertEqual(disc.inner_radius, 1) self.assertEqual(disc.outer_radius, 2) for i in range(20): x, y, z = disc.generate() mag = x**2 + (y - 1)**2 + (z - 2)**2 self.failUnless(1 <= mag <= 4, ((x, y, z), mag)) self.failUnless((x, y, z) in disc, (x, y, z)) self.failIf((0, 1, 2) in disc) self.failIf((0, 0, 2) in disc) self.failUnless((1, 1, 3) in disc) self.failUnless((2, 1, 2) in disc) self.failUnless((-2, 1, 2) in disc) self.failIf((2.1, 1, 2) in disc) self.failIf((-2.1, 1, 2) in disc) self.failIf((0, 1.2, 2) in disc)
def __init__(self, x, y, size): self.emitter = emitter.StaticEmitter( template = Particle( position=(x, y, 0), color=(1, 1, 1, .01), velocity=(0, 0, 0), size=(64, 64, 0), ), velocity=Disc((0,0,0), (0,0,1), 400), ) self.group = ParticleGroup( controllers=[ self.emitter, controller.Growth(50), controller.Movement(), controller.Fader(start_alpha=1,fade_out_start=0,fade_out_end=.7,end_alpha=0), controller.Lifetime(.7), ], renderer = Render('point64.png'), ) self.emitter.emit(50, self.group)
def __init__(self, rect, scale=1): x, y = rect.center self.emitter = emitter.StaticEmitter( rate = 20, template = Particle( position=(x, y, 0), color=(1, 1, 1, .5), velocity=(0, 0, 0), size=(8, 8, 0), ), velocity=Disc((0,0,0), (0,0,1), rect.width*.75*scale), ) self.group = ParticleGroup( controllers=[ self.emitter, controller.Movement(), controller.Clumper(50), controller.Fader(start_alpha=1,fade_out_start=0,fade_out_end=1,end_alpha=0), controller.Lifetime(1), ], renderer = Render(self.filename), ) self.emitter.emit(1, self.group)
glLoadIdentity() win.on_resize = on_resize glEnable(GL_BLEND) glShadeModel(GL_SMOOTH) glBlendFunc(GL_SRC_ALPHA, GL_ONE) glHint(GL_PERSPECTIVE_CORRECTION_HINT, GL_NICEST) glDisable(GL_DEPTH_TEST) texture = image.load(os.path.join(os.path.dirname(__file__), 'flare3.png')).get_texture() texturizer = SpriteTexturizer(texture.id) source = Disc((0, -30, 0), (0, 1, 0), 2, 2) dust_emitter = StaticEmitter(rate=40, template=Particle( velocity=(0, 0, 0), mass=1.0, color=(1, 1, 1, 0.25), ), position=source, deviation=Particle(velocity=(20, 0, 20), color=(0.0, 1.0, 1.0), age=0.5)) vortex = Cone((0, -30, 0), (0, 28, 0), 16, 0) front = AABox((-100, -50, -50), (100, 25, 0)) back = AABox((-100, -50, 50), (100, 25, 0))
Movement(min_velocity=10), Lifetime(electron_lifetime * 1.5), Magnet(nucleus, charge=15000.0), Magnet(nucleus, charge=-15000.0, exponent=3), Fader(fade_in_end=1, fade_out_start=electron_lifetime * 1.4, fade_out_end=electron_lifetime * 1.5), ]) electron_emitter = StaticEmitter( template=Particle( position=(-20, 0, 0), size=(25, 25, 25), color=(0.1, 0.1, 1.0), ), velocity=Disc((0, 0, 0), (-1, 0, 0), 36, 36), ) # Trails for electrons trail_emitter = PerParticleEmitter( electrons, rate=80, template=Particle(color=(1, 0, 0, 1), size=(4.25, 4.25, 0)), deviation=Particle(up=(0, 0, math.pi), rotation=(0, 0, math.pi), size=(0.5, 0.5, 0), velocity=(1, 1, 1), color=(0, 1, 0), age=trail_lifetime / 2.0), )