Пример #1
0
	def test_AABox_intersect(self):
		from lepton.domain import AABox
		from lepton.particle_struct import Vec3
		box = AABox((-3, -1, 0), (-2, 1, 3))
		lines = [
			((-4, 0, 1), (-2, 0, 1)),
			((-2.5, -2, 2), (-2.5, -0.5, 2)),
			((-2.8, 0.5, -1), (-2.8, 0.5, 1)),
			((-1, 0, 1), (-2, 0, 1)),
			((-2.5, 2, 2), (-2.5, 1, 2)),
			((-2.8, 0.5, 4), (-2.8, 0.5, 1)),
		]
		expected = [
			((-3, 0, 1), (-1, 0, 0)),
			((-2.5, -1, 2), (0, -1, 0)),
			((-2.8, 0.5, 0), (0, 0, -1)),
			((-2, 0, 1), (1, 0, 0)),
			((-2.5, 1, 2), (0, 1, 0)),
			((-2.8, 0.5, 3), (0, 0, 1)),
		]
		for (start, end), (point, normal) in zip(lines, expected):
			p, N = box.intersect(start, end)
			self.failUnless(start not in box)
			self.failUnless(end in box)
			self.assertVector(p, point)
			self.assertVector(N, normal)

			# Reverse direction should yield same point and inverse normal
			p, N = box.intersect(end, start)
			self.assertVector(p, point)
			self.assertVector(N, -Vec3(*normal))
Пример #2
0
    def test_AABox_intersect(self):
        from lepton.domain import AABox
        from lepton.particle_struct import Vec3
        box = AABox((-3, -1, 0), (-2, 1, 3))
        lines = [
            ((-4, 0, 1), (-2, 0, 1)),
            ((-2.5, -2, 2), (-2.5, -0.5, 2)),
            ((-2.8, 0.5, -1), (-2.8, 0.5, 1)),
            ((-1, 0, 1), (-2, 0, 1)),
            ((-2.5, 2, 2), (-2.5, 1, 2)),
            ((-2.8, 0.5, 4), (-2.8, 0.5, 1)),
        ]
        expected = [
            ((-3, 0, 1), (-1, 0, 0)),
            ((-2.5, -1, 2), (0, -1, 0)),
            ((-2.8, 0.5, 0), (0, 0, -1)),
            ((-2, 0, 1), (1, 0, 0)),
            ((-2.5, 1, 2), (0, 1, 0)),
            ((-2.8, 0.5, 3), (0, 0, 1)),
        ]
        for (start, end), (point, normal) in zip(lines, expected):
            p, N = box.intersect(start, end)
            self.failUnless(start not in box)
            self.failUnless(end in box)
            self.assertVector(p, point)
            self.assertVector(N, normal)

            # Reverse direction should yield same point and inverse normal
            p, N = box.intersect(end, start)
            self.assertVector(p, point)
            self.assertVector(N, -Vec3(*normal))
Пример #3
0
    def test_AABox_no_intersect(self):
        from lepton.domain import AABox
        box = AABox((-3, -1, 0), (-2, 1, 3))

        # No intersection
        self.assertEqual(box.intersect((-4, 2, 1), (-2, 2, 1)), (None, None))
        self.assertEqual(box.intersect((-2, 0, 1), (-2.8, 0.5, 1)),
                         (None, None))
Пример #4
0
 def test_AABox_grazing_intersect(self):
     from lepton.domain import AABox
     box = AABox((-3, -1, 0), (-2, 1, 3))
     p, N = box.intersect((-4, 0, 1), (0, 0, 1))
     self.assertEqual(p, (-3, 0, 1))
     self.assertEqual(N, (-1, 0, 0))
     p, N = box.intersect((0, 0, 1), (-4, 0, 1))
     self.assertEqual(p, (-2, 0, 1))
     self.assertEqual(N, (1, 0, 0))
Пример #5
0
	def test_AABox_no_intersect(self):
		from lepton.domain import AABox
		box = AABox((-3, -1, 0), (-2, 1, 3))
	
		# No intersection
		self.assertEqual(
			box.intersect((-4, 2, 1), (-2, 2, 1)), (None, None))
		self.assertEqual(
			box.intersect((-2, 0, 1), (-2.8, 0.5, 1)), (None, None))
Пример #6
0
	def test_AABox_grazing_intersect(self):
		from lepton.domain import AABox
		box = AABox((-3, -1, 0), (-2, 1, 3))
		p, N = box.intersect((-4, 0, 1), (0, 0, 1))
		self.assertEqual(p, (-3, 0, 1))
		self.assertEqual(N, (-1, 0, 0))
		p, N = box.intersect((0, 0, 1), (-4, 0, 1))
		self.assertEqual(p, (-2, 0, 1))
		self.assertEqual(N, (1, 0, 0))
Пример #7
0
    def test_AABox_line_in_sides(self):
        from lepton.domain import AABox
        box = AABox((-3, -1, 0), (-2, 1, 3))

        # Lines completely in sides
        lines = [
            ((-3, 0, 1), (-3, 0.5, 2)),
            ((-2.5, -1, 2), (-2, -1, 2)),
            ((-2.8, 0.5, 0), (-2.5, 0.5, 0)),
            ((-2, 0, 1), (-2, 0.5, 2)),
            ((-2.5, 1, 2), (-2.5, 1, 1)),
            ((-2.8, 0.5, 3), (-2.9, 0.5, 3)),
        ]
        for start, end in lines:
            self.assertEqual(box.intersect(start, end), (None, None))
Пример #8
0
 def test_AABox_generate_contains(self):
     from lepton.domain import AABox
     box = AABox((-3, -1, 0), (-2, 1, 3))
     for i in range(20):
         x, y, z = box.generate()
         self.failUnless(-3 <= x <= -2, x)
         self.failUnless(-1 <= y <= 1, y)
         self.failUnless(0 <= z <= 3, z)
         self.failUnless((x, y, z) in box, (x, y, z))
     self.failUnless((-3, -1, 0) in box)
     self.failUnless((-3, 1, 0) in box)
     self.failUnless((-2, 1, 3) in box)
     self.failUnless((-2, -1, 0) in box)
     self.failUnless((-2.5, 0, 0) in box)
     self.failIf((-3, -3, -3) in box)
     self.failIf((-3, 2, 3) in box)
Пример #9
0
	def test_AABox_line_in_sides(self):
		from lepton.domain import AABox
		box = AABox((-3, -1, 0), (-2, 1, 3))

		# Lines completely in sides
		lines = [
			((-3, 0, 1), (-3, 0.5, 2)),
			((-2.5, -1, 2), (-2, -1, 2)),
			((-2.8, 0.5, 0), (-2.5, 0.5, 0)),
			((-2, 0, 1), (-2, 0.5, 2)),
			((-2.5, 1, 2), (-2.5, 1, 1)),
			((-2.8, 0.5, 3), (-2.9, 0.5, 3)),
		]
		for start, end in lines:
			self.assertEqual(
				box.intersect(start, end), (None, None))
Пример #10
0
	def test_AABox_generate_contains(self):
		from lepton.domain import AABox
		box = AABox((-3, -1, 0), (-2, 1, 3))
		for i in range(20):
			x, y, z = box.generate()
			self.failUnless(-3 <= x <= -2, x)
			self.failUnless(-1 <= y <= 1, y)
			self.failUnless(0 <= z <= 3, z)
			self.failUnless((x, y, z) in box, (x, y, z))
		self.failUnless((-3, -1, 0) in box)
		self.failUnless((-3, 1, 0) in box)
		self.failUnless((-2, 1, 3) in box)
		self.failUnless((-2, -1, 0) in box)
		self.failUnless((-2.5, 0, 0) in box)
		self.failIf((-3,-3,-3) in box)
		self.failIf((-3,2,3) in box)
Пример #11
0
 def __init__(self, x1, y1, x2, y2):
     self.emitter = emitter.StaticEmitter(
         rate = (x2-x1) // 5,
         template = Particle(
             position=(x1, y1, 0),
             color=(1, 1, 1, .5),
             velocity=(0, 0, 0),
             size=(32, 32, 0),
         ),
         position=Line((x1, y1, 0), (x2, y1, 0)),
         velocity=AABox((-100, -50, 0), (100, -200, 1)),
     )
     self.group = ParticleGroup(
         controllers=[
             self.emitter,
             controller.Movement(),
             controller.Growth(100),
             controller.Gravity((0, -50, 0)),
             controller.Fader(start_alpha=1,fade_out_start=0,fade_out_end=1,end_alpha=0),
             controller.Lifetime(2),
         ],
         renderer = Render('black-bubble.png'),
     )
     self.emitter.emit(1, self.group)
Пример #12
0
    glShadeModel(GL_SMOOTH)  # Enables Smooth Shading
    glBlendFunc(GL_SRC_ALPHA, GL_ONE)  #Type Of Blending To Perform
    glHint(GL_PERSPECTIVE_CORRECTION_HINT, GL_NICEST)
    #Really Nice Perspective Calculations
    glHint(GL_POINT_SMOOTH_HINT, GL_NICEST)
    #Really Nice Point Smoothing
    glDisable(GL_DEPTH_TEST)


ball_count = 100
ball_size = 15
bumper_count = 8

# Screen domain is a box the size of the screen
screen_domain = AABox(
    (ball_size / 2.0, ball_size / 2.0, 0),
    (win.width - ball_size / 2.0, win.height - ball_size / 2.0, 0))

bumpers = []
for i in range(bumper_count):
    bumper = Bumper(
        (win.width / (bumper_count - 1) * i, win.height * 2.0 / 3.0 -
         (i % 2) * win.height / 3, 0), win.height / 15)
    bumpers.append(bumper)

up_fan = AABox((win.width / 2 - win.width / 12, 0, -1),
               (win.width / 2 + win.width / 12, win.height * 0.8, 1))
left_fan = AABox((win.width / 2 - win.width / 12, win.height * 0.8, -1),
                 (win.width / 2, win.height, 1))
right_fan = AABox((win.width / 2, win.height * 0.8, -1),
                  (win.width / 2 + win.width / 12, win.height, 1))
Пример #13
0
win.on_resize = on_resize

glEnable(GL_BLEND)
glShadeModel(GL_SMOOTH)
glBlendFunc(GL_SRC_ALPHA,GL_ONE)
glDisable(GL_DEPTH_TEST)

emitter = StaticEmitter(
	rate=250,
	template=Particle(
		size=(6,6,0),
		velocity=(0,-10,20),
	),
	color=[(1,0,0), (0,1,0), (0,0,1), (1,1,0), (1,0.5,0), (0.5,0,1)],
	rotation=[(0,0,0.3), (0,0,-0.3)],
	position=AABox((-100, 70, -100), (100, 70, -300)),
	deviation=Particle(
		color=(0.1, 0.1, 0.1, 0),
		rotation=(0,0,0.1),
		velocity=(0,5,0),
	)
)

default_system.add_global_controller(
	Movement(),
	Collector(Plane((0, 0, 0), (0, 0, -1))),
	Fader(fade_in_end=15.0),
)

font = pyglet.font.load(size=72)
# Try to force all glyphs into a single texture
Пример #14
0
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))

dust = ParticleGroup(
    controllers=[
        dust_emitter,
        Lifetime(8),
        Gravity((0, -20, 0)),
        Drag(0.0, 0.10, fluid_velocity=(80, 0, 0), domain=front),
        Drag(0.0, 0.10, fluid_velocity=(-80, 0, 0), domain=back),
        Magnet(charge=500, domain=vortex, exponent=0.75, epsilon=0.5),
        Movement(),
    ],
    renderer=PointRenderer(16, texturizer),
)