2017-05-22 3 views
0

제가 작업하고있는 프로젝트는 스프링으로 연결된 일련의 구로 이동하는 펄스를 모델링하기로되어 있습니다. 맥박이 체인을 따라 내려감에 따라 스프링 길이를 줄이기 위해 노력하고 있지만, 나는 그것을 실행할 때 아무 일도 일어나지 않습니다.스프링 길이를 변경하는 루프는 실행시 아무 것도 바뀌지 않습니다.

from visual import * 

one = sphere(pos=(-10,0,0), radius = 0.5, color = color.red) 
two = sphere(pos=(-8,0,0), radius = 0.5, color = color.orange) 
three = sphere(pos=(-6,0,0), radius = 0.5, color = color.yellow) 
four = sphere(pos=(-4,0,0), radius = 0.5, color = color.green) 
five = sphere(pos=(-2,0,0), radius = 0.5, color = color.blue) 
six = sphere(pos=(0,0,0), radius = 0.5, color = color.cyan) 
seven = sphere(pos=(2,0,0), radius = 0.5, color = color.magenta) 
eight = sphere(pos=(4,0,0), radius = 0.5, color = color.white) 
nine = sphere(pos=(6,0,0), radius = 0.5, color = color.red) 
ten = sphere(pos=(8,0,0), radius = 0.5, color = color.orange) 

spring1 = helix(pos = (-10, 0, 0), length = 2, radius = 0.3, 
    thickness = 0.05, color = color.red) 
spring2 = helix(pos = (-8, 0, 0), length = 2, radius = 0.3, 
    thickness = 0.05, color = color.orange) 
spring3 = helix(pos = (-6, 0, 0), length = 2, radius = 0.3, 
    thickness = 0.05, color = color.yellow) 
spring4 = helix(pos = (-4, 0, 0), length = 2.0, radius = 0.3, 
    thickness = 0.05, color = color.green) 
spring5 = helix(pos = (-2, 0, 0), length = 2.0, radius = 0.3, 
    thickness = 0.05, color = color.blue) 
spring6 = helix(pos = (0, 0, 0), length = 2.0, radius = 0.3, 
    thickness = 0.05, color = color.cyan) 
spring7 = helix(pos = (2, 0, 0), length = 2.0, radius = 0.3, 
    thickness = 0.05, color = color.magenta) 
spring8 = helix(pos = (4, 0, 0), length = 2.0, radius = 0.3, 
    thickness = 0.05, color = color.white) 
spring9 = helix(pos = (6, 0, 0), length = 2.0, radius = 0.3, 
    thickness = 0.05, color = color.red) 

masses = [one, two, three, four, five, six, seven, eight, nine, ten] 
springs = [spring1, spring2, spring3, spring4, spring5, spring6, spring7, 
      spring8, spring9] 

while True: 
    n=0 
    deltax=.2 
    while n < 10: 
     rate(30) 
     masses[n].pos.x = masses[n].pos.x + deltax 
     if n < 9: 
      springs[n].pos = masses[n].pos 
      springs[n].axis = masses[n+1].pos-masses[n].pos 
     n=n+1 

    n = n-1 
    while n >= 0: 
     rate(30) 
     masses[n].pos.x = masses[n].pos.x - deltax 
     if n < 0: 
      springs[n-1].pos = masses[n-1].pos - deltax 
      springs[n-1].axis = masses[n].pos-masses[n-1].pos 
     n = n-1 


while True: 
    m=0 
    deltat=.2 
    while m<9: 
     rate(30) 
     springs[m].length = springs[m].length - deltat 
     springs[m].length = springs[m].length + deltat 
     m=m+1 

    m=m-1 
    while n>=0: 
     rate(30) 
     springs[m].length = springs[m].length - deltat 
     springs[m].length = springs[m].length + deltat 
     m=m-1 

답변

0

가 ('클릭') 대중이 불투명 = 0.3이 있는지 확인하고 scene.waitfor와 일류 문을 대체 :

여기 내 코드입니다. n 번째 질량을 오른쪽으로 움직이면 스프링이 실제로 단축되고 (n + 1) 번째 질량이 움직일 때 스프링이 오른쪽으로 짧아지고 n 번째 스프링과 (n + 1) 번째 스프링.

덧붙여서, 두 번째 "while true"가 어디인지는 이해할 수 없습니다. 결코 도달하지 못할 것입니다. 나는 더 나은 장소가 VPython 질문을 제기 할 수 있다고 광고하는 것

https://groups.google.com/forum/?fromgroups&hl=en#!forum/vpython-users

에서 VPython 포럼에
관련 문제