【问题标题】:Slider won't change value in VPython滑块不会改变 VPython 中的值
【发布时间】:2012-12-15 03:45:23
【问题描述】:

我的滑块不会改变我给它的参数值。滑块移动,但值不变。这里重要的是“温度”,我需要随滑块 2 变化。

另外,winsound 不会播放任何内容,我的滑块也没有标签。这到底是怎么回事?

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

temperature = 50
funct1 = gcurve(color=(temperature*0.04, (temperature*0.04)-2, (temperature*0.04)-2))

for x in arange (0., 100.1, 0.1):
    funct1.plot(pos=(x,5.*cos(2.*x)))
def setdir(direction): 
    cube.dir = direction

def setrate(obj): # called on slider drag events
    cuberate(obj.value) # value is min-max slider position

def cuberate(value):
    cube.dtheta = 2*value*pi/1e3

def woosh(sound):
    winsound.playsound('%s.wav' % sound, winsound.sphere.wav)


x=0
y=0
z=0
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)

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

cube = sphere(color=(temperature*0.04, (temperature*0.04)-2, (temperature*0.04)-2), material=materials.rough, pos=(x,y,z))
sphere.velocity = vector(x,y,z)

setrate(s1) 
setdir(-1) 

side = .4
thk = 0.3

t=0
dt=0.1
while True:
    rate(100)
    cube.p = vector (sin(t*0.02*temperature),sin(t*0.03*temperature),sin(t*0.04*temperature))
    cube.rotate(axis=(0,1,0), angle=cube.dir*cube.dtheta)
    t = t + dt
    cube.pos = cube.p*sin(t*temperature/100)/5
    woosh    
    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

【问题讨论】:

    标签: graphics controls vpython


    【解决方案1】:

    我认为这是对单词 value 中字母“s”的疏忽。将value替换成values在行ctrl:

    ctrl = slider(pos=(-50,20), width=7, length=100, axis=(1,0,0), text='temperature', min=0, max=50, values = temperature)
    

    【讨论】:

      猜你喜欢
      • 2021-12-29
      • 2011-09-17
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2022-01-23
      • 1970-01-01
      相关资源
      最近更新 更多