设置滑块值

时间:2012-12-12 04:28:25

标签: python vpython

首先,我没有太多Python经验。我试图做的就是让这个滑块给我一个我可以实际使用的变量temp。因为这是该死的事情或者告诉我数据类型不匹配或者根本没有报告滑块的位置。这是代码,(是的,我知道我的立方体是一个球体)

import pygame
import time
from visual.controls import *
from math import *

def setdir(direction): 
    cube.dir = direction

def red(value):
    red = temp * 0.04

def blue(value):
    blue = red - 2

def green(value):
    green = red - 2

def spherecolor(value): 
    cube.color = (red, 0, 0)
    if cube.color == color.red:
        t1.value = 0 
    else:
        t1.value = 1

def setrate(obj): 
    cuberate(obj.value) 

def cuberate(value):
    cube.dtheta = 2*value*pi/1e3
temp=1
a = 0
b = 0
c = 0
x = sin(a)
y = sin(b)
z = sin(c)
w = 350

display(x=w, y=0, width=w, height=w, range=1.5, forward=-vector(0,0,1), newzoom=1)

c = controls(x=0, y=0, width=w, height=w, range=60)

s2 = slider(pos=(-50,20), width=7, length=100, axis=(1,0,0), text='Temperature', max=100., value=temp)
s1 = slider(pos=(-50,40), width=7, length=100, axis=(1,0,0), text='Angular Velocity', action=lambda: setrate(s1))

cube = sphere(color=(temp/25, (temp/25)-2, (temp/25)-2), material=materials.rough, pos=(x,y,z))
sphere.velocity = vector(x,y,z)

setrate(s1) 
setdir(-1) 

side = .4
thk = 0.3
s2 = 2*side - thk
s3 = 2*side + thk

cube.p = vector (0.5,-0.3,0.0)
t=0
dt=0.1
while True:
    rate(100)
    cube.rotate(axis=(0,1,0), angle=cube.dir*cube.dtheta)
    t = t + dt
    cube.pos = cube.p*sin(t)/10
    if not (side > cube.x > -side):
        cube.p.x = -cube.p.x
    if not (side > cube.y > -side):
        cube.p.y = -cube.p.y
    if not (side > cube.z > -side):
        cube.p.z = -cube.p.z

1 个答案:

答案 0 :(得分:0)

创建s2后,再重新分配s2:

  s2 = 2*side - thk

将此s2更改为其他内容。