首先,我对 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