2017-08-07 2 views
0

Ich habe von hier aus oft eine Lösung für meine Probleme gefunden, aber dieses Mal bin ich total verblüfft. Ich weiß nicht, was an meinem Code falsch ist.Vpython Greyscreen Absturz

Ich habe einen Code erstellt, um mit VPYTHON eine Box mit geladenen Teilchen zu erstellen. Als ich das Programm starte, bekomme ich nur einen grauen Bildschirm und das Programm stürzt ab. Keine Fehlermeldung, nichts.

from visual import * 
from random import * 

def electronizer(num): 
    list = [] 
    electron_charge = -1.60217662e-19 
    electron_mass = 9.10938356e-31 
    for i in range(num): 
     another_list = [] 
     e = sphere(pos=(random(), random(),random()), radius=2.818e-15, 
color=color.cyan) 
     e.v = vector(random(), random(), random()) 
     another_list.append(e) 
     another_list.append(e.v) 
     another_list.append(electron_charge) 
     another_list.append(electron_mass) 
     list.append(another_list) 
    return list 

def protonizer(num): 
    list = [] 
    proton_charge = 1.60217662e-19 
    proton_mass = 1.6726219e-27 
    for i in range(num): 
     another_list = [] 
     p = sphere(pos=(random(), random(),random()), radius=0.8408739e-15, color=color.red) 
     p.v = vector(random(), random(), random()) 
     another_list.append(p) 
     another_list.append(p.v) 
     another_list.append(proton_charge) 
     another_list.append(proton_mass) 
     list.append(another_list) 
    return list 

def cross(a, b): 
    c = vector(a[1]*b[2] - a[2]*b[1], 
     a[2]*b[0] - a[0]*b[2], 
     a[0]*b[1] - a[1]*b[0]) 

    return c 

def positioner(work_list): 
    k = 8.9875517873681764e3 #Nm2/C2 
    G = 6.674e-11 # Nm2/kg2 
    vac_perm = 1.2566370614e-6 # H/m 
    pi = 3.14159265 
    dt = 0.1e-3 
    constant = 1 
    force = vector(0,0,0) 
    for i in range(len(work_list)): 
     for j in range(len(work_list)): 
      if i != j: 
       r = work_list[i][0].pos - work_list[j][0].pos 
       r_mag = mag(r) 
       r_norm = norm(r) 
       F = k * ((work_list[i][2] * work_list[j][2])/(r_mag**2)) * r_norm 
       force += F 

       B = constant*(vac_perm/4*pi) * (cross(work_list[j][2] * work_list[j][1], norm(r)))/r_mag**2 
       F = cross(work_list[i][2] * work_list[i][1], B) 
       force += F 

       F = -(G * work_list[i][3] * work_list[j][3])/r_mag**2 * r_norm 
       force += F 

     acceleration = force/work_list[i][3] 
     difference_in_velocity = acceleration * dt 
     work_list[i][1] += difference_in_velocity 
     difference_in_position = work_list[i][1] * dt 
     work_list[i][0].pos += difference_in_position 

     if abs(work_list[i][0].pos[0]) > 2.5e-6: 
      work_list[i][1][0] = -work_list[i][1][0] 
     elif abs(work_list[i][0][1]) > 2.5e-6: 
      work_list[i][1][1] = -work_list[i][1][1] 
     elif abs(work_list[i][0][2]) > 2.5e-6: 
      work_list[i][1][2] = -work_list[i][1][2] 
return work_list 

box = box(pos=(0, 0, 0), length = 5e-6, width = 5e-6, height = 5e-6, opacity = 0.5) 

protons_num = raw_input("number of protons: ") 
electrons_num = raw_input("number of electrons: ") 
list_of_electrons = electronizer(int(electrons_num)) 
list_of_protons = protonizer(int(protons_num)) 
work_list = list_of_electrons + list_of_protons 

while True: 
    work_list = positioner(work_list) 

Antwort

0

Sie sollten Ihre Frage im VPython.org Forum fragen, wo die VPython Experten hängen und in der Lage, Ihre Frage zu beantworten. Sie sollten angeben, welches Betriebssystem Sie verwenden und welche Version von Python Sie verwenden. Aus Ihrem Code sehe ich, dass Sie klassisches VPython verwenden. Es gibt eine neuere Version von VPython 7, die gerade erschienen ist, aber die VPython-Syntax hat sich geändert.