示例#1
0
def flyby():
    width = height = 800

    scene = Scene(f=2000, cx=width/2, cy=height/2)
    scene.main_camera.position = Vector3(0, 10, -5)
    scene.main_camera.look_at(Vector3.zero())
    cubes = [
        Cube(color=(0, 1, 0), position=Vector3(x, 0, z))
        for x in range(-10, 10, 2) for z in range(-10, 10, 2)
    ]
    cubes = [Cube(), Cube(position=Vector3(0, 0, 2))]

    renderer = SDLRenderer(width=width, height=height)

    for o in cubes:
        scene.add_object(o)

    t0 = time.time()
    while True:
        t = time.time()
        dt = t - t0
        # scene.main_camera.position = Vector3(50*sin(t/2), 30*tan(t/8), 50*cos(t/2))
        scene.main_camera.look_at(Vector3(0, 0, 0))
        # for o in cubes:
            # o.rotate(Vector3(-.2, 0.5*t, t/10))
        renderer.render(scene, draw_polys=True, draw_edges=True)
示例#2
0
def punyty(grid, t):
    target_array = get_target_array(grid)
    renderer = get_renderer(target_array)

    if hydra.f < 0.2:
        cube.rotate(
            Vector3(-3 + hydra.a * 6, -3 + hydra.b * 6, -3 + hydra.c * 6))
        cube.color = Vector3(hydra.a, hydra.b, hydra.c)
    else:
        cube.rotate(
            Vector3(math.sin(.9 * t), math.sin(0.63 * t), math.cos(0.85 * t)))
        color = Vector3(sin(.1 * t + 1), .1 + sin(0.08 * t), cos(0.1515 * t))
        cube.color = color

    renderer.render(scene)

    grid_w = grid.shape[1]
    target_w = target_array.shape[1]
    xi = np.linspace(0, target_w, grid_w, endpoint=False, dtype=np.int32)
    dst = target_array[:, xi]
    mask = dst > 0
    grid[mask] = dst[mask]
示例#3
0
文件: punytty.py 项目: jsheedy/punyty
def punytty():
    args = parse_args()
    scene = Scene()
    objects = []

    if args.bunny:
        path = os.path.join(BASEDIR, '../models/bunny.ply')
        bunny = Model.load_ply(path)
        bunny.position = Vector3(0, 0, 0)
        objects.append(bunny)
        args.polys = True
    else:
        objects.append(Cube(color=Vector3(.1, 1, .2)))

    renderer = TTYRenderer(status_bar=args.fps,
                           draw_polys=args.polys,
                           draw_edges=(not args.polys))

    for o in objects:
        scene.add_object(o)

    bench = benchmark.Benchmark(renderer)
    fps = ''

    while True:
        t = time.time()
        scene.update()
        for o in objects:
            o.rotate(Vector3(-.2, 0.5 * t, t / 10))

        renderer.render(scene)

        if args.fps:
            fps = bench.update(t) or fps
            sys.stdout.buffer.write(HOME + renderer.pixel(255, 255, 255) +
                                    fps.encode('utf8'))
示例#4
0
    def __init__(self,
                 width=800,
                 height=600,
                 window_title="punyty",
                 opengl=True,
                 **kwargs):
        super().__init__(**kwargs)
        self.width = width
        self.height = height
        sdl2.ext.init()

        if opengl:
            flags = sdl2.SDL_WINDOW_OPENGL
        else:
            flags = sdl2.SDL_RENDERER_SOFTWARE

        self.window = sdl2.ext.Window(window_title,
                                      flags=flags,
                                      size=(width, height))
        self.window.show()
        self.context = sdl2.ext.Renderer(self.window)
        self.joystick = Joystick(0, 0)
        self.clear_color = kwargs.get('clear_color', Vector3(0, 0, 0))
示例#5
0
import math

import numpy as np
from punyty.vector import Vector3
from punyty.objects import Cube
from punyty.renderers import ArrayRenderer
from punyty.scene import Scene

from ..hydra import hydra
from ..utils import sin, cos

scene = Scene()
cube = Cube(color=Vector3(1, 0.8, 0.7), position=Vector3(-.35, 0, 1.3))
scene.add_object(cube)

cache = {}


def get_target_array(grid):
    if 'target_array' in cache:
        return cache.get('target_array')

    h, w, c = grid.shape
    s = max((h, w))
    ta = np.zeros((s, s, c), dtype=np.float32)
    cache['target_array'] = ta
    return ta


def get_renderer(target_array):
    renderer = cache.get('renderer')
示例#6
0
ArrayRenderer independent of display """

import time

import numpy as np

from punyty.vector import Vector3
from punyty.objects import Cube
from punyty.renderers import ArrayRenderer
from punyty.scene import Scene

import benchmark

if __name__ == '__main__':
    width = 800
    height = 800
    target_array = np.zeros((height, width, 3))
    scene = Scene()
    cube = Cube()
    scene.add_object(cube)
    renderer = ArrayRenderer(target_array=target_array)

    bench = benchmark.Benchmark(renderer)

    while True:
        t = time.time()
        renderer.render(scene)
        cube.rotate(Vector3(time.time(), 0, 0))
        fps = bench.update(t)
        if fps:
            print(fps)
示例#7
0
import time

from punyty.vector import Vector3
from punyty.objects import Cube
from punyty.renderers import SDLRenderer
from punyty.scene import Scene
import benchmark

if __name__ == '__main__':
    width = 1280
    height = 720

    scene = Scene()

    cube = Cube(color=Vector3(1, 1, 1))
    scene.add_object(cube)

    renderer = SDLRenderer(width=width, height=height)

    bench = benchmark.Benchmark(renderer)

    while True:
        scene.update()

        t = time.time()

        cube.rotate(Vector3(t, t, t))

        renderer.render(scene, draw_edges=False, draw_polys=True)

        fps = bench.update(t)
示例#8
0
from punyty.renderers import SDLRenderer
from punyty.scene import Scene, DirectionalLight
import benchmark

def sin(x):
    return math.sin(x)/2+0.5

def cos(x):
    return math.cos(x)/2+0.5

if __name__ == '__main__':
    width = 1280
    height = 720

    scene = Scene()
    scene.main_camera.position = Vector3(0, 0, -10)
    scene.main_camera.look_at(Vector3(0, 0, 0))
    cubes = (
        Tetrahedron(position=Vector3(-2, -2, 0), color=Vector3(1, 0, 0)),
        Cube(position=Vector3(-2, 2, 0), color=Vector3(0, 1, 0)),
        Octahedron(position=Vector3(2, -2, 0), color=Vector3(0, 0, 1)),
        Cube(position=Vector3(2, 2, 0), color=Vector3(.8, .0, .0)),
    )
    # for cube in cubes:
    #     scene.add_object(cube)
    # bunny = Model.load_ply('models/bunny.ply')
    bunny = Model.load_ply('/Users/velotron/assets/stegs-low-poly.ply')
    bunny.color = Vector3(1,.5,.75)
    bunny.rotate(Vector3(0,1.1, 0))
    # bunny = Model.load_ply('/Users/velotron/assets/velotron_arise_eecc.ply')
    # bunny = Model.load_ply('/Users/velotron/assets/sphere.ply')
示例#9
0
""" two renderers at once """
import math
import time

from punyty.model import Model
from punyty.objects import Cube, Tetrahedron
from punyty.renderers import TTYRenderer, SDLRenderer
from punyty.scene import Scene
from punyty.vector import Vector3


if __name__ == '__main__':
    width = 800
    height = 800
    scene = Scene()
    scene.main_camera.position = Vector3(0,0,-15)
    cube = Cube(position=Vector3(0,-0.5,0), scale=Vector3(0.2, 0.2, 0.2))
    model = Model.load_ply('/Users/velotron/assets/stegs-low-poly.ply')
    scene.add_object(cube)
    scene.add_object(model)
    tty_renderer = TTYRenderer()
    sdl_renderer = SDLRenderer(width=width, height=height)

    while True:
        t = time.time()
        # cube.rotate(Vector3(math.sin(t), t, t))
        # model.rotate(Vector3(math.sin(t), t, t))
        scene.main_camera.position=Vector3(10*math.cos(.2*t), .2, 10*math.sin(.4*t))
        scene.main_camera.look_at(Vector3())
        scene.update()
        tty_renderer.render(scene, draw_edges=False, draw_polys=True)