2012-12-12 91 views
3

首先,我沒有太多的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 
+0

您可能會嘗試修剪您的代碼,直到您找到一個小部分無法按預期工作。我看到你有兩個滑塊。他們中的任何一個工作?也許嘗試刪除一個,只是讓一個工作,然後才能工作。 –

+0

一個工作。 s1正常工作,s2什麼都不做。 – user1896636

+0

嗯..這是非常重要的信息,你可能想包括這個問題。注意你發送給每個參數的不同參數名稱;也許這與問題有關。 –

回答

0

創造S2後,你再重新分配S2:

 s2 = 2*side - thk

更改此S2到別的東西。