Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.
import os
from payton.scene import Scene
from payton.scene.geometry import Cube
from payton.scene.gui import info_box
from payton.scene.observer import Observer
scene = Scene()
scene.background.top_color = [0, 0, 0, 1]
scene.background.bottom_color = [0, 0, 0, 1]
texture_file = os.path.join(os.path.dirname(__file__), "cube.png")
cube = Cube(width=5.0, height=5.0, depth=5.0)
cube.position = [0, 0, 2.5]
cube.material.texture = texture_file
scene.add_object("cube", cube)
inside_box = Observer(position=[-1.7898840267533351, 2.210322695165203, 1.400984730396208], target=[0, 0, 1], fov=110,)
scene.add_observer(inside_box)
scene.add_object(
from payton.scene import Scene
scene = Scene()
scene.run()
import random
from payton.scene import Scene
from payton.scene.geometry import Cube
from payton.scene.gui import Button, Hud, Theme, Window, WindowAlignment
scene = Scene()
hud = Hud()
scene.add_object("interface", hud)
def new_cube():
x = random.randint(-5, 5)
y = random.randint(-5, 5)
z = random.randint(0, 5)
obj_count = len(scene.objects)
cube = Cube()
cube.position = [x, y, z]
scene.add_object("cube_{}".format(obj_count), cube)
def print_fps(period, total):
scene.huds["interface"].children["main_window"].children["fps_text"].label = f"FPS: {scene.fps}"
from payton.scene import Scene
from payton.scene.gui import info_box
minutes = 0
def change_background(period, total):
global minutes
h = int(minutes / 60) % 24
m = minutes % 60
scene.background.set_time(h, m)
minutes += 10
scene = Scene()
scene.create_clock("sun", 0.1, change_background)
scene.add_object(
"info", info_box(left=10, top=10, width=220, height=100, label="Hit SPACE\nto start animation",),
)
scene.run()
import math
import os
from payton.scene import SHADOW_HIGH, Scene
from payton.scene.geometry import Wavefront
scene = Scene(1600, 900)
angle = 0
def change_date(period, total):
global angle
angle += 1
if angle == 180:
angle = 0
if angle < 30 or angle > 150:
scene.lights[0].color = [1, 0.7, 0]
else:
scene.lights[0].color = [1, 1, 1]
total_minutes = angle * 4
collision.resolve(pair[0], pair[1])
return True
def hit_aabb(collision, pairs):
for pair in pairs:
pair[0].material.color = [0.0, 1.0, 0]
pair[1].material.color = [0.0, 1.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])
return True
scene = Scene(width=600, height=600)
spherical_collision = CollisionTest(callback=hit_sphere, level=CollisionTest.SPHERICAL)
aabb_collision = CollisionTest(callback=hit_aabb, level=CollisionTest.AABB)
car_object_file = os.path.join(os.path.dirname(__file__), "lib", "Low-Poly-Racing-Car.obj")
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]
from payton.scene import Scene
from payton.scene.geometry import Line, Plane
from payton.scene.gui import info_box
def draw(hit):
global scene
scene.objects["line"].append([hit])
scene = Scene()
scene.add_click_plane([0, 0, 0.5], [0, 0, 1], draw)
scene.add_object("line", Line())
scene.objects["line"].material.color = [1.0, 0.0, 0.0]
ground = Plane(30, 30)
ground.position = [0, 0, 0.48]
scene.add_object("ground", ground)
scene.add_object(
"info", info_box(left=10, top=10, width=220, height=100, label="Start Clicking \nto draw lines",),
)
scene.run()
import random
from payton.scene import Scene
from payton.scene.geometry import Cube, Plane
scene = Scene()
ground = Plane(20, 20)
scene.add_object("ground", ground)
for i in range(100):
x = random.randint(-10, 10)
y = random.randint(-10, 10)
z = random.randint(0, 10)
r = random.randint(0, 255) / 255.0
g = random.randint(0, 255) / 255.0
b = random.randint(0, 255) / 255.0
cube = Cube()
cube.material.color = [r, g, b]
cube.material.opacity = random.randint(0, 255) / 255.0
cube.position = [x, y, z]
scene.add_object("cube_{}".format(i), cube)
from payton.scene import Scene
from payton.scene.geometry import Line
scene = Scene()
line = Line(
vertices=[[0, 0, 0], [0, 0, 1], [0.5, 0, 1.5], [1, 0, 1], [0, 0, 1], [1, 0, 0], [0, 0, 0], [1, 0, 1], [1, 0, 0]]
)
scene.add_object("line", line)
scene.run()
import math
import os
from payton.scene import Scene
from payton.scene.geometry import Wavefront
scene = Scene()
scene.background.top_color = [0, 0, 0, 1]
scene.background.bottom_color = [0, 0, 0, 1]
amount = 0.5
total_angles = -30
def swing(period, total):
global total_angles, amount
scene.objects["lamp"].rotate_around_x(math.radians(amount))
total_angles += amount
if total_angles >= 30:
amount = -0.5
if total_angles <= -60:
amount = 0.5
light_pos = scene.objects["lamp"].to_absolute([0, 0, -3.4])