# -*- coding: utf-8 -*-
# Copyright (c) 2014, Vispy Development Team.
# Distributed under the (new) BSD License. See LICENSE.txt for more info.

"""
Demonstration of Cube
"""

import sys

from vispy import app, gloo
from vispy.visuals import CubeVisual, TransformSystem, transforms


class Canvas(app.Canvas):
    def __init__(self):
        self.cube = CubeVisual((1.0, 0.5, 0.25), color='red',
                               edge_color='black')
        self.theta = 0
        self.phi = 0

        app.Canvas.__init__(self, 'Cube', keys='interactive',
                            size=(400, 400))
        self.cube_transform = transforms.AffineTransform()
        self._timer = app.Timer('auto', connect=self.on_timer, start=True)

    def on_draw(self, event):
        gloo.set_viewport(0, 0, *self.size)
        gloo.clear('white')
        # Create a TransformSystem that will tell the visual how to draw
        tr_sys = TransformSystem(self)
        tr_sys.visual_to_document = self.cube_transform
        self.cube.draw(tr_sys)

    def on_timer(self, event):
        self.theta += .5
        self.phi += .5
        self.cube_transform.reset()
        self.cube_transform.rotate(self.theta, (0, 0, 1))
        self.cube_transform.rotate(self.phi, (0, 1, 0))
        self.cube_transform.scale((100, 100, 0.001))
        self.cube_transform.translate((200, 200))
        self.update()

if __name__ == '__main__':
    win = Canvas()
    win.show()
    if sys.flags.interactive != 1:
        win.app.run()

# -*- coding: utf-8 -*-
# Copyright (c) 2014, Vispy Development Team.
# Distributed under the (new) BSD License. See LICENSE.txt for more info.

"""
Demonstration of Cube
"""

import sys

from vispy import app, gloo
from vispy.visuals import CubeVisual, transforms


class Canvas(app.Canvas):
    def __init__(self):
        self.cube = CubeVisual((1.0, 0.5, 0.25), color='red',
                               edge_color='black')
        self.theta = 0
        self.phi = 0

        app.Canvas.__init__(self, 'Cube', keys='interactive',
                            size=(400, 400))
        self.cube_transform = transforms.AffineTransform()
        self._timer = app.Timer('auto', connect=self.on_timer, start=True)

    def on_draw(self, event):
        gloo.set_viewport(0, 0, *self.size)
        gloo.clear('white')
        # Create a TransformSystem that will tell the visual how to draw
        tr_sys = transforms.TransformSystem(self)
        tr_sys.visual_to_document = self.cube_transform
        self.cube.draw(tr_sys)

    def on_timer(self, event):
        self.theta += .5
        self.phi += .5
        self.cube_transform.reset()
        self.cube_transform.rotate(self.theta, (0, 0, 1))
        self.cube_transform.rotate(self.phi, (0, 1, 0))
        self.cube_transform.scale((100, 100, 0.001))
        self.cube_transform.translate((200, 200))
        self.update()

if __name__ == '__main__':
    win = Canvas()
    win.show()
    if sys.flags.interactive != 1:
        win.app.run()

fix cube example