Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.
def test_bounding_sphere_collision_false(self):
a = Sphere(radius=2.0)
b = Sphere()
b.position = [4.5, 0.5, 0]
c = CollisionTest(callback=dummy, objects=[a, b])
check = c._bounding_sphere_collision(a, b)
self.assertFalse(check)
def test_dist(self):
a = Sphere()
b = Sphere()
b.position = [3, 0, 4]
c = CollisionTest(callback=dummy, objects=[a, b])
dist = c._dist(a, b)
self.assertAlmostEqual(dist, 5)
def test_dist(self):
a = Sphere()
b = Sphere()
b.position = [3, 0, 4]
c = CollisionTest(callback=dummy, objects=[a, b])
dist = c._dist(a, b)
self.assertAlmostEqual(dist, 5)
def test_sphere_in_sphere_false(self):
a = Sphere(radius=10)
b = Sphere(radius=2)
b.position = [10, 2, 0]
c = CollisionTest(callback=dummy, objects=[a, b])
check = c._sphere_in_sphere_collision(a, b)
self.assertFalse(check)
pair[0].material.color = [1.0, 0, 0]
pair[1].material.color = [1.0, 0, 0]
# Once there is a hit, system will not check
# for the same collision, if you want to have the objects
# back in the collision detection pipeline, you have to do
# collision.resolve(pair[0], pair[1])
scene = Scene()
collision = CollisionTest(callback=hit)
for i in range(50):
x = random.randint(-5, 5)
y = random.randint(-5, 5)
z = random.randint(-5, 5)
if i % 2 == 0:
s = Sphere()
s.position = [x, y, z]
scene.add_object("s_{}".format(i), s)
collision.add_object(s)
else:
c = Cube()
c.position = [x, y, z]
scene.add_object("c_{}".format(i), c)
collision.add_object(c)
scene.add_collision_test("test", collision)
scene.run()
if scene.active_observer.far < 1:
direction = 3
if direction == 3:
scene.active_observer.far += 0.1
if scene.active_observer.far > 20:
direction = 0
scene.active_observer.far = 20
collision = CollisionTest(callback=hit)
for i in range(50):
x = random.randint(-5, 5)
y = random.randint(-5, 5)
z = random.randint(-5, 5)
if i % 2 == 0:
s = Sphere()
s.position = [x, y, z]
scene.add_object("s_{}".format(i), s)
collision.add_object(s)
else:
c = Cube()
c.position = [x, y, z]
scene.add_object("c_{}".format(i), c)
collision.add_object(c)
scene.add_collision_test("test", collision)
scene.create_clock("plane", 0.01, change_near_plane)
scene.run()
import os
from payton.scene.geometry import Cube, Sphere, Wavefront
from payton.scene.geometry.export import export_json, import_json
from payton.scene.scene import Scene
object_file = os.path.join(os.path.dirname(__file__), "monkey.obj")
monkey = Wavefront(filename=object_file)
monkey.add_child("cube", Cube())
monkey.children["cube"].position = [0, 0, 3]
monkey.children["cube"].add_child("sphere", Sphere())
monkey.children["cube"].children["sphere"].position = [1, 0, 0]
export_json(monkey, "test.json")
new = import_json("test.json")
scene = Scene()
scene.add_object("monkey", new)
scene.run()
space.lights[0].position = [px, py, 0]
space.lights[1].position = [-px, -py, 0]
space = Scene()
space.shadow_quality = SHADOW_NONE
space.lights.append(Light(position=[12, 12, 12]))
space.observers[0].position = [20, 20, 20]
space.grid.resize(40, 40, 1)
texture_file = os.path.join(os.path.dirname(__file__), "map.png")
earth = Sphere(radius=5, parallels=36, meridians=36)
earth.material.texture = texture_file
moon = Sphere()
moon.position = [8, 0, 0]
moon_moon = Sphere(radius=0.5)
moon_moon.position = [0, 2, 0]
earth.add_child("moon", moon)
moon.add_child("moon_moon", moon_moon)
space.add_object("earth", earth)
space.create_clock("motion", 0.01, motion)
space.add_object(
"info", info_box(left=10, top=10, width=220, height=100, label="Hit SPACE\nto start animation",),
)
space.run()
import random
from payton.scene import Scene
from payton.scene.geometry import Sphere
from payton.scene.gui import info_box
from payton.scene.material import RED, YELLOW
sphere_count = 0
score_board = 0
game = Scene()
base_sphere = Sphere()
def create_balloons():
global sphere_count
for i in range(4):
x = random.randint(-5, 5)
y = random.randint(-5, 5)
z = random.randint(10, 20)
proxy = base_sphere.clone()
proxy.position = [x, y, z]
game.add_object(f"sphere_{sphere_count}", proxy)
sphere_count += 1
def move_balloons(period, total):
for k in range(sphere_count):
0,
]
space.lights[0].position = [px, py, 0]
space.lights[1].position = [-px, -py, 0]
space = Scene()
space.shadow_quality = SHADOW_NONE
space.lights.append(Light(position=[12, 12, 12]))
space.observers[0].position = [20, 20, 20]
space.grid.resize(40, 40, 1)
texture_file = os.path.join(os.path.dirname(__file__), "map.png")
earth = Sphere(radius=5, parallels=36, meridians=36)
earth.material.texture = texture_file
moon = Sphere()
moon.position = [8, 0, 0]
moon_moon = Sphere(radius=0.5)
moon_moon.position = [0, 2, 0]
earth.add_child("moon", moon)
moon.add_child("moon_moon", moon_moon)
space.add_object("earth", earth)
space.create_clock("motion", 0.01, motion)
space.add_object(
"info", info_box(left=10, top=10, width=220, height=100, label="Hit SPACE\nto start animation",),
)