Rotate a cube with slider

53 views
Skip to first unread message

Lucas Fonseca

unread,
Jul 15, 2016, 2:31:49 PM7/15/16
to VPython-users
Hello guys,
  How could use a slider to rotate a box forward or backward, and the slider is 0 to 100 and begins at 50, all I can is turning forward, thank you, excuse my English.

Lucas Fonseca

unread,
Jul 15, 2016, 2:35:39 PM7/15/16
to VPython-users


On Friday, July 15, 2016 at 3:31:49 PM UTC-3, Lucas Fonseca wrote:
Hello guys,
  How could use a slider to rotate a box forward or backward, and the slider is 0 to 100 and begins at 50, all I can is turning forward, thank you, excuse my English.

     I´m using: python-3.2.2 and VPython-Win-Py3.2-5.74 

Bruce Sherwood

unread,
Jul 15, 2016, 4:37:35 PM7/15/16
to VPython-users

A simple way is to use slidervalue - 50 to determine the rotation angle, so the altered value runs from -50 to +50.


--
You received this message because you are subscribed to the Google Groups "VPython-users" group.
To unsubscribe from this group and stop receiving emails from it, send an email to vpython-user...@googlegroups.com.
For more options, visit https://groups.google.com/d/optout.

Lucas Fonseca

unread,
Jul 15, 2016, 5:11:06 PM7/15/16
to VPython-users
To rotate the cube forward until you reach the 50 it rotates normal, but when I return the slider, the hub continues rotating forward until you get to 25, because it ?, thank you.

Bruce Sherwood

unread,
Jul 15, 2016, 5:25:43 PM7/15/16
to VPython-users

Please post a short version of your program that illustrates the problem.

Message has been deleted
Message has been deleted

Bruce Sherwood

unread,
Jul 15, 2016, 8:31:30 PM7/15/16
to VPython-users

What we need is a very short excerpt of your long program that illustrates the problem you are having. For example, just the slider and some simple code that uses the slider value. We can't track through your long program looking for your problem.

Bruce Sherwood

unread,
Jul 15, 2016, 9:22:10 PM7/15/16
to VPython-users

Perhaps I should comment that I do read Portuguese, so although I can't write it, feel free to write in Portuguese if that works better for you.

Lucas Fonseca

unread,
Jul 15, 2016, 9:28:12 PM7/15/16
to VPython-users
Desculpe por postar o código grande, segue aqui um código pequeno, e muito obrigado Bruce

from visual import *
from visual.controls import *

cube = box( pos=(0, 0, 0), size=(0.2, 0.2, 0.2), color=(0.80, 0.52, 0.10) )

def giraFrente(rot):        
    cube.rotate( axis= (1, 0, 0), angle= s1.value, origin= (0 , 0, 0) )

cont = controls(title= 'Controles', x= 440, y= 0, width=200, height= 200, range= 50, background=(0.18, 0.18, 0.18))

s1 = slider( pos=(-35, 22), width=10, length=70, axis=(1000, 1, 0), min= -0.10, value= 0, max= 0.10, action=lambda: giraFrente(s1) )


Em sexta-feira, 15 de julho de 2016 15:31:49 UTC-3, Lucas Fonseca escreveu:

Bruce Sherwood

unread,
Jul 15, 2016, 11:30:06 PM7/15/16
to VPython-users
I think what you intended is this:

from visual import *
from visual.controls import *

cube = box()

def giraFrente(s):
    theta = s.value
    cube.up = vector(0,sin(theta),cos(theta))

cont = controls(title='Controles', x=440, y=0,
                width=200, height=200, range=50,
                background=(0.18,0.18,0.18))
s1 = slider(pos=(-35,22), width=10, length=70,
    axis=vector(1000,1,0), min=-pi/2, value=0, max=pi/2,
    action=lambda: giraFrente(s1))

I'm guessing that you meant to use the slider to place the box at a particular angle equal to the setting of the slider. But the rotate function CHANGES the orientation by the slider amount, it doesn't SET the angle. The program shown above SETS the orientation of the box.

If you wanted to do something else, please describe in detail what you want to do (in Portuguese).


Lucas Fonseca

unread,
Jul 16, 2016, 8:46:10 AM7/16/16
to VPython-users
Isso mesmo, mas teria como escolher a origem do cubo?, seria como uma cabeça que rotaciona no pescoço, muito obrigado por sua atenção Bruce.


Em sexta-feira, 15 de julho de 2016 15:31:49 UTC-3, Lucas Fonseca escreveu:

Bruce Sherwood

unread,
Jul 16, 2016, 11:20:33 AM7/16/16
to VPython-users

The origin of the box is at it's center, which is specified by the pos attribute. In contrast, the origin of a cylinder is at the end. I suggest reading carefully the documentation for box and cylinder.

Bruce Sherwood

unread,
Jul 16, 2016, 11:42:36 AM7/16/16
to VPython-users

Maybe I should say it this way: If an object has been rotated by an amount theta2, a second rotation by an amount theta2 will result in a total rotation of theta1+theta2, whereas if you perform two changes of up of an object, the second operation is unaffected by having done the first operation.

Lucas Fonseca

unread,
Jul 16, 2016, 12:17:32 PM7/16/16
to VPython-users
Você me ajudou muito Bruce, só mais uma pequena coisa, como faço para enquanto ficar pressionando um Botão o cubo ficar girando?, abraços.


Em sexta-feira, 15 de julho de 2016 15:31:49 UTC-3, Lucas Fonseca escreveu:

Bruce Sherwood

unread,
Jul 16, 2016, 12:52:01 PM7/16/16
to VPython-users

All I can say is to study the documentation on the visual.controls module and run the VPython examples available when you start up VIDLE by opening files on the file menu.

Lucas Fonseca

unread,
Jul 16, 2016, 1:26:34 PM7/16/16
to VPython-users
Ok vou estudar tudo, desculpe qualquer coisa, e muito obrigado por sua atenção e por tudo Bruce, grande abraço.


Em sexta-feira, 15 de julho de 2016 15:31:49 UTC-3, Lucas Fonseca escreveu:
Reply all
Reply to author
Forward
0 new messages