Exemple #1
0
import os
from payton.scene import Scene
from payton.scene.geometry import Mesh


scene = Scene()
mesh = Mesh()
mesh.add_triangle(
    [[0, 0, 0], [2, 0, 0], [2, 2, 0]], texcoords=[[0, 0], [1, 0], [1, 1]]
)
mesh.add_triangle(
    [[0, 0, 0], [2, 2, 0], [0, 2, 0]], texcoords=[[0, 0], [1, 1], [0, 1]]
)
texture_file = os.path.join(os.path.dirname(__file__), "cube.png")
mesh.material.texture = texture_file
scene.add_object("mesh", mesh)
scene.run()
Exemple #2
0
def logger(name, scene, period, total):
    if scene.objects["ball"].matrix[3][2] < 0:
        # Do not continue simulation if we hit the ground.
        scene.clocks[name].kill()  # We do not need this clock anymore
        return None

    # Log ball location
    logging.debug("Ball position: x:{} y:{} z:{} t={}".format(
        scene.objects["ball"].matrix[3][0],
        scene.objects["ball"].matrix[3][1],
        scene.objects["ball"].matrix[3][2],
        total,
    ))


#  Definitions
pm_scene = Scene()

ball = Sphere(radius=1, track_motion=True)

# Add ball to the scene
pm_scene.add_object("ball", ball)
pm_scene.observers[0].target_object = ball  # Track the ball

pm_scene.grid.resize(30, 30, 2)

pm_scene.create_clock("motion", 0.01, projectile_motion)
pm_scene.create_clock("logger", 0.05, logger)

pm_scene.run()
Exemple #3
0
        score_board += 1
        game.huds["hud"].children[
            "score"].label = f"Number of balloons popped: {score_board}"


game.create_clock("balloon-creator", 1, create_balloon)
game.create_clock("move-balloons", 0.005, move_balloons)
game.on_select = select
hud = Hud()

text = Text(
    label="Hit Space to start popping the balloons!",
    position=(10, 10),
    color=(1, 1, 1),
    size=(300, 100),
)

hud.add_child("info", text)

score = Text(
    label="Number of balloons popped: 0",
    position=(10, 40),
    color=(1, 1, 1),
    size=(300, 100),
)

hud.add_child("score", score)

game.add_object("hud", hud)
game.run()
Exemple #4
0
    scene.objects["nucleus"].children["particle"].children[
        "sub_particle"
    ].position = [sx, sy, 0]
    scene.lights[0].position = [px, py, 0]
    scene.lights[1].position = [-px, -py, 0]


space = Scene()
space.lights.append(Light())
space.observers[0].position = [20, 20, 20]
space.grid.resize(40, 40, 1)

texture_file = os.path.join(os.path.dirname(__file__), "map.png")

nucleus = Sphere(radius=5, parallels=36, meridians=36)
nucleus.material.texture = texture_file
particle = Sphere()
particle.position = [8, 0, 0]

sub_particle = Sphere(radius=0.5)
sub_particle.position = [0, 2, 0]

nucleus.add_child("particle", particle)
particle.add_child("sub_particle", sub_particle)

space.add_object("nucleus", nucleus)

space.create_clock("motion", 0.01, motion)
print("Hit SPACE to continue animation")
space.run()
Exemple #5
0
    moving_part = c3
    myScene.clocks["c2_clocks"].pause()
    print("Collision triggered")


collision = CollisionTest(callback=makeItRed)
collision.add_object(c2)
collision.add_object(c3)
myScene.add_collision_test("test", collision)

myScene.add_object("cylinder_1", c1)
myScene.add_object("cylinder_2", c2)
myScene.add_object("cylinder_3", c3)


def c2Move(period, total):
    pos = moving_part.position
    moving_part.position = [pos[0], pos[1], pos[2] + period]


def c3Move(period, total):
    if moving_part == c3 and myScene.clocks["c2_clocks"]._pause:
        time.sleep(0.5)
        c3.material.color = [1.0, 1.0, 1.0]
        myScene.clocks["c2_clocks"].pause()


myScene.create_clock("c2_clocks", 0.03, c2Move)
myScene.create_clock("c3_clocks", 0.03, c3Move)
myScene.run()