コード例 #1
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()
コード例 #2
0
            rise = False
    else:
        if c[0] >= initial[0]:
            c[0] -= 0.01
        if c[1] >= initial[1]:
            c[1] -= 0.01
        if c[2] >= initial[2]:
            c[2] -= 0.01

        if sum(c) <= sum(initial) + 0.01:
            rise = True
    scene._background.top_color = c


scene = Scene()
scene.create_clock("sun", 0.1, change_background)

hud = Hud()
font_file = os.path.join(os.path.dirname(__file__),
                         "../static/arial_narrow_7.ttf")
hud.set_font(font_file, 15)

info_text = "Hit space to start background animation"

info = Text(label=info_text,
            position=(550, 0),
            color=(1, 1, 1),
            size=(300, 200))

hud.add_child("info", info)
scene.add_object("hud", hud)
コード例 #3
0
spherical_car_1 = Wavefront(filename=car_object_file)
spherical_car_2 = Wavefront(filename=car_object_file)

aabb_car_1 = Wavefront(filename=car_object_file)
aabb_car_2 = Wavefront(filename=car_object_file)

spherical_car_1.position = [-2, 0, 0]
spherical_car_2.position = [-2, 0, 4]

aabb_car_1.position = [2, 0, 0]
aabb_car_2.position = [2, 0, 4]

scene.add_object("scar1", spherical_car_1)
scene.add_object("scar2", spherical_car_2)

scene.add_object("acar1", aabb_car_1)
scene.add_object("acar2", aabb_car_2)

spherical_collision.add_object(spherical_car_1)
spherical_collision.add_object(spherical_car_2)

aabb_collision.add_object(aabb_car_1)
aabb_collision.add_object(aabb_car_2)

scene.add_collision_test(spherical_collision)
scene.add_collision_test(aabb_collision)

scene.create_clock("motion", 0.01, motion)

scene.run()
コード例 #4
0
ファイル: 14_rotate.py プロジェクト: magandrez/payton
import os
import math
from payton.scene import Scene
from payton.scene.geometry import Cube


def rotate(name, scene, period, total):
    y = math.radians(period * 100)
    y = -y if int(total) % 2 == 0 else y

    scene.objects["cube"].rotate_around_x(math.radians(period * 50))
    scene.objects["cube"].rotate_around_y(y)
    scene.objects["cube"].rotate_around_z(math.radians(period * 150))


scene = Scene()
cube = Cube()
texture_file = os.path.join(os.path.dirname(__file__), "cube.png")

scene.observers[0].distance_to_target(3)
cube.material.texture = texture_file
scene.add_object("cube", cube)

scene.create_clock("rotate", 0.01, rotate)
scene.run()
コード例 #5
0
ファイル: instagram.py プロジェクト: magandrez/payton
                if y == 3:
                    y = 0
                    z += 1
                cube.material.texture = f"/tmp/{node['id']}.jpg"
                cube.info = node["edge_media_to_caption"]["edges"][0]["node"][
                    "text"
                ]
                scene.add_object(node["id"], cube)


def select(list):
    global scene
    print(list[0].info)
    scene.huds["hud"].children["info"].label = list[0].info
    scene.active_observer.target_object = list[0]


scene.on_select = select
scene.create_clock("fetch_instagram", 0.1, fetch_instagram)
hud = Hud()
hud.set_font(font_file)

text = Text(
    label="Instagram Photos", color=(1, 1, 1), position=(0, 0), size=(800, 600)
)
hud.add_child("info", text)

scene.add_object("hud", hud)

scene.run()
コード例 #6
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()
コード例 #7
0
def generate(name, scene, period, total):
    x = random.randint(-10, 10)
    y = random.randint(-10, 10)
    z = random.randint(-10, 10)
    r = random.randint(0, 255) / 255
    g = random.randint(0, 255) / 255
    b = random.randint(0, 255) / 255
    scene.objects["pc"].add([[x, y, z]], [[r, g, b]])


scene = Scene()

hud = Hud()
text = Text(
    label="Hit Space to create points",
    position=(5, 5),
    size=(200, 35),
    color=(1, 1, 1),
)

hud.add_child("text", text)
scene.add_object("hud", hud)

pc = PointCloud()

scene.add_object("pc", pc)
scene.create_clock("generate", 0.001, generate)

scene.run()
コード例 #8
0
                scene.objects[sphere_name].material.color = RED


def select(list):
    global game
    global score_board
    for obj in list:
        if not obj.visible:
            continue
        obj.hide()
        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",
コード例 #9
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()